1.1 --- a/Server/MainForm.cs Sat Aug 16 11:15:42 2014 +0200
1.2 +++ b/Server/MainForm.cs Sun Aug 17 22:30:30 2014 +0200
1.3 @@ -20,27 +20,6 @@
1.4
1.5 namespace SharpDisplayManager
1.6 {
1.7 - /// <summary>
1.8 - /// A UI thread copy of a client relevant data.
1.9 - /// Keeping this copy in the UI thread helps us deal with threading issues.
1.10 - /// </summary>
1.11 - public class ClientData
1.12 - {
1.13 - public ClientData(string aSessionId, IDisplayServiceCallback aCallback)
1.14 - {
1.15 - SessionId = aSessionId;
1.16 - Name = "";
1.17 - Texts = new List<string>();
1.18 - Callback = aCallback;
1.19 - }
1.20 -
1.21 - public string SessionId { get; set;}
1.22 - public string Name { get; set;}
1.23 - public List<string> Texts { get; set;}
1.24 - public IDisplayServiceCallback Callback { get; set;}
1.25 - }
1.26 -
1.27 -
1.28 public partial class MainForm : Form
1.29 {
1.30 DateTime LastTickTime;
1.31 @@ -478,8 +457,8 @@
1.32 //Delegates are used for our thread safe method
1.33 public delegate void AddClientDelegate(string aSessionId, IDisplayServiceCallback aCallback);
1.34 public delegate void RemoveClientDelegate(string aSessionId);
1.35 - public delegate void SetTextDelegate(int aLineIndex, string aText);
1.36 - public delegate void SetTextsDelegate(System.Collections.Generic.IList<string> aTexts);
1.37 + public delegate void SetTextDelegate(string SessionId, int aLineIndex, string aText);
1.38 + public delegate void SetTextsDelegate(string SessionId, System.Collections.Generic.IList<string> aTexts);
1.39 public delegate void SetClientNameDelegate(string aSessionId, string aName);
1.40
1.41
1.42 @@ -545,25 +524,39 @@
1.43 /// </summary>
1.44 /// <param name="aLineIndex"></param>
1.45 /// <param name="aText"></param>
1.46 - public void SetTextThreadSafe(int aLineIndex, string aText)
1.47 + public void SetTextThreadSafe(string aSessionId, int aLineIndex, string aText)
1.48 {
1.49 if (this.InvokeRequired)
1.50 {
1.51 //Not in the proper thread, invoke ourselves
1.52 SetTextDelegate d = new SetTextDelegate(SetTextThreadSafe);
1.53 - this.Invoke(d, new object[] { aLineIndex, aText });
1.54 + this.Invoke(d, new object[] { aSessionId, aLineIndex, aText });
1.55 }
1.56 else
1.57 {
1.58 - //We are in the proper thread
1.59 - //Only support two lines for now
1.60 - if (aLineIndex == 0)
1.61 + ClientData client = iClients[aSessionId];
1.62 + if (client != null)
1.63 {
1.64 - marqueeLabelTop.Text = aText;
1.65 - }
1.66 - else if (aLineIndex == 1)
1.67 - {
1.68 - marqueeLabelBottom.Text = aText;
1.69 + //Make sure all our texts are in place
1.70 + while (client.Texts.Count < (aLineIndex + 1))
1.71 + {
1.72 + client.Texts.Add("");
1.73 + }
1.74 + client.Texts[aLineIndex] = aText;
1.75 +
1.76 + //We are in the proper thread
1.77 + //Only support two lines for now
1.78 + if (aLineIndex == 0)
1.79 + {
1.80 + marqueeLabelTop.Text = aText;
1.81 + }
1.82 + else if (aLineIndex == 1)
1.83 + {
1.84 + marqueeLabelBottom.Text = aText;
1.85 + }
1.86 +
1.87 +
1.88 + UpdateClientTreeViewNode(client);
1.89 }
1.90 }
1.91 }
1.92 @@ -572,28 +565,49 @@
1.93 ///
1.94 /// </summary>
1.95 /// <param name="aTexts"></param>
1.96 - public void SetTextsThreadSafe(System.Collections.Generic.IList<string> aTexts)
1.97 + public void SetTextsThreadSafe(string aSessionId, System.Collections.Generic.IList<string> aTexts)
1.98 {
1.99 if (this.InvokeRequired)
1.100 {
1.101 //Not in the proper thread, invoke ourselves
1.102 SetTextsDelegate d = new SetTextsDelegate(SetTextsThreadSafe);
1.103 - this.Invoke(d, new object[] { aTexts });
1.104 + this.Invoke(d, new object[] { aSessionId, aTexts });
1.105 }
1.106 else
1.107 {
1.108 - //We are in the proper thread
1.109 - //Only support two lines for now
1.110 - for (int i = 0; i < aTexts.Count; i++)
1.111 + ClientData client = iClients[aSessionId];
1.112 + if (client != null)
1.113 {
1.114 - if (i == 0)
1.115 + //Populate our client with the given texts
1.116 + int j = 0;
1.117 + foreach (string text in aTexts)
1.118 {
1.119 - marqueeLabelTop.Text = aTexts[i];
1.120 + if (client.Texts.Count < (j + 1))
1.121 + {
1.122 + client.Texts.Add(text);
1.123 + }
1.124 + else
1.125 + {
1.126 + client.Texts[j]=text;
1.127 + }
1.128 + j++;
1.129 }
1.130 - else if (i == 1)
1.131 + //We are in the proper thread
1.132 + //Only support two lines for now
1.133 + for (int i = 0; i < aTexts.Count; i++)
1.134 {
1.135 - marqueeLabelBottom.Text = aTexts[i];
1.136 + if (i == 0)
1.137 + {
1.138 + marqueeLabelTop.Text = aTexts[i];
1.139 + }
1.140 + else if (i == 1)
1.141 + {
1.142 + marqueeLabelBottom.Text = aTexts[i];
1.143 + }
1.144 }
1.145 +
1.146 +
1.147 + UpdateClientTreeViewNode(client);
1.148 }
1.149 }
1.150 }
1.151 @@ -683,8 +697,30 @@
1.152 textsRoot.Nodes.Add(new TreeNode(text));
1.153 }
1.154 }
1.155 +
1.156 + node.ExpandAll();
1.157 }
1.158 }
1.159
1.160 }
1.161 +
1.162 + /// <summary>
1.163 + /// A UI thread copy of a client relevant data.
1.164 + /// Keeping this copy in the UI thread helps us deal with threading issues.
1.165 + /// </summary>
1.166 + public class ClientData
1.167 + {
1.168 + public ClientData(string aSessionId, IDisplayServiceCallback aCallback)
1.169 + {
1.170 + SessionId = aSessionId;
1.171 + Name = "";
1.172 + Texts = new List<string>();
1.173 + Callback = aCallback;
1.174 + }
1.175 +
1.176 + public string SessionId { get; set; }
1.177 + public string Name { get; set; }
1.178 + public List<string> Texts { get; set; }
1.179 + public IDisplayServiceCallback Callback { get; set; }
1.180 + }
1.181 }