author | sl |
Fri, 15 Aug 2014 10:20:01 +0200 | |
changeset 30 | c375286d1a1c |
parent 29 | c4e03315035c |
child 31 | f19b04646b6a |
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@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@30 | 17 |
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)] |
sl@30 | 18 |
public class Callback : IDisplayServiceCallback, IDisposable |
sl@20 | 19 |
{ |
sl@20 | 20 |
public void OnConnected() |
sl@20 | 21 |
{ |
sl@20 | 22 |
//Debug.Assert(Thread.CurrentThread.IsThreadPoolThread); |
sl@20 | 23 |
//Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId); |
sl@20 | 24 |
|
sl@20 | 25 |
MessageBox.Show("OnConnected()", "Client"); |
sl@20 | 26 |
} |
sl@20 | 27 |
|
sl@20 | 28 |
|
sl@20 | 29 |
public void OnServerClosing() |
sl@20 | 30 |
{ |
sl@20 | 31 |
//Debug.Assert(Thread.CurrentThread.IsThreadPoolThread); |
sl@20 | 32 |
//Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId); |
sl@20 | 33 |
|
sl@21 | 34 |
//MessageBox.Show("OnServerClosing()", "Client"); |
sl@21 | 35 |
Program.iMainForm.CloseConnection(); |
sl@29 | 36 |
Program.iMainForm.Close(); |
sl@20 | 37 |
} |
sl@25 | 38 |
|
sl@25 | 39 |
//From IDisposable |
sl@25 | 40 |
public void Dispose() |
sl@25 | 41 |
{ |
sl@25 | 42 |
|
sl@25 | 43 |
} |
sl@20 | 44 |
} |
sl@20 | 45 |
|
sl@20 | 46 |
|
sl@25 | 47 |
/// <summary> |
sl@25 | 48 |
/// |
sl@25 | 49 |
/// </summary> |
sl@30 | 50 |
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)] |
sl@30 | 51 |
public class Client : DuplexClientBase<IDisplayService> |
sl@20 | 52 |
{ |
sl@30 | 53 |
public string Name { get; set; } |
sl@30 | 54 |
public string SessionId { get { return InnerChannel.SessionId; } } |
sl@26 | 55 |
|
sl@26 | 56 |
public Client(InstanceContext callbackInstance) |
sl@30 | 57 |
: base(callbackInstance, new NetTcpBinding(SecurityMode.None, true), new EndpointAddress("net.tcp://localhost:8001/DisplayService")) |
sl@20 | 58 |
{ } |
sl@20 | 59 |
|
sl@20 | 60 |
public void Connect(string aClientName) |
sl@20 | 61 |
{ |
sl@26 | 62 |
Name = aClientName; |
sl@20 | 63 |
Channel.Connect(aClientName); |
sl@20 | 64 |
} |
sl@20 | 65 |
|
sl@26 | 66 |
public void Disconnect() |
sl@26 | 67 |
{ |
sl@26 | 68 |
Channel.Disconnect(Name); |
sl@26 | 69 |
Name = ""; |
sl@26 | 70 |
} |
sl@26 | 71 |
|
sl@20 | 72 |
public void SetText(int aLineIndex, string aText) |
sl@20 | 73 |
{ |
sl@20 | 74 |
Channel.SetText(aLineIndex, aText); |
sl@20 | 75 |
} |
sl@20 | 76 |
|
sl@20 | 77 |
|
sl@20 | 78 |
public void SetTexts(System.Collections.Generic.IList<string> aTexts) |
sl@20 | 79 |
{ |
sl@20 | 80 |
Channel.SetTexts(aTexts); |
sl@20 | 81 |
} |
sl@20 | 82 |
|
sl@30 | 83 |
|
sl@30 | 84 |
|
sl@20 | 85 |
} |
sl@20 | 86 |
} |