Merge
authorStephaneLenclud
Sun, 21 Jun 2015 12:40:05 +0200
changeset 14553dbdcf73f08
parent 144 8e4c7cca77b8
parent 143 9e1ce603fe71
child 146 f39b1a8bafb1
Merge
Server/SharpDisplayManager.csproj
     1.1 --- a/Server/ClientData.cs	Sat Jun 13 11:29:22 2015 +0200
     1.2 +++ b/Server/ClientData.cs	Sun Jun 21 12:40:05 2015 +0200
     1.3 @@ -28,5 +28,8 @@
     1.4          public List<DataField> Fields { get; set; }
     1.5          public TableLayout Layout { get; set; }
     1.6          public ICallback Callback { get; set; }
     1.7 +
     1.8 +        //Client management
     1.9 +        public DateTime LastSwitchTime { get; set; }
    1.10      }
    1.11  }
     2.1 --- a/Server/MainForm.cs	Sat Jun 13 11:29:22 2015 +0200
     2.2 +++ b/Server/MainForm.cs	Sun Jun 21 12:40:05 2015 +0200
     2.3 @@ -555,7 +555,7 @@
     2.4          /// This will take care of applying our client layout and set data fields.
     2.5          /// </summary>
     2.6          /// <param name="aSessionId"></param>
     2.7 -        void SetCurrentClient(string aSessionId)
     2.8 +        void SetCurrentClient(string aSessionId, bool aForce=false)
     2.9          {
    2.10              if (aSessionId == iCurrentClientSessionId)
    2.11              {
    2.12 @@ -564,8 +564,26 @@
    2.13                  return;
    2.14              }
    2.15  
    2.16 +
    2.17 +            //Check when was the last time we switched to that client
    2.18 +            if (iCurrentClientData != null)
    2.19 +            {
    2.20 +                double lastSwitchToClientSecondsAgo = (DateTime.Now - iCurrentClientData.LastSwitchTime).TotalSeconds;
    2.21 +                //TODO: put that hard coded value as a client property
    2.22 +                //Clients should be able to define how often they can be interrupted
    2.23 +                //Thus a background client can set this to zero allowing any other client to interrupt at any time
    2.24 +                //We could also compute this delay by looking at the requests frequencies?
    2.25 +                if (!aForce && (lastSwitchToClientSecondsAgo < 30)) //Make sure a client is on for at least 30 seconds
    2.26 +                {
    2.27 +                    //Don't switch clients too often
    2.28 +                    return;
    2.29 +                }
    2.30 +            }
    2.31 +
    2.32              //Set current client ID.
    2.33              iCurrentClientSessionId = aSessionId;
    2.34 +            //Set the time we last switched to that client
    2.35 +            iClients[aSessionId].LastSwitchTime = DateTime.Now;
    2.36              //Fetch and set current client data.
    2.37              iCurrentClientData = iClients[aSessionId];
    2.38              //Apply layout and set data fields.
    2.39 @@ -1320,7 +1338,20 @@
    2.40  
    2.41          private void treeViewClients_AfterSelect(object sender, TreeViewEventArgs e)
    2.42          {
    2.43 +            //Root node must have at least one child
    2.44 +            if (e.Node.Nodes.Count == 0)
    2.45 +            {
    2.46 +                return;
    2.47 +            }
    2.48  
    2.49 +            //If the selected node is the root node of a client then switch to it
    2.50 +            string sessionId=e.Node.Nodes[0].Text; //First child of a root node is the sessionId
    2.51 +            if (iClients.ContainsKey(sessionId)) //Check that's actually what we are looking at
    2.52 +            {
    2.53 +                //We have a valid session just switch to that client
    2.54 +                SetCurrentClient(sessionId,true);
    2.55 +            }
    2.56 +            
    2.57          }
    2.58  
    2.59  
    2.60 @@ -1405,8 +1436,8 @@
    2.61                  ClientData client = iClients[aSessionId];
    2.62                  if (client != null)
    2.63                  {
    2.64 +                    //Set our client layout then
    2.65                      client.Layout = aLayout;
    2.66 -                    UpdateTableLayoutPanel(client);
    2.67                      //
    2.68                      UpdateClientTreeViewNode(client);
    2.69                  }
    2.70 @@ -1440,63 +1471,69 @@
    2.71          /// <param name="aSessionId"></param>
    2.72          /// <param name="aField"></param>
    2.73          private void SetClientField(string aSessionId, DataField aField)
    2.74 -        {
    2.75 -            SetCurrentClient(aSessionId);
    2.76 +        {   
    2.77 +            //TODO: should check if the field actually changed?
    2.78 +
    2.79              ClientData client = iClients[aSessionId];
    2.80 -            if (client != null)
    2.81 +            bool layoutChanged = false;
    2.82 +
    2.83 +            //Make sure all our fields are in place
    2.84 +            while (client.Fields.Count < (aField.Index + 1))
    2.85              {
    2.86 -                bool somethingChanged = false;
    2.87 +                //Add a text field with proper index
    2.88 +                client.Fields.Add(new DataField(client.Fields.Count));
    2.89 +                layoutChanged = true;
    2.90 +            }
    2.91  
    2.92 -                //Make sure all our fields are in place
    2.93 -                while (client.Fields.Count < (aField.Index + 1))
    2.94 +            if (client.Fields[aField.Index].IsSameLayout(aField))
    2.95 +            {
    2.96 +                //Same layout just update our field
    2.97 +                client.Fields[aField.Index] = aField;
    2.98 +                //If we are updating a field in our current client we need to update it in our panel
    2.99 +                if (aSessionId == iCurrentClientSessionId)
   2.100                  {
   2.101 -                    //Add a text field with proper index
   2.102 -                    client.Fields.Add(new DataField(client.Fields.Count));
   2.103 -                    somethingChanged = true;
   2.104 -                }
   2.105 -
   2.106 -                if (client.Fields[aField.Index].IsSameLayout(aField))
   2.107 -                {
   2.108 -                    //Same layout just update our field
   2.109 -                    client.Fields[aField.Index] = aField;
   2.110 -                    //
   2.111 -                    if (aField.IsText && tableLayoutPanel.Controls[aField.Index] is MarqueeLabel)
   2.112 +                    if (aField.IsText && aField.Index < tableLayoutPanel.Controls.Count && tableLayoutPanel.Controls[aField.Index] is MarqueeLabel)
   2.113                      {
   2.114                          //Text field control already in place, just change the text
   2.115                          MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aField.Index];
   2.116 -                        somethingChanged = (label.Text != aField.Text || label.TextAlign != aField.Alignment);
   2.117 +                        layoutChanged = (label.Text != aField.Text || label.TextAlign != aField.Alignment);
   2.118                          label.Text = aField.Text;
   2.119                          label.TextAlign = aField.Alignment;
   2.120                      }
   2.121 -                    else if (aField.IsBitmap && tableLayoutPanel.Controls[aField.Index] is PictureBox)
   2.122 +                    else if (aField.IsBitmap && aField.Index < tableLayoutPanel.Controls.Count && tableLayoutPanel.Controls[aField.Index] is PictureBox)
   2.123                      {
   2.124 -                        somethingChanged = true; //TODO: Bitmap comp or should we leave that to clients?
   2.125 +                        layoutChanged = true; //TODO: Bitmap comp or should we leave that to clients?
   2.126                          //Bitmap field control already in place just change the bitmap
   2.127                          PictureBox pictureBox = (PictureBox)tableLayoutPanel.Controls[aField.Index];
   2.128                          pictureBox.Image = aField.Bitmap;
   2.129                      }
   2.130                      else
   2.131                      {
   2.132 -                        somethingChanged = true;
   2.133 -                        //The requested control in our layout it not of the correct type
   2.134 -                        //Wrong control type, re-create them all
   2.135 -                        UpdateTableLayoutPanel(iCurrentClientData);
   2.136 +                        layoutChanged = true;
   2.137                      }
   2.138                  }
   2.139 -                else
   2.140 +            }
   2.141 +            else
   2.142 +            {
   2.143 +                layoutChanged = true;
   2.144 +                //Different layout, need to rebuild it
   2.145 +                client.Fields[aField.Index] = aField;
   2.146 +            }
   2.147 +
   2.148 +            //
   2.149 +            if (layoutChanged)
   2.150 +            {
   2.151 +                UpdateClientTreeViewNode(client);
   2.152 +                //Our layout has changed, if we are already the current client we need to update our panel
   2.153 +                if (aSessionId == iCurrentClientSessionId)
   2.154                  {
   2.155 -                    somethingChanged = true;
   2.156 -                    //Different layout, need to rebuild it
   2.157 -                    client.Fields[aField.Index] = aField;
   2.158 +                    //Apply layout and set data fields.
   2.159                      UpdateTableLayoutPanel(iCurrentClientData);
   2.160                  }
   2.161 +            }
   2.162  
   2.163 -                //
   2.164 -                if (somethingChanged)
   2.165 -                {
   2.166 -                    UpdateClientTreeViewNode(client);
   2.167 -                }
   2.168 -            }
   2.169 +            //When a client field is set we try switching to this client to present the new information to our user
   2.170 +            SetCurrentClient(aSessionId);
   2.171          }
   2.172  
   2.173          /// <summary>
   2.174 @@ -1646,6 +1683,7 @@
   2.175              TableLayout layout = aClient.Layout;
   2.176              int fieldCount = 0;
   2.177  
   2.178 +            //First clean our current panel
   2.179              tableLayoutPanel.Controls.Clear();
   2.180              tableLayoutPanel.RowStyles.Clear();
   2.181              tableLayoutPanel.ColumnStyles.Clear();
     3.1 --- a/Server/SharpDisplayManager.csproj	Sat Jun 13 11:29:22 2015 +0200
     3.2 +++ b/Server/SharpDisplayManager.csproj	Sun Jun 21 12:40:05 2015 +0200
     3.3 @@ -32,8 +32,8 @@
     3.4      <CreateWebPageOnPublish>true</CreateWebPageOnPublish>
     3.5      <WebPage>index.htm</WebPage>
     3.6      <OpenBrowserOnPublish>false</OpenBrowserOnPublish>
     3.7 -    <ApplicationRevision>3</ApplicationRevision>
     3.8 -    <ApplicationVersion>0.4.0.%2a</ApplicationVersion>
     3.9 +    <ApplicationRevision>2</ApplicationRevision>
    3.10 +    <ApplicationVersion>0.4.1.%2a</ApplicationVersion>
    3.11      <UseApplicationTrust>false</UseApplicationTrust>
    3.12      <CreateDesktopShortcut>true</CreateDesktopShortcut>
    3.13      <PublishWizardCompleted>true</PublishWizardCompleted>