Client/Client.cs
author sl
Mon, 22 Sep 2014 17:23:35 +0200
changeset 63 cd9924457275
parent 57 544132d07c3b
child 67 6e50baf5a811
permissions -rw-r--r--
TableLayout now support row and column styles.
     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 SharpDisplay;
     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 : ICallback, 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<IService>
    59     {
    60         public string Name { get; set; }
    61         public string SessionId { get { return InnerChannel.SessionId; } }
    62 
    63         public Client(ICallback aCallback)
    64             : base(new InstanceContext(aCallback), 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 
    74         public void SetLayout(TableLayout aLayout)
    75         {
    76             Channel.SetLayout(aLayout);
    77         }
    78 
    79         public void SetText(TextField aTextField)
    80         {
    81             Channel.SetText(aTextField);
    82         }
    83 
    84         public void SetTexts(System.Collections.Generic.IList<TextField> aTextFields)
    85         {
    86             Channel.SetTexts(aTextFields);
    87         }
    88 
    89         public int ClientCount()
    90         {
    91             return Channel.ClientCount();
    92         }
    93 
    94         public bool IsReady()
    95         {
    96             return State == CommunicationState.Opened;
    97         }
    98     }
    99 }