# HG changeset patch
# User StephaneLenclud
# Date 1454511877 -3600
# Node ID 317fdfa4fbb600b040c5606d54da62191a7b8be0
# Parent d0919a87be128c271b26e94bfd608668f08b4066
Basic idle client functionality.
diff -r d0919a87be12 -r 317fdfa4fbb6 Clients/Idle/FormClientIdle.Designer.cs
--- a/Clients/Idle/FormClientIdle.Designer.cs Wed Feb 03 13:23:17 2016 +0100
+++ b/Clients/Idle/FormClientIdle.Designer.cs Wed Feb 03 16:04:37 2016 +0100
@@ -1,4 +1,5 @@
-namespace SharpDisplayIdleClient
+
+namespace SharpDisplayIdleClient
{
partial class FormClientIdle
{
@@ -28,20 +29,31 @@
///
private void InitializeComponent()
{
+ this.components = new System.ComponentModel.Container();
+ this.iTimer = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
- // FormIdleClient
+ // iTimer
+ //
+ this.iTimer.Tick += new System.EventHandler(this.iTimer_Tick);
+ //
+ // FormClientIdle
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(531, 303);
- this.Name = "FormIdleClient";
+ this.Name = "FormClientIdle";
this.Text = "Sharp Display Idle Client";
+ this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormClientIdle_FormClosing);
+ this.Load += new System.EventHandler(this.FormClientIdle_Load);
+ this.Shown += new System.EventHandler(this.FormClientIdle_Shown);
this.ResumeLayout(false);
}
#endregion
+
+ private System.Windows.Forms.Timer iTimer;
}
}
diff -r d0919a87be12 -r 317fdfa4fbb6 Clients/Idle/FormClientIdle.cs
--- a/Clients/Idle/FormClientIdle.cs Wed Feb 03 13:23:17 2016 +0100
+++ b/Clients/Idle/FormClientIdle.cs Wed Feb 03 16:04:37 2016 +0100
@@ -1,4 +1,23 @@
-using System;
+//
+// Copyright (C) 2014-2016 Stéphane Lenclud.
+//
+// This file is part of SharpDisplayManager.
+//
+// SharpDisplayManager is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// SharpDisplayManager is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with SharpDisplayManager. If not, see .
+//
+
+using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@@ -7,16 +26,187 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using System.Diagnostics;
+using SharpLib.Display;
+
namespace SharpDisplayIdleClient
{
+
+ ///
+ /// Sharp Display Client designed to act as an idle client.
+ /// It should take care of screen saving and other such concerns.
+ ///
public partial class FormClientIdle : Form
{
public StartParams Params { get; set; }
+ Client iClient;
+ ContentAlignment iAlignment;
+ TextField iTextField;
+
+ public delegate void CloseDelegate();
+ public delegate void CloseConnectionDelegate();
+
+
public FormClientIdle()
{
InitializeComponent();
}
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ private void FormClientIdle_Load(object sender, EventArgs e)
+ {
+ //Display client
+ iClient = new Client();
+ iClient.CloseOrderEvent += OnCloseOrder;
+ iClient.Open();
+ iClient.SetName("Idle");
+ iClient.SetPriority(SharpLib.Display.Priorities.Background);
+ SetupDisplayClient();
+
+ //Timer
+ iTimer.Interval = IntervalToNextMinute();
+ iTimer.Start();
+ }
+
+ ///
+ ///
+ ///
+ ///
+ public static int IntervalToNextMinute()
+ {
+ DateTime now = DateTime.Now;
+ return 60000 - now.Millisecond;
+ }
+
+
+ ///
+ ///
+ ///
+ ///
+ public bool IsClientReady()
+ {
+ return (iClient != null && iClient.IsReady());
+ }
+
+ ///
+ ///
+ ///
+ public void SetupDisplayClient()
+ {
+ //Setup our layout
+
+ //Set one column one line layout
+ TableLayout layout = new TableLayout(1, 1);
+ iClient.SetLayout(layout);
+
+ //Setup our fields
+ iAlignment = ContentAlignment.MiddleCenter;
+ iTextField = new TextField(DateTime.Now.ToString("t"), iAlignment, 0, 0);
+
+ //Set our fields
+ iClient.CreateFields(new DataField[]
+ {
+ iTextField
+ });
+ }
+
+ public void OnCloseOrder()
+ {
+ CloseThreadSafe();
+ }
+
+ ///
+ ///
+ ///
+ public void CloseThreadSafe()
+ {
+ if (this.InvokeRequired)
+ {
+ //Not in the proper thread, invoke ourselves
+ CloseDelegate d = new CloseDelegate(CloseThreadSafe);
+ this.Invoke(d, new object[] { });
+ }
+ else
+ {
+ //We are in the proper thread
+ Close();
+ }
+ }
+
+ ///
+ ///
+ ///
+ public void CloseConnectionThreadSafe()
+ {
+ if (this.InvokeRequired)
+ {
+ //Not in the proper thread, invoke ourselves
+ CloseConnectionDelegate d = new CloseConnectionDelegate(CloseConnectionThreadSafe);
+ this.Invoke(d, new object[] { });
+ }
+ else
+ {
+ //We are in the proper thread
+ if (IsClientReady())
+ {
+ string sessionId = iClient.SessionId;
+ Trace.TraceInformation("Closing client: " + sessionId);
+ iClient.Close();
+ Trace.TraceInformation("Closed client: " + sessionId);
+ }
+
+ iClient = null;
+ }
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ private void FormClientIdle_FormClosing(object sender, FormClosingEventArgs e)
+ {
+ CloseConnectionThreadSafe();
+ }
+
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ private void iTimer_Tick(object sender, EventArgs e)
+ {
+ //Timer
+ iTimer.Interval = IntervalToNextMinute();
+ iTimer.Start();
+
+ //
+ if (String.IsNullOrEmpty(iTextField.Text))
+ {
+ //Time to show our time
+ iTextField.Text = DateTime.Now.ToString("t");
+ }
+ else
+ {
+ //Do some screen saving
+ iTextField.Text = "";
+ }
+
+ // Update our field
+ iClient.SetField(iTextField);
+ }
+
+ private void FormClientIdle_Shown(object sender, EventArgs e)
+ {
+ //Visible = false;
+ }
}
+
}
diff -r d0919a87be12 -r 317fdfa4fbb6 Clients/Idle/FormClientIdle.resx
--- a/Clients/Idle/FormClientIdle.resx Wed Feb 03 13:23:17 2016 +0100
+++ b/Clients/Idle/FormClientIdle.resx Wed Feb 03 16:04:37 2016 +0100
@@ -117,4 +117,7 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 17, 17
+
\ No newline at end of file
diff -r d0919a87be12 -r 317fdfa4fbb6 Clients/Idle/Program.cs
--- a/Clients/Idle/Program.cs Wed Feb 03 13:23:17 2016 +0100
+++ b/Clients/Idle/Program.cs Wed Feb 03 16:04:37 2016 +0100
@@ -1,5 +1,5 @@
//
-// Copyright (C) 2014-2015 Stéphane Lenclud.
+// Copyright (C) 2014-2016 Stéphane Lenclud.
//
// This file is part of SharpDisplayManager.
//
@@ -52,6 +52,8 @@
Application.SetCompatibleTextRenderingDefault(false);
FormClientIdle form = new FormClientIdle();
form.Params = (StartParams)aParams;
+ form.WindowState = FormWindowState.Minimized;
+ form.ShowInTaskbar = false;
Application.Run(form);
}