Client/Client.cs
author sl
Sat, 25 Oct 2014 13:35:11 +0200
changeset 72 fd0bb39a7818
parent 67 6e50baf5a811
child 73 926cdf23b485
child 75 2549a8055bd1
permissions -rw-r--r--
Now having a single class for both text and bitmap field.
Thus we should soon be able to use common functions to pass in fields.
     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(DataField aField)
    80         {
    81             Channel.SetText(aField);
    82         }
    83 
    84         public void SetTexts(System.Collections.Generic.IList<DataField> aFields)
    85         {
    86             Channel.SetTexts(aFields);
    87         }
    88 
    89         public void SetBitmap(DataField aField)
    90         {
    91             Channel.SetBitmap(aField);
    92         }
    93 
    94         public int ClientCount()
    95         {
    96             return Channel.ClientCount();
    97         }
    98 
    99         public bool IsReady()
   100         {
   101             return State == CommunicationState.Opened;
   102         }
   103     }
   104 }