Client/Client.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.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 using System.Windows.Forms;
     7 using SharpDisplayInterface;
     8 using System.ServiceModel;
     9 using System.ServiceModel.Channels;
    10 
    11 
    12 namespace SharpDisplayClient
    13 {
    14     /// <summary>
    15     ///
    16     /// </summary>
    17     [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
    18     public class Callback : IDisplayServiceCallback, IDisposable
    19     {
    20         public void OnConnected()
    21         {
    22             //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
    23             //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
    24 
    25             MessageBox.Show("OnConnected()", "Client");
    26         }
    27 
    28 
    29         public void OnServerClosing()
    30         {
    31             //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
    32             //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
    33 
    34             //MessageBox.Show("OnServerClosing()", "Client");
    35             Program.iMainForm.CloseConnection();
    36             Program.iMainForm.Close();
    37         }
    38 
    39         //From IDisposable
    40         public void Dispose()
    41         {
    42 
    43         }
    44     }
    45 
    46 
    47     /// <summary>
    48     ///
    49     /// </summary>
    50     [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
    51     public class Client : DuplexClientBase<IDisplayService>
    52     {
    53         public string Name { get; set; }
    54         public string SessionId { get { return InnerChannel.SessionId; } }
    55 
    56         public Client(InstanceContext callbackInstance)
    57             : base(callbackInstance, new NetTcpBinding(SecurityMode.None, true), new EndpointAddress("net.tcp://localhost:8001/DisplayService"))
    58         { }
    59 
    60         public void Connect(string aClientName)
    61         {
    62             Name = aClientName;
    63             Channel.Connect(aClientName);
    64         }
    65 
    66         public void Disconnect()
    67         {
    68             Channel.Disconnect(Name);
    69             Name = "";
    70         }
    71 
    72         public void SetText(int aLineIndex, string aText)
    73         {
    74             Channel.SetText(aLineIndex, aText);
    75         }
    76 
    77 
    78         public void SetTexts(System.Collections.Generic.IList<string> aTexts)
    79         {
    80             Channel.SetTexts(aTexts);
    81         }
    82 
    83         
    84 
    85     }
    86 }