Client/Client.cs
author StephaneLenclud
Mon, 18 Aug 2014 23:43:44 +0200
changeset 35 f3893924a6eb
parent 31 f19b04646b6a
child 43 86aad774b532
permissions -rw-r--r--
Tried using Control instead of Label as base class for our Marquee.
Sticking to Label for now.
     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.Multiple)]
    18     public class Callback : IDisplayServiceCallback, IDisposable
    19     {
    20         private MainForm MainForm { get; set; }
    21 
    22         public Callback(MainForm aMainForm)
    23         {
    24             MainForm = aMainForm;
    25         }
    26 
    27         public void OnConnected()
    28         {
    29             //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
    30             //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
    31 
    32             MessageBox.Show("OnConnected()", "Client");
    33         }
    34 
    35 
    36         public void OnCloseOrder()
    37         {
    38             //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
    39             //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
    40 
    41             //MessageBox.Show("OnServerClosing()", "Client");
    42             MainForm.CloseConnectionThreadSafe();
    43             MainForm.CloseThreadSafe();
    44         }
    45 
    46         //From IDisposable
    47         public void Dispose()
    48         {
    49 
    50         }
    51     }
    52 
    53 
    54     /// <summary>
    55     ///
    56     /// </summary>
    57     [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
    58     public class Client : DuplexClientBase<IDisplayService>
    59     {
    60         public string Name { get; set; }
    61         public string SessionId { get { return InnerChannel.SessionId; } }
    62 
    63         public Client(InstanceContext callbackInstance)
    64             : base(callbackInstance, new NetTcpBinding(SecurityMode.None, true), new EndpointAddress("net.tcp://localhost:8001/DisplayService"))
    65         { }
    66 
    67         public void SetName(string aClientName)
    68         {
    69             Name = aClientName;
    70             Channel.SetName(aClientName);
    71         }
    72 
    73         public void SetText(int aLineIndex, string aText)
    74         {
    75             Channel.SetText(aLineIndex, aText);
    76         }
    77 
    78         public void SetTexts(System.Collections.Generic.IList<string> aTexts)
    79         {
    80             Channel.SetTexts(aTexts);
    81         }
    82 
    83         public int ClientCount()
    84         {
    85             return Channel.ClientCount();
    86         }
    87     }
    88 }