author | sl |
Tue, 14 Oct 2014 19:32:09 +0200 | |
changeset 70 | dcd2bbb90d42 |
parent 62 | ac698f4e1b36 |
child 72 | fd0bb39a7818 |
permissions | -rw-r--r-- |
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@43 | 79 |
public void SetText(TextField aTextField) |
sl@20 | 80 |
{ |
sl@43 | 81 |
Channel.SetText(aTextField); |
sl@20 | 82 |
} |
sl@20 | 83 |
|
sl@43 | 84 |
public void SetTexts(System.Collections.Generic.IList<TextField> aTextFields) |
sl@20 | 85 |
{ |
sl@43 | 86 |
Channel.SetTexts(aTextFields); |
sl@20 | 87 |
} |
sl@20 | 88 |
|
sl@67 | 89 |
public void SetBitmap(BitmapField aBitmapField) |
sl@67 | 90 |
{ |
sl@67 | 91 |
Channel.SetBitmap(aBitmapField); |
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 |
} |