Client now recovers from faulty states and timeout.
2 using System.Collections.Generic;
5 using System.Threading.Tasks;
6 using System.Windows.Forms;
8 using System.ServiceModel;
9 using System.ServiceModel.Channels;
12 namespace SharpDisplayClient
17 [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
18 public class Callback : ICallback, IDisposable
20 private MainForm MainForm { get; set; }
22 public Callback(MainForm aMainForm)
27 public void OnConnected()
29 //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
30 //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
32 MessageBox.Show("OnConnected()", "Client");
36 public void OnCloseOrder()
38 //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
39 //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
41 //MessageBox.Show("OnServerClosing()", "Client");
42 MainForm.CloseConnectionThreadSafe();
43 MainForm.CloseThreadSafe();
57 [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
58 public class Client : DuplexClientBase<IService>
60 public string Name { get; set; }
61 public string SessionId { get { return InnerChannel.SessionId; } }
63 public Client(ICallback aCallback)
64 : base(new InstanceContext(aCallback), new NetTcpBinding(SecurityMode.None, true), new EndpointAddress("net.tcp://localhost:8001/DisplayService"))
67 public void SetName(string aClientName)
70 Channel.SetName(aClientName);
74 public void SetLayout(TableLayout aLayout)
76 Channel.SetLayout(aLayout);
79 public void SetText(DataField aField)
81 Channel.SetText(aField);
84 public void SetTexts(System.Collections.Generic.IList<DataField> aFields)
86 Channel.SetTexts(aFields);
89 public void SetBitmap(DataField aField)
91 Channel.SetBitmap(aField);
94 public int ClientCount()
96 return Channel.ClientCount();
101 return State == CommunicationState.Opened;
109 public class DisplayClient
113 private MainForm MainForm { get; set; }
115 public string Name { get; set; }
116 public string SessionId { get { return iClient.SessionId; } }
118 public DisplayClient(MainForm aMainForm)
120 MainForm = aMainForm;
126 iCallback = new Callback(MainForm);
127 iClient = new Client(iCallback);
130 iClient.SetName(Name);
142 public bool IsReady()
144 return (iClient != null && iCallback != null && iClient.IsReady());
147 public void CheckConnection()
155 public void SetName(string aClientName)
159 iClient.SetName(aClientName);
163 public void SetLayout(TableLayout aLayout)
166 iClient.SetLayout(aLayout);
169 public void SetText(DataField aField)
172 iClient.SetText(aField);
175 public void SetTexts(System.Collections.Generic.IList<DataField> aFields)
178 iClient.SetTexts(aFields);
181 public void SetBitmap(DataField aField)
184 iClient.SetBitmap(aField);
187 public int ClientCount()
190 return iClient.ClientCount();