Client/MainForm.cs
author sl
Fri, 15 Aug 2014 10:20:01 +0200
changeset 30 c375286d1a1c
parent 29 c4e03315035c
child 31 f19b04646b6a
permissions -rw-r--r--
Still trying to setup WCF for us to work nicely.
Now using multi threading and reliable session.
Implementing thread safe functions where needed.
Enforcing session mode.
Fixing bug in marquee label as we forgot to reset current position when text is changed.
     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.Linq;
     7 using System.Text;
     8 using System.Threading.Tasks;
     9 using System.Windows.Forms;
    10 using System.ServiceModel;
    11 using System.ServiceModel.Channels;
    12 
    13 
    14 namespace SharpDisplayClient
    15 {
    16     public partial class MainForm : Form
    17     {
    18         Client iClient;
    19         Callback iCallback;
    20 
    21         public MainForm()
    22         {
    23             InitializeComponent();
    24         }
    25 
    26         private void buttonSetText_Click(object sender, EventArgs e)
    27         {
    28             //iClient.SetText(0,"Top");
    29             //iClient.SetText(1, "Bottom");
    30             iClient.SetTexts(new string[] { iClient.Name, iClient.SessionId });
    31         }
    32 
    33         private void MainForm_Load(object sender, EventArgs e)
    34         {
    35             iCallback = new Callback();
    36             //Instance context is then managed by our client class
    37             InstanceContext instanceContext = new InstanceContext(iCallback);
    38             iClient = new Client(instanceContext);
    39 
    40             //Connect using unique name
    41             string name = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt");
    42             iClient.Connect(name);
    43             //Text = Text + ": " + name;
    44             Text = Text + ": " + iClient.SessionId;
    45 
    46         }
    47 
    48         public void CloseConnection()
    49         {
    50             if (IsClientReady())
    51             {
    52                 //iClient.Disconnect();
    53                 iClient.Close();
    54             }
    55 
    56             iClient = null;
    57             iCallback = null;
    58         }
    59 
    60         private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
    61         {
    62             if (IsClientReady()) //Could catch exception instead
    63             {
    64                 iClient.Disconnect();
    65             }
    66 
    67             CloseConnection();
    68         }
    69 
    70         public bool IsClientReady()
    71         {
    72             return (iClient != null && iClient.State == CommunicationState.Opened);
    73         }
    74     }
    75 }