# HG changeset patch # User Stephane Lenclud # Date 1453526595 -3600 # Node ID 3d8af0e778f4b6aadf759646df3339a472ba4c8b # Parent f2d8620e24345d5db2f800e8b06751b80a70361e Switched to SharpLibDisplay. diff -r f2d8620e2434 -r 3d8af0e778f4 GUI/SharpDisplay.cs --- a/GUI/SharpDisplay.cs Tue Feb 03 10:14:18 2015 +0100 +++ b/GUI/SharpDisplay.cs Sat Jan 23 06:23:15 2016 +0100 @@ -20,7 +20,7 @@ using System.Runtime.InteropServices; using UacHelpers; using System.ServiceModel; -using SharpDisplay; +using SharpLib.Display; namespace OpenHardwareMonitor.GUI @@ -31,13 +31,13 @@ private PersistentSettings settings; private UnitManager unitManager; private List iSensors = new List(); - private global::SharpDisplay.DisplayClient iClient; - DataField iTextFieldTop; - DataField iTextFieldBottom; - DataField iTextFieldTopRight; - DataField iTextFieldBottomRight; + private Client iClient; + TextField iTextFieldTop; + TextField iTextFieldBottom; + TextField iTextFieldTopRight; + TextField iTextFieldBottomRight; - DataField[] iTextFields; + DataField[] iTextFields; private int iNextSensorToDisplay = 0; private int iTickCounter = 0; @@ -53,12 +53,12 @@ //Connect our client //Instance context is then managed by our client class - iClient = new global::SharpDisplay.DisplayClient(); + iClient = new Client(); // - iTextFieldTop = new DataField(0); - iTextFieldBottom = new DataField(1); - iTextFieldTopRight = new DataField(2, "", ContentAlignment.MiddleRight); - iTextFieldBottomRight = new DataField(3, "", ContentAlignment.MiddleRight); + iTextFieldTop = new TextField("", ContentAlignment.MiddleLeft,0,0); + iTextFieldBottom = new TextField("", ContentAlignment.MiddleLeft, 0, 1); + iTextFieldTopRight = new TextField("", ContentAlignment.MiddleRight,1,0); + iTextFieldBottomRight = new TextField("", ContentAlignment.MiddleRight,1,1); // iClient.Open(); iClient.SetName("Open Hardware Monitor"); diff -r f2d8620e2434 -r 3d8af0e778f4 GUI/SharpDisplayClient.cs --- a/GUI/SharpDisplayClient.cs Tue Feb 03 10:14:18 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,291 +0,0 @@ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using SharpDisplay; -using System.ServiceModel; -using System.ServiceModel.Channels; - - -namespace SharpDisplay -{ - /// - /// - /// - [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] - public class Callback : ICallback, IDisposable - { - private DisplayClient DisplayClient { get; set; } - - public Callback(DisplayClient aClient) - { - DisplayClient = aClient; - } - - public void OnConnected() - { - //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread); - //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId); - - MessageBox.Show("OnConnected()", "Client"); - } - - - public void OnCloseOrder() - { - DisplayClient.Close(); - //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread); - //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId); - - //MessageBox.Show("OnServerClosing()", "Client"); - //MainForm.CloseConnectionThreadSafe(); - //MainForm.CloseThreadSafe(); - } - - //From IDisposable - public void Dispose() - { - - } - } - - - /// - /// - /// - [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] - public class Client : DuplexClientBase - { - public string SessionId { get { return InnerChannel.SessionId; } } - - public Client(ICallback aCallback) - : base(new InstanceContext(aCallback), new NetTcpBinding(SecurityMode.None, true), new EndpointAddress("net.tcp://localhost:8001/DisplayService")) - { } - - public void SetName(string aClientName) - { - Channel.SetName(aClientName); - } - - public void SetLayout(TableLayout aLayout) - { - Channel.SetLayout(aLayout); - } - - public void SetField(DataField aField) - { - Channel.SetField(aField); - } - - public void SetFields(System.Collections.Generic.IList aFields) - { - Channel.SetFields(aFields); - } - - public int ClientCount() - { - return Channel.ClientCount(); - } - - public bool IsReady() - { - return State == CommunicationState.Opened || State == CommunicationState.Created; - } - } - - - /// - /// Handle connection with our Sharp Display Server. - /// If the connection is faulted it will attempt to restart it. - /// - public class DisplayClient - { - private Client iClient; - private Callback iCallback; - private bool resetingConnection = false; - - //private MainForm MainForm { get; set; } - public string SessionId { get { return iClient.SessionId; } } - public string Name { get; private set; } - private TableLayout Layout { get; set; } - private System.Collections.Generic.IList Fields { get; set; } - - - public DisplayClient(/*MainForm aMainForm*/) - { - //MainForm = aMainForm; - Name = ""; - Fields = new DataField[]{}; - } - - /// - /// Initialize our server connection. - /// - public void Open() - { - iCallback = new Callback(this); - iClient = new Client(iCallback); - } - - /// - /// Terminate our server connection. - /// - public void Close() - { - iClient.Close(); - iClient = null; - iCallback.Dispose(); - iCallback = null; - } - - /// - /// Tells whether a server connection is available. - /// - /// True if a server connection is available. False otherwise. - public bool IsReady() - { - return (iClient != null && iCallback != null && iClient.IsReady()); - } - - /// - /// Check if our server connection is available and attempt reset it if it isn't. - /// This is notably dealing with timed out connections. - /// - public void CheckConnection() - { - if (!IsReady() && !resetingConnection) - { - //Try to reconnect - Open(); - - //Avoid stack overflow in case of persisting failure - resetingConnection = true; - - try - { - //On reconnect there is a bunch of properties we need to reset - if (Name != "") - { - iClient.SetName(Name); - } - - SetLayout(Layout); - iClient.SetFields(Fields); - } - finally - { - //Make sure our this state does not get out of sync - resetingConnection = true; - } - } - } - - public void SetName(string aClientName) - { - Name = aClientName; - CheckConnection(); - iClient.SetName(aClientName); - } - - - public void SetLayout(TableLayout aLayout) - { - Layout = aLayout; - CheckConnection(); - iClient.SetLayout(aLayout); - } - - /// - /// Set the specified field. - /// - /// - /// True if the specified field was set client side. False means you need to redefine all your fields using CreateFields. - public bool SetField(DataField aField) - { - int i = 0; - bool fieldFound = false; - foreach (DataField field in Fields) - { - if (field.Index == aField.Index) - { - //Update our field then - Fields[i] = aField; - fieldFound = true; - break; - } - i++; - } - - if (!fieldFound) - { - //Field not found, make to use SetFields with all your fields at least once after setting your layout. - return false; - } - - CheckConnection(); - iClient.SetField(aField); - return true; - } - - /// - /// Use this function when updating existing fields. - /// - /// - public bool SetFields(System.Collections.Generic.IList aFields) - { - int fieldFoundCount = 0; - foreach (DataField fieldUpdate in aFields) - { - int i = 0; - foreach (DataField existingField in Fields) - { - if (existingField.Index == fieldUpdate.Index) - { - //Update our field then - Fields[i] = fieldUpdate; - fieldFoundCount++; - //Move on to the next field - break; - } - i++; - } - } - - // - if (fieldFoundCount!=aFields.Count) - { - //Field not found, make sure to use SetFields with all your fields at least once after setting your layout. - return false; - } - - CheckConnection(); - iClient.SetFields(aFields); - return true; - } - - /// - /// Use this function when creating your fields. - /// - /// - public void CreateFields(System.Collections.Generic.IList aFields) - { - Fields = aFields; - CheckConnection(); - iClient.SetFields(aFields); - } - - public int ClientCount() - { - CheckConnection(); - return iClient.ClientCount(); - } - - - - } - - -} diff -r f2d8620e2434 -r 3d8af0e778f4 GUI/SharpDisplayInterface.cs --- a/GUI/SharpDisplayInterface.cs Tue Feb 03 10:14:18 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,204 +0,0 @@ -// -// Define a public API for both SharpDisplay client and server to use. -// - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.ServiceModel; -using System.Collections; -using System.Drawing; -using System.Runtime.Serialization; -using System.Windows.Forms; - - -namespace SharpDisplay -{ - /// - /// For client to specify a specific layout. - /// - [DataContract] - public class TableLayout - { - public TableLayout() - { - Columns = new List(); - Rows = new List(); - Cells = new List(); - } - - public TableLayout(int aColumnCount, int aRowCount) - { - Columns = new List(); - Rows = new List(); - - for (int i = 0; i < aColumnCount; i++) - { - Columns.Add(new ColumnStyle(SizeType.Percent, 100 / aColumnCount)); - } - - for (int i = 0; i < aRowCount; i++) - { - Rows.Add(new RowStyle(SizeType.Percent, 100 / aRowCount)); - } - } - - [DataMember] - public List Cells { get; set; } - - [DataMember] - public List Columns { get; set; } - - [DataMember] - public List Rows { get; set; } - } - - /// - /// - /// - [DataContract] - public class DataField - { - public DataField() - { - Index = 0; - ColumnSpan = 1; - RowSpan = 1; - //Text - Text = ""; - Alignment = ContentAlignment.MiddleLeft; - //Bitmap - Bitmap = null; - } - - //Text constructor - public DataField(int aIndex, string aText = "", ContentAlignment aAlignment = ContentAlignment.MiddleLeft) - { - ColumnSpan = 1; - RowSpan = 1; - Index = aIndex; - Text = aText; - Alignment = aAlignment; - // - Bitmap = null; - } - - //Bitmap constructor - public DataField(int aIndex, Bitmap aBitmap) - { - ColumnSpan = 1; - RowSpan = 1; - Index = aIndex; - Bitmap = aBitmap; - //Text - Text = ""; - Alignment = ContentAlignment.MiddleLeft; - } - - - //Generic layout properties - [DataMember] - public int Index { get; set; } - - [DataMember] - public int Column { get; set; } - - [DataMember] - public int Row { get; set; } - - [DataMember] - public int ColumnSpan { get; set; } - - [DataMember] - public int RowSpan { get; set; } - - //Text properties - [DataMember] - public string Text { get; set; } - - [DataMember] - public ContentAlignment Alignment { get; set; } - - //Bitmap properties - [DataMember] - public Bitmap Bitmap { get; set; } - - // - public bool IsBitmap { get { return Bitmap != null; } } - // - public bool IsText { get { return Bitmap == null; } } - // - public bool IsSameLayout(DataField aField) - { - return (aField.ColumnSpan == ColumnSpan && aField.RowSpan == RowSpan); - } - } - - /// - /// Define our SharpDisplay service. - /// Clients and servers must implement it to communicate with one another. - /// Through this service clients can send requests to a server. - /// Through this service a server session can receive requests from a client. - /// - [ServiceContract(CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)] - public interface IService - { - /// - /// Set the name of this client. - /// Name is a convenient way to recognize your client. - /// Naming you client is not mandatory. - /// In the absence of a name the session ID is often used instead. - /// - /// - [OperationContract(IsOneWay = true)] - void SetName(string aClientName); - - /// - /// - /// - [OperationContract(IsOneWay = true)] - void SetLayout(TableLayout aLayout); - - /// - /// Set the given field on your display. - /// Fields are often just lines of text or bitmaps. - /// - /// - [OperationContract(IsOneWay = true)] - void SetField(DataField aField); - - /// - /// Allows a client to set multiple fields at once. - /// - /// - [OperationContract(IsOneWay = true)] - void SetFields(System.Collections.Generic.IList aFields); - - /// - /// Provides the number of clients currently connected - /// - /// - [OperationContract()] - int ClientCount(); - - } - - /// - /// SharDisplay callback provides a means for a server to notify its clients. - /// - public interface ICallback - { - [OperationContract(IsOneWay = true)] - void OnConnected(); - - /// - /// Tell our client to close its connection. - /// Notably sent when the server is shutting down. - /// - [OperationContract(IsOneWay = true)] - void OnCloseOrder(); - } - -} diff -r f2d8620e2434 -r 3d8af0e778f4 OpenHardwareMonitor.csproj --- a/OpenHardwareMonitor.csproj Tue Feb 03 10:14:18 2015 +0100 +++ b/OpenHardwareMonitor.csproj Sat Jan 23 06:23:15 2016 +0100 @@ -65,6 +65,10 @@ External\OxyPlot.WindowsForms.dll + + packages\SharpLibDisplay.0.2.4\lib\net40\SharpLibDisplay.dll + True + @@ -116,8 +120,6 @@ - - @@ -188,6 +190,7 @@ + Designer diff -r f2d8620e2434 -r 3d8af0e778f4 packages.config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/packages.config Sat Jan 23 06:23:15 2016 +0100 @@ -0,0 +1,4 @@ + + + + \ No newline at end of file