# HG changeset patch # User StephaneLenclud # Date 1434883205 -7200 # Node ID 53dbdcf73f08e1d8d28e6613d0c0ee65c8ed5763 # Parent 8e4c7cca77b892d526dc00d22581cf2954946a33# Parent 9e1ce603fe7130fdb20be4c8201617beaaf2821d Merge diff -r 8e4c7cca77b8 -r 53dbdcf73f08 Server/ClientData.cs --- a/Server/ClientData.cs Sat Jun 13 11:29:22 2015 +0200 +++ b/Server/ClientData.cs Sun Jun 21 12:40:05 2015 +0200 @@ -28,5 +28,8 @@ public List Fields { get; set; } public TableLayout Layout { get; set; } public ICallback Callback { get; set; } + + //Client management + public DateTime LastSwitchTime { get; set; } } } diff -r 8e4c7cca77b8 -r 53dbdcf73f08 Server/MainForm.cs --- a/Server/MainForm.cs Sat Jun 13 11:29:22 2015 +0200 +++ b/Server/MainForm.cs Sun Jun 21 12:40:05 2015 +0200 @@ -555,7 +555,7 @@ /// This will take care of applying our client layout and set data fields. /// /// - void SetCurrentClient(string aSessionId) + void SetCurrentClient(string aSessionId, bool aForce=false) { if (aSessionId == iCurrentClientSessionId) { @@ -564,8 +564,26 @@ return; } + + //Check when was the last time we switched to that client + if (iCurrentClientData != null) + { + double lastSwitchToClientSecondsAgo = (DateTime.Now - iCurrentClientData.LastSwitchTime).TotalSeconds; + //TODO: put that hard coded value as a client property + //Clients should be able to define how often they can be interrupted + //Thus a background client can set this to zero allowing any other client to interrupt at any time + //We could also compute this delay by looking at the requests frequencies? + if (!aForce && (lastSwitchToClientSecondsAgo < 30)) //Make sure a client is on for at least 30 seconds + { + //Don't switch clients too often + return; + } + } + //Set current client ID. iCurrentClientSessionId = aSessionId; + //Set the time we last switched to that client + iClients[aSessionId].LastSwitchTime = DateTime.Now; //Fetch and set current client data. iCurrentClientData = iClients[aSessionId]; //Apply layout and set data fields. @@ -1320,7 +1338,20 @@ private void treeViewClients_AfterSelect(object sender, TreeViewEventArgs e) { + //Root node must have at least one child + if (e.Node.Nodes.Count == 0) + { + return; + } + //If the selected node is the root node of a client then switch to it + string sessionId=e.Node.Nodes[0].Text; //First child of a root node is the sessionId + if (iClients.ContainsKey(sessionId)) //Check that's actually what we are looking at + { + //We have a valid session just switch to that client + SetCurrentClient(sessionId,true); + } + } @@ -1405,8 +1436,8 @@ ClientData client = iClients[aSessionId]; if (client != null) { + //Set our client layout then client.Layout = aLayout; - UpdateTableLayoutPanel(client); // UpdateClientTreeViewNode(client); } @@ -1440,63 +1471,69 @@ /// /// private void SetClientField(string aSessionId, DataField aField) - { - SetCurrentClient(aSessionId); + { + //TODO: should check if the field actually changed? + ClientData client = iClients[aSessionId]; - if (client != null) + bool layoutChanged = false; + + //Make sure all our fields are in place + while (client.Fields.Count < (aField.Index + 1)) { - bool somethingChanged = false; + //Add a text field with proper index + client.Fields.Add(new DataField(client.Fields.Count)); + layoutChanged = true; + } - //Make sure all our fields are in place - while (client.Fields.Count < (aField.Index + 1)) + if (client.Fields[aField.Index].IsSameLayout(aField)) + { + //Same layout just update our field + client.Fields[aField.Index] = aField; + //If we are updating a field in our current client we need to update it in our panel + if (aSessionId == iCurrentClientSessionId) { - //Add a text field with proper index - client.Fields.Add(new DataField(client.Fields.Count)); - somethingChanged = true; - } - - if (client.Fields[aField.Index].IsSameLayout(aField)) - { - //Same layout just update our field - client.Fields[aField.Index] = aField; - // - if (aField.IsText && tableLayoutPanel.Controls[aField.Index] is MarqueeLabel) + if (aField.IsText && aField.Index < tableLayoutPanel.Controls.Count && tableLayoutPanel.Controls[aField.Index] is MarqueeLabel) { //Text field control already in place, just change the text MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aField.Index]; - somethingChanged = (label.Text != aField.Text || label.TextAlign != aField.Alignment); + layoutChanged = (label.Text != aField.Text || label.TextAlign != aField.Alignment); label.Text = aField.Text; label.TextAlign = aField.Alignment; } - else if (aField.IsBitmap && tableLayoutPanel.Controls[aField.Index] is PictureBox) + else if (aField.IsBitmap && aField.Index < tableLayoutPanel.Controls.Count && tableLayoutPanel.Controls[aField.Index] is PictureBox) { - somethingChanged = true; //TODO: Bitmap comp or should we leave that to clients? + layoutChanged = true; //TODO: Bitmap comp or should we leave that to clients? //Bitmap field control already in place just change the bitmap PictureBox pictureBox = (PictureBox)tableLayoutPanel.Controls[aField.Index]; pictureBox.Image = aField.Bitmap; } else { - somethingChanged = true; - //The requested control in our layout it not of the correct type - //Wrong control type, re-create them all - UpdateTableLayoutPanel(iCurrentClientData); + layoutChanged = true; } } - else + } + else + { + layoutChanged = true; + //Different layout, need to rebuild it + client.Fields[aField.Index] = aField; + } + + // + if (layoutChanged) + { + UpdateClientTreeViewNode(client); + //Our layout has changed, if we are already the current client we need to update our panel + if (aSessionId == iCurrentClientSessionId) { - somethingChanged = true; - //Different layout, need to rebuild it - client.Fields[aField.Index] = aField; + //Apply layout and set data fields. UpdateTableLayoutPanel(iCurrentClientData); } + } - // - if (somethingChanged) - { - UpdateClientTreeViewNode(client); - } - } + //When a client field is set we try switching to this client to present the new information to our user + SetCurrentClient(aSessionId); } /// @@ -1646,6 +1683,7 @@ TableLayout layout = aClient.Layout; int fieldCount = 0; + //First clean our current panel tableLayoutPanel.Controls.Clear(); tableLayoutPanel.RowStyles.Clear(); tableLayoutPanel.ColumnStyles.Clear(); diff -r 8e4c7cca77b8 -r 53dbdcf73f08 Server/SharpDisplayManager.csproj --- a/Server/SharpDisplayManager.csproj Sat Jun 13 11:29:22 2015 +0200 +++ b/Server/SharpDisplayManager.csproj Sun Jun 21 12:40:05 2015 +0200 @@ -32,8 +32,8 @@ true index.htm false - 3 - 0.4.0.%2a + 2 + 0.4.1.%2a false true true