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.
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@55
     7
using SharpDisplay;
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@31
    17
    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
sl@55
    18
    public class Callback : ICallback, IDisposable
sl@20
    19
    {
sl@31
    20
        private MainForm MainForm { get; set; }
sl@31
    21
sl@31
    22
        public Callback(MainForm aMainForm)
sl@31
    23
        {
sl@31
    24
            MainForm = aMainForm;
sl@31
    25
        }
sl@31
    26
sl@20
    27
        public void OnConnected()
sl@20
    28
        {
sl@20
    29
            //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
sl@20
    30
            //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
sl@20
    31
sl@20
    32
            MessageBox.Show("OnConnected()", "Client");
sl@20
    33
        }
sl@20
    34
sl@20
    35
sl@32
    36
        public void OnCloseOrder()
sl@20
    37
        {
sl@20
    38
            //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
sl@20
    39
            //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
sl@20
    40
sl@21
    41
            //MessageBox.Show("OnServerClosing()", "Client");
sl@31
    42
            MainForm.CloseConnectionThreadSafe();
sl@31
    43
            MainForm.CloseThreadSafe();
sl@20
    44
        }
sl@25
    45
sl@25
    46
        //From IDisposable
sl@25
    47
        public void Dispose()
sl@25
    48
        {
sl@25
    49
sl@25
    50
        }
sl@20
    51
    }
sl@20
    52
sl@20
    53
sl@25
    54
    /// <summary>
sl@25
    55
    ///
sl@25
    56
    /// </summary>
sl@31
    57
    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
sl@55
    58
    public class Client : DuplexClientBase<IService>
sl@20
    59
    {
sl@30
    60
        public string Name { get; set; }
sl@30
    61
        public string SessionId { get { return InnerChannel.SessionId; } }
sl@26
    62
sl@57
    63
        public Client(ICallback aCallback)
sl@57
    64
            : base(new InstanceContext(aCallback), new NetTcpBinding(SecurityMode.None, true), new EndpointAddress("net.tcp://localhost:8001/DisplayService"))
sl@20
    65
        { }
sl@20
    66
sl@32
    67
        public void SetName(string aClientName)
sl@20
    68
        {
sl@26
    69
            Name = aClientName;
sl@32
    70
            Channel.SetName(aClientName);
sl@26
    71
        }
sl@26
    72
sl@62
    73
sl@62
    74
        public void SetLayout(TableLayout aLayout)
sl@62
    75
        {
sl@62
    76
            Channel.SetLayout(aLayout);
sl@62
    77
        }
sl@62
    78
sl@72
    79
        public void SetText(DataField aField)
sl@20
    80
        {
sl@72
    81
            Channel.SetText(aField);
sl@20
    82
        }
sl@20
    83
sl@72
    84
        public void SetTexts(System.Collections.Generic.IList<DataField> aFields)
sl@20
    85
        {
sl@72
    86
            Channel.SetTexts(aFields);
sl@20
    87
        }
sl@20
    88
sl@72
    89
        public void SetBitmap(DataField aField)
sl@67
    90
        {
sl@72
    91
            Channel.SetBitmap(aField);
sl@67
    92
        }
sl@67
    93
sl@32
    94
        public int ClientCount()
sl@32
    95
        {
sl@32
    96
            return Channel.ClientCount();
sl@32
    97
        }
sl@57
    98
sl@57
    99
        public bool IsReady()
sl@57
   100
        {
sl@57
   101
            return State == CommunicationState.Opened;
sl@57
   102
        }
sl@20
   103
    }
sl@20
   104
}