Client/Client.cs
author sl
Thu, 14 Aug 2014 09:57:44 +0200
changeset 26 a6fb2b2f73b0
parent 25 6f10207a89a8
child 29 c4e03315035c
permissions -rw-r--r--
Adding disconnect function to our interface.
     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     public partial class Callback : IDisplayServiceCallback, IDisposable
    18     {
    19         public void OnConnected()
    20         {
    21             //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
    22             //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
    23 
    24             MessageBox.Show("OnConnected()", "Client");
    25         }
    26 
    27 
    28         public void OnServerClosing()
    29         {
    30             //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
    31             //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
    32 
    33             //MessageBox.Show("OnServerClosing()", "Client");
    34             Program.iMainForm.CloseConnection();
    35         }
    36 
    37         //From IDisposable
    38         public void Dispose()
    39         {
    40 
    41         }
    42     }
    43 
    44 
    45     /// <summary>
    46     ///
    47     /// </summary>
    48     public partial class Client : DuplexClientBase<IDisplayService>
    49     {
    50         private string Name { get; set; }
    51 
    52         public Client(InstanceContext callbackInstance)
    53             : base(callbackInstance, new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:8001/DisplayService"))
    54         { }
    55 
    56         public void Connect(string aClientName)
    57         {
    58             Name = aClientName;
    59             Channel.Connect(aClientName);
    60         }
    61 
    62         public void Disconnect()
    63         {
    64             Channel.Disconnect(Name);
    65             Name = "";
    66         }
    67 
    68         public void SetText(int aLineIndex, string aText)
    69         {
    70             Channel.SetText(aLineIndex, aText);
    71         }
    72 
    73 
    74         public void SetTexts(System.Collections.Generic.IList<string> aTexts)
    75         {
    76             Channel.SetTexts(aTexts);
    77         }
    78 
    79     }
    80 }