Client/Client.cs
author sl
Sun, 21 Sep 2014 13:15:52 +0200
changeset 55 b5ed2e29be23
parent 43 86aad774b532
child 57 544132d07c3b
permissions -rw-r--r--
Renaming stuff.
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@26
    63
        public Client(InstanceContext callbackInstance)
sl@30
    64
            : base(callbackInstance, 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@43
    73
        public void SetText(TextField aTextField)
sl@20
    74
        {
sl@43
    75
            Channel.SetText(aTextField);
sl@20
    76
        }
sl@20
    77
sl@43
    78
        public void SetTexts(System.Collections.Generic.IList<TextField> aTextFields)
sl@20
    79
        {
sl@43
    80
            Channel.SetTexts(aTextFields);
sl@20
    81
        }
sl@20
    82
sl@32
    83
        public int ClientCount()
sl@32
    84
        {
sl@32
    85
            return Channel.ClientCount();
sl@32
    86
        }
sl@20
    87
    }
sl@20
    88
}