StephaneLenclud@191: // StephaneLenclud@191: // Copyright (C) 2014-2015 Stéphane Lenclud. StephaneLenclud@191: // StephaneLenclud@191: // This file is part of SharpDisplayManager. StephaneLenclud@191: // StephaneLenclud@191: // SharpDisplayManager is free software: you can redistribute it and/or modify StephaneLenclud@191: // it under the terms of the GNU General Public License as published by StephaneLenclud@191: // the Free Software Foundation, either version 3 of the License, or StephaneLenclud@191: // (at your option) any later version. StephaneLenclud@191: // StephaneLenclud@191: // SharpDisplayManager is distributed in the hope that it will be useful, StephaneLenclud@191: // but WITHOUT ANY WARRANTY; without even the implied warranty of StephaneLenclud@191: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the StephaneLenclud@191: // GNU General Public License for more details. StephaneLenclud@191: // StephaneLenclud@191: // You should have received a copy of the GNU General Public License StephaneLenclud@191: // along with SharpDisplayManager. If not, see . StephaneLenclud@191: // StephaneLenclud@191: StephaneLenclud@191: using System; StephaneLenclud@191: using System.Collections.Generic; StephaneLenclud@191: using System.ComponentModel; StephaneLenclud@191: using System.Data; StephaneLenclud@191: using System.Drawing; StephaneLenclud@191: using System.Linq; StephaneLenclud@191: using System.Text; StephaneLenclud@191: using System.Threading.Tasks; StephaneLenclud@191: using System.Windows.Forms; StephaneLenclud@191: using System.ServiceModel; StephaneLenclud@191: using System.ServiceModel.Channels; StephaneLenclud@191: using System.Diagnostics; StephaneLenclud@191: using SharpLib.Display; StephaneLenclud@191: StephaneLenclud@191: StephaneLenclud@191: namespace SharpDisplayClient StephaneLenclud@191: { StephaneLenclud@191: public partial class FormClientTest : Form StephaneLenclud@191: { StephaneLenclud@191: public StartParams Params { get; set; } StephaneLenclud@191: StephaneLenclud@191: // StephaneLenclud@191: Client iClient; StephaneLenclud@191: // StephaneLenclud@191: ContentAlignment Alignment; StephaneLenclud@191: TextField iTextFieldTop; StephaneLenclud@191: StephaneLenclud@191: StephaneLenclud@191: /// StephaneLenclud@191: /// Constructor StephaneLenclud@191: /// StephaneLenclud@191: public FormClientTest() StephaneLenclud@191: { StephaneLenclud@191: InitializeComponent(); StephaneLenclud@191: Alignment = ContentAlignment.MiddleLeft; StephaneLenclud@191: iTextFieldTop = new TextField(); StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: public void OnCloseOrder() StephaneLenclud@191: { StephaneLenclud@191: CloseThreadSafe(); StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: /// StephaneLenclud@191: /// StephaneLenclud@191: /// StephaneLenclud@191: /// StephaneLenclud@191: /// StephaneLenclud@191: private void MainForm_Load(object sender, EventArgs e) StephaneLenclud@191: { StephaneLenclud@191: iClient = new Client(); StephaneLenclud@191: iClient.CloseOrderEvent += OnCloseOrder; StephaneLenclud@191: iClient.Open(); StephaneLenclud@191: StephaneLenclud@191: //Connect using unique name StephaneLenclud@191: //string name = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"); StephaneLenclud@191: string name = "Client-" + (iClient.ClientCount() - 1); StephaneLenclud@191: iClient.SetName(name); StephaneLenclud@191: //Text = Text + ": " + name; StephaneLenclud@191: Text = "[[" + name + "]] " + iClient.SessionId; StephaneLenclud@191: StephaneLenclud@191: // StephaneLenclud@191: textBoxTop.Text = iClient.Name; StephaneLenclud@191: textBoxBottom.Text = iClient.SessionId; StephaneLenclud@191: StephaneLenclud@191: if (Params != null) StephaneLenclud@191: { StephaneLenclud@191: //Parameters where specified use them StephaneLenclud@191: if (Params.TopText != "") StephaneLenclud@191: { StephaneLenclud@191: textBoxTop.Text = Params.TopText; StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: if (Params.BottomText != "") StephaneLenclud@191: { StephaneLenclud@191: textBoxBottom.Text = Params.BottomText; StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: Location = Params.Location; StephaneLenclud@191: // StephaneLenclud@191: SetBasicLayoutAndText(); StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: StephaneLenclud@191: StephaneLenclud@191: public delegate void CloseConnectionDelegate(); StephaneLenclud@191: public delegate void CloseDelegate(); StephaneLenclud@191: StephaneLenclud@191: /// StephaneLenclud@191: /// StephaneLenclud@191: /// StephaneLenclud@191: public void CloseConnectionThreadSafe() StephaneLenclud@191: { StephaneLenclud@191: if (this.InvokeRequired) StephaneLenclud@191: { StephaneLenclud@191: //Not in the proper thread, invoke ourselves StephaneLenclud@191: CloseConnectionDelegate d = new CloseConnectionDelegate(CloseConnectionThreadSafe); StephaneLenclud@191: this.Invoke(d, new object[] { }); StephaneLenclud@191: } StephaneLenclud@191: else StephaneLenclud@191: { StephaneLenclud@191: //We are in the proper thread StephaneLenclud@191: if (IsClientReady()) StephaneLenclud@191: { StephaneLenclud@191: string sessionId = iClient.SessionId; StephaneLenclud@191: Trace.TraceInformation("Closing client: " + sessionId); StephaneLenclud@191: iClient.Close(); StephaneLenclud@191: Trace.TraceInformation("Closed client: " + sessionId); StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: iClient = null; StephaneLenclud@191: } StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: /// StephaneLenclud@191: /// StephaneLenclud@191: /// StephaneLenclud@191: public void CloseThreadSafe() StephaneLenclud@191: { StephaneLenclud@191: if (this.InvokeRequired) StephaneLenclud@191: { StephaneLenclud@191: //Not in the proper thread, invoke ourselves StephaneLenclud@191: CloseDelegate d = new CloseDelegate(CloseThreadSafe); StephaneLenclud@191: this.Invoke(d, new object[] { }); StephaneLenclud@191: } StephaneLenclud@191: else StephaneLenclud@191: { StephaneLenclud@191: //We are in the proper thread StephaneLenclud@191: Close(); StephaneLenclud@191: } StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: StephaneLenclud@191: private void MainForm_FormClosing(object sender, FormClosingEventArgs e) StephaneLenclud@191: { StephaneLenclud@191: CloseConnectionThreadSafe(); StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: public bool IsClientReady() StephaneLenclud@191: { StephaneLenclud@191: return (iClient != null && iClient.IsReady()); StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: private void buttonAlignLeft_Click(object sender, EventArgs e) StephaneLenclud@191: { StephaneLenclud@191: Alignment = ContentAlignment.MiddleLeft; StephaneLenclud@191: textBoxTop.TextAlign = HorizontalAlignment.Left; StephaneLenclud@191: textBoxBottom.TextAlign = HorizontalAlignment.Left; StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: private void buttonAlignCenter_Click(object sender, EventArgs e) StephaneLenclud@191: { StephaneLenclud@191: Alignment = ContentAlignment.MiddleCenter; StephaneLenclud@191: textBoxTop.TextAlign = HorizontalAlignment.Center; StephaneLenclud@191: textBoxBottom.TextAlign = HorizontalAlignment.Center; StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: private void buttonAlignRight_Click(object sender, EventArgs e) StephaneLenclud@191: { StephaneLenclud@191: Alignment = ContentAlignment.MiddleRight; StephaneLenclud@191: textBoxTop.TextAlign = HorizontalAlignment.Right; StephaneLenclud@191: textBoxBottom.TextAlign = HorizontalAlignment.Right; StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: private void buttonSetTopText_Click(object sender, EventArgs e) StephaneLenclud@191: { StephaneLenclud@191: //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft); StephaneLenclud@191: iTextFieldTop.Text = textBoxTop.Text; StephaneLenclud@191: iTextFieldTop.Alignment = Alignment; StephaneLenclud@191: bool res = iClient.SetField(iTextFieldTop); StephaneLenclud@191: StephaneLenclud@191: if (!res) StephaneLenclud@191: { StephaneLenclud@191: MessageBox.Show("Create you fields first", "Field update error", MessageBoxButtons.OK, MessageBoxIcon.Error); StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: private void buttonSetText_Click(object sender, EventArgs e) StephaneLenclud@191: { StephaneLenclud@191: SetBasicLayoutAndText(); StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: void SetBasicLayoutAndText() StephaneLenclud@191: { StephaneLenclud@191: //Set one column two lines layout StephaneLenclud@191: TableLayout layout = new TableLayout(1, 2); StephaneLenclud@191: iClient.SetLayout(layout); StephaneLenclud@191: StephaneLenclud@191: //Set our fields StephaneLenclud@191: iClient.CreateFields(new DataField[] StephaneLenclud@191: { StephaneLenclud@191: new TextField(textBoxTop.Text, Alignment, 0, 0), StephaneLenclud@191: new TextField(textBoxBottom.Text, Alignment, 0, 1) StephaneLenclud@191: }); StephaneLenclud@191: StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: private void buttonLayoutUpdate_Click(object sender, EventArgs e) StephaneLenclud@191: { StephaneLenclud@191: //Define a 2 by 2 layout StephaneLenclud@191: TableLayout layout = new TableLayout(2,2); StephaneLenclud@191: //Second column only takes up 25% StephaneLenclud@191: layout.Columns[1].Width = 25F; StephaneLenclud@191: //Send layout to server StephaneLenclud@191: iClient.SetLayout(layout); StephaneLenclud@191: StephaneLenclud@191: // StephaneLenclud@191: RecordingField recording = new RecordingField(); StephaneLenclud@191: recording.IsActive = true; StephaneLenclud@191: recording.Text = "Recording Tame of Gone until 22:05"; StephaneLenclud@191: //Set texts StephaneLenclud@191: iClient.CreateFields(new DataField[] StephaneLenclud@191: { StephaneLenclud@191: new TextField(textBoxTop.Text, Alignment, 0, 0), StephaneLenclud@191: new TextField(textBoxBottom.Text, Alignment, 0, 1), StephaneLenclud@191: new TextField("Third text field", Alignment, 1, 0), StephaneLenclud@191: new TextField("Forth text field", Alignment, 1, 1), StephaneLenclud@191: recording StephaneLenclud@191: }); StephaneLenclud@191: StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: private void buttonSetBitmap_Click(object sender, EventArgs e) StephaneLenclud@191: { StephaneLenclud@191: int x1 = 0; StephaneLenclud@191: int y1 = 0; StephaneLenclud@191: int x2 = 256; StephaneLenclud@191: int y2 = 32; StephaneLenclud@191: StephaneLenclud@191: Bitmap bitmap = new Bitmap(x2,y2); StephaneLenclud@191: Pen blackPen = new Pen(Color.Black, 3); StephaneLenclud@191: StephaneLenclud@191: // Draw line to screen. StephaneLenclud@191: using (var graphics = Graphics.FromImage(bitmap)) StephaneLenclud@191: { StephaneLenclud@191: graphics.DrawLine(blackPen, x1, y1, x2, y2); StephaneLenclud@191: graphics.DrawLine(blackPen, x1, y2, x2, y1); StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: DataField field = new BitmapField(bitmap); StephaneLenclud@191: //field.ColumnSpan = 2; StephaneLenclud@191: iClient.SetField(field); StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: private void buttonBitmapLayout_Click(object sender, EventArgs e) StephaneLenclud@191: { StephaneLenclud@191: SetLayoutWithBitmap(); StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: /// StephaneLenclud@191: /// Define a layout with a bitmap field on the left and two lines of text on the right. StephaneLenclud@191: /// StephaneLenclud@191: private void SetLayoutWithBitmap() StephaneLenclud@191: { StephaneLenclud@191: //Define a 2 by 2 layout StephaneLenclud@191: TableLayout layout = new TableLayout(2, 2); StephaneLenclud@191: //First column only takes 25% StephaneLenclud@191: layout.Columns[0].Width = 25F; StephaneLenclud@191: //Second column takes up 75% StephaneLenclud@191: layout.Columns[1].Width = 75F; StephaneLenclud@191: //Send layout to server StephaneLenclud@191: iClient.SetLayout(layout); StephaneLenclud@191: StephaneLenclud@191: //Set a bitmap for our first field StephaneLenclud@191: int x1 = 0; StephaneLenclud@191: int y1 = 0; StephaneLenclud@191: int x2 = 64; StephaneLenclud@191: int y2 = 64; StephaneLenclud@191: StephaneLenclud@191: Bitmap bitmap = new Bitmap(x2, y2); StephaneLenclud@191: Pen blackPen = new Pen(Color.Black, 3); StephaneLenclud@191: StephaneLenclud@191: // Draw line to screen. StephaneLenclud@191: using (var graphics = Graphics.FromImage(bitmap)) StephaneLenclud@191: { StephaneLenclud@191: graphics.DrawLine(blackPen, x1, y1, x2, y2); StephaneLenclud@191: graphics.DrawLine(blackPen, x1, y2, x2, y1); StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: //Create a bitmap field from the bitmap we just created StephaneLenclud@191: //We want our bitmap field to span across two rows StephaneLenclud@191: BitmapField bitmapField = new BitmapField(bitmap, 0, 0, 1, 2); StephaneLenclud@191: StephaneLenclud@191: //Set texts StephaneLenclud@191: iClient.CreateFields(new DataField[] StephaneLenclud@191: { StephaneLenclud@191: bitmapField, StephaneLenclud@191: new TextField(textBoxTop.Text, Alignment, 1, 0), StephaneLenclud@191: new TextField(textBoxBottom.Text, Alignment, 1, 1) StephaneLenclud@191: }); StephaneLenclud@191: StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: private void buttonIndicatorsLayout_Click(object sender, EventArgs e) StephaneLenclud@191: { StephaneLenclud@191: //Define a 2 by 4 layout StephaneLenclud@191: TableLayout layout = new TableLayout(2, 4); StephaneLenclud@191: //First column StephaneLenclud@191: layout.Columns[0].Width = 87.5F; StephaneLenclud@191: //Second column StephaneLenclud@191: layout.Columns[1].Width = 12.5F; StephaneLenclud@191: //Send layout to server StephaneLenclud@191: iClient.SetLayout(layout); StephaneLenclud@191: StephaneLenclud@191: //Create a bitmap for our indicators field StephaneLenclud@191: int x1 = 0; StephaneLenclud@191: int y1 = 0; StephaneLenclud@191: int x2 = 32; StephaneLenclud@191: int y2 = 16; StephaneLenclud@191: StephaneLenclud@191: Bitmap bitmap = new Bitmap(x2, y2); StephaneLenclud@191: Pen blackPen = new Pen(Color.Black, 3); StephaneLenclud@191: StephaneLenclud@191: // Draw line to screen. StephaneLenclud@191: using (var graphics = Graphics.FromImage(bitmap)) StephaneLenclud@191: { StephaneLenclud@191: graphics.DrawLine(blackPen, x1, y1, x2, y2); StephaneLenclud@191: graphics.DrawLine(blackPen, x1, y2, x2, y1); StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: //Create a bitmap field from the bitmap we just created StephaneLenclud@191: DataField indicator1 = new BitmapField(bitmap, 1, 0); StephaneLenclud@191: //Create a bitmap field from the bitmap we just created StephaneLenclud@191: DataField indicator2 = new BitmapField(bitmap, 1, 1); StephaneLenclud@191: //Create a bitmap field from the bitmap we just created StephaneLenclud@191: DataField indicator3 = new BitmapField(bitmap, 1, 2); StephaneLenclud@191: //Create a bitmap field from the bitmap we just created StephaneLenclud@191: DataField indicator4 = new BitmapField(bitmap, 1, 3); StephaneLenclud@191: StephaneLenclud@191: // StephaneLenclud@191: TextField textFieldTop = new TextField(textBoxTop.Text, Alignment, 0, 0, 1, 2); StephaneLenclud@191: TextField textFieldBottom = new TextField(textBoxBottom.Text, Alignment, 0, 2, 1, 2); StephaneLenclud@191: StephaneLenclud@191: //Set texts StephaneLenclud@191: iClient.CreateFields(new DataField[] StephaneLenclud@191: { StephaneLenclud@191: textFieldTop, StephaneLenclud@191: textFieldBottom, StephaneLenclud@191: indicator1, StephaneLenclud@191: indicator2, StephaneLenclud@191: indicator3, StephaneLenclud@191: indicator4 StephaneLenclud@191: }); StephaneLenclud@191: StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: private void buttonUpdateTexts_Click(object sender, EventArgs e) StephaneLenclud@191: { StephaneLenclud@191: StephaneLenclud@191: bool res = iClient.SetFields(new DataField[] StephaneLenclud@191: { StephaneLenclud@191: new TextField(textBoxTop.Text, Alignment,0,0), StephaneLenclud@191: new TextField(textBoxBottom.Text, Alignment,0,1) StephaneLenclud@191: }); StephaneLenclud@191: StephaneLenclud@191: if (!res) StephaneLenclud@191: { StephaneLenclud@191: MessageBox.Show("Create you fields first", "Field update error", MessageBoxButtons.OK, MessageBoxIcon.Error); StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: private void buttonLayoutOneTextField_Click(object sender, EventArgs e) StephaneLenclud@191: { StephaneLenclud@191: //Set one column one line layout StephaneLenclud@191: TableLayout layout = new TableLayout(1, 1); StephaneLenclud@191: iClient.SetLayout(layout); StephaneLenclud@191: StephaneLenclud@191: //Set our fields StephaneLenclud@191: iClient.CreateFields(new DataField[] StephaneLenclud@191: { StephaneLenclud@191: new TextField(textBoxTop.Text, Alignment) StephaneLenclud@191: }); StephaneLenclud@191: } StephaneLenclud@191: StephaneLenclud@191: private void numericUpDownPriority_ValueChanged(object sender, EventArgs e) StephaneLenclud@191: { StephaneLenclud@191: iClient.SetPriority((uint)numericUpDownPriority.Value); StephaneLenclud@191: } StephaneLenclud@191: } StephaneLenclud@191: }