sl@18: using System; sl@18: using System.Collections.Generic; sl@18: using System.ComponentModel; sl@18: using System.Data; sl@18: using System.Drawing; sl@18: using System.Linq; sl@18: using System.Text; sl@18: using System.Threading.Tasks; sl@18: using System.Windows.Forms; sl@18: using System.ServiceModel; sl@18: using System.ServiceModel.Channels; sl@31: using System.Diagnostics; sl@55: using SharpDisplay; sl@20: sl@18: sl@18: namespace SharpDisplayClient sl@18: { sl@18: public partial class MainForm : Form sl@18: { sl@26: Client iClient; sl@26: Callback iCallback; sl@43: ContentAlignment Alignment; sl@43: TextField iTextFieldTop; sl@18: sl@18: public MainForm() sl@18: { sl@18: InitializeComponent(); sl@43: Alignment = ContentAlignment.MiddleLeft; sl@43: iTextFieldTop = new TextField(0); sl@18: } sl@18: sl@18: sl@18: private void MainForm_Load(object sender, EventArgs e) sl@18: { sl@31: iCallback = new Callback(this); sl@25: //Instance context is then managed by our client class sl@26: InstanceContext instanceContext = new InstanceContext(iCallback); sl@26: iClient = new Client(instanceContext); sl@18: sl@29: //Connect using unique name sl@32: //string name = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"); sl@32: string name = "Client-" + (iClient.ClientCount() - 1); sl@32: iClient.SetName(name); sl@30: //Text = Text + ": " + name; sl@32: Text = "[[" + name + "]] " + iClient.SessionId; sl@18: sl@33: // sl@33: textBoxTop.Text = iClient.Name; sl@33: textBoxBottom.Text = iClient.SessionId; sl@33: sl@18: } sl@21: sl@31: sl@31: sl@31: public delegate void CloseConnectionDelegate(); sl@31: public delegate void CloseDelegate(); sl@31: sl@31: /// sl@31: /// sl@31: /// sl@31: public void CloseConnectionThreadSafe() sl@21: { sl@31: if (this.InvokeRequired) sl@29: { sl@31: //Not in the proper thread, invoke ourselves sl@31: CloseConnectionDelegate d = new CloseConnectionDelegate(CloseConnectionThreadSafe); sl@31: this.Invoke(d, new object[] { }); sl@29: } sl@31: else sl@31: { sl@31: //We are in the proper thread sl@31: if (IsClientReady()) sl@31: { sl@31: Trace.TraceInformation("Closing client: " + iClient.SessionId); sl@31: iClient.Close(); sl@31: Trace.TraceInformation("Closed client: " + iClient.SessionId); sl@31: } sl@29: sl@31: iClient = null; sl@31: iCallback = null; sl@31: } sl@26: } sl@26: sl@31: /// sl@31: /// sl@31: /// sl@31: public void CloseThreadSafe() sl@31: { sl@31: if (this.InvokeRequired) sl@31: { sl@31: //Not in the proper thread, invoke ourselves sl@31: CloseDelegate d = new CloseDelegate(CloseThreadSafe); sl@31: this.Invoke(d, new object[] { }); sl@31: } sl@31: else sl@31: { sl@31: //We are in the proper thread sl@31: Close(); sl@31: } sl@31: } sl@31: sl@31: sl@26: private void MainForm_FormClosing(object sender, FormClosingEventArgs e) sl@26: { sl@31: CloseConnectionThreadSafe(); sl@29: } sl@29: sl@29: public bool IsClientReady() sl@29: { sl@29: return (iClient != null && iClient.State == CommunicationState.Opened); sl@21: } sl@43: sl@43: private void buttonAlignLeft_Click(object sender, EventArgs e) sl@43: { sl@43: Alignment = ContentAlignment.MiddleLeft; sl@43: textBoxTop.TextAlign = HorizontalAlignment.Left; sl@43: textBoxBottom.TextAlign = HorizontalAlignment.Left; sl@43: } sl@43: sl@43: private void buttonAlignCenter_Click(object sender, EventArgs e) sl@43: { sl@43: Alignment = ContentAlignment.MiddleCenter; sl@43: textBoxTop.TextAlign = HorizontalAlignment.Center; sl@43: textBoxBottom.TextAlign = HorizontalAlignment.Center; sl@43: } sl@43: sl@43: private void buttonAlignRight_Click(object sender, EventArgs e) sl@43: { sl@43: Alignment = ContentAlignment.MiddleRight; sl@43: textBoxTop.TextAlign = HorizontalAlignment.Right; sl@43: textBoxBottom.TextAlign = HorizontalAlignment.Right; sl@43: } sl@43: sl@43: private void buttonSetTopText_Click(object sender, EventArgs e) sl@43: { sl@43: //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft); sl@43: iTextFieldTop.Text = textBoxTop.Text; sl@43: iClient.SetText(iTextFieldTop); sl@43: } sl@43: sl@43: private void buttonSetText_Click(object sender, EventArgs e) sl@43: { sl@43: //iClient.SetText(0,"Top"); sl@43: //iClient.SetText(1, "Bottom"); sl@43: //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft); sl@43: sl@43: iClient.SetTexts(new TextField[] sl@43: { sl@43: new TextField(0, textBoxTop.Text, Alignment), sl@43: new TextField(1, textBoxBottom.Text, Alignment) sl@43: }); sl@43: } sl@18: } sl@18: }