Client/Client.cs
author sl
Thu, 14 Aug 2014 10:19:53 +0200
changeset 27 9c49c04fc620
parent 25 6f10207a89a8
child 29 c4e03315035c
permissions -rw-r--r--
Adding suspend/resume button.
Setting our server process to higher priority to avoid render lags.
sl@20
     1
using System;
sl@20
     2
using System.Collections.Generic;
sl@20
     3
using System.Linq;
sl@20
     4
using System.Text;
sl@20
     5
using System.Threading.Tasks;
sl@20
     6
using System.Windows.Forms;
sl@22
     7
using SharpDisplayInterface;
sl@20
     8
using System.ServiceModel;
sl@20
     9
using System.ServiceModel.Channels;
sl@20
    10
sl@20
    11
sl@20
    12
namespace SharpDisplayClient
sl@20
    13
{
sl@25
    14
    /// <summary>
sl@25
    15
    ///
sl@25
    16
    /// </summary>
sl@26
    17
    public partial class Callback : IDisplayServiceCallback, IDisposable
sl@20
    18
    {
sl@20
    19
        public void OnConnected()
sl@20
    20
        {
sl@20
    21
            //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
sl@20
    22
            //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
sl@20
    23
sl@20
    24
            MessageBox.Show("OnConnected()", "Client");
sl@20
    25
        }
sl@20
    26
sl@20
    27
sl@20
    28
        public void OnServerClosing()
sl@20
    29
        {
sl@20
    30
            //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
sl@20
    31
            //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
sl@20
    32
sl@21
    33
            //MessageBox.Show("OnServerClosing()", "Client");
sl@21
    34
            Program.iMainForm.CloseConnection();
sl@20
    35
        }
sl@25
    36
sl@25
    37
        //From IDisposable
sl@25
    38
        public void Dispose()
sl@25
    39
        {
sl@25
    40
sl@25
    41
        }
sl@20
    42
    }
sl@20
    43
sl@20
    44
sl@25
    45
    /// <summary>
sl@25
    46
    ///
sl@25
    47
    /// </summary>
sl@26
    48
    public partial class Client : DuplexClientBase<IDisplayService>
sl@20
    49
    {
sl@26
    50
        private string Name { get; set; }
sl@26
    51
sl@26
    52
        public Client(InstanceContext callbackInstance)
sl@20
    53
            : base(callbackInstance, new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:8001/DisplayService"))
sl@20
    54
        { }
sl@20
    55
sl@20
    56
        public void Connect(string aClientName)
sl@20
    57
        {
sl@26
    58
            Name = aClientName;
sl@20
    59
            Channel.Connect(aClientName);
sl@20
    60
        }
sl@20
    61
sl@26
    62
        public void Disconnect()
sl@26
    63
        {
sl@26
    64
            Channel.Disconnect(Name);
sl@26
    65
            Name = "";
sl@26
    66
        }
sl@26
    67
sl@20
    68
        public void SetText(int aLineIndex, string aText)
sl@20
    69
        {
sl@20
    70
            Channel.SetText(aLineIndex, aText);
sl@20
    71
        }
sl@20
    72
sl@20
    73
sl@20
    74
        public void SetTexts(System.Collections.Generic.IList<string> aTexts)
sl@20
    75
        {
sl@20
    76
            Channel.SetTexts(aTexts);
sl@20
    77
        }
sl@20
    78
sl@20
    79
    }
sl@20
    80
}