Client/Client.cs
author sl
Sun, 26 Oct 2014 16:16:57 +0100
changeset 75 2549a8055bd1
parent 72 fd0bb39a7818
child 77 042c1fa136b9
permissions -rw-r--r--
Removing specific functions for setting text and bitmap.
Now having a generic functions for setting any kind of fields.
Thus bitmaps can now be set together with text fields in a single server call.
     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 SetField(DataField aField)
    80         {
    81             Channel.SetField(aField);
    82         }
    83 
    84         public void SetFields(System.Collections.Generic.IList<DataField> aFields)
    85         {
    86             Channel.SetFields(aFields);
    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 }