/ src / modules / MouseWithoutBorders / App / Class / MachinePoolHelpers.cs
MachinePoolHelpers.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using System;
 6  
 7  using MouseWithoutBorders.Core;
 8  
 9  namespace MouseWithoutBorders.Class
10  {
11      internal static class MachinePoolHelpers
12      {
13          internal static readonly char[] Comma = new char[] { ',' };
14          internal static readonly char[] Colon = new char[] { ':' };
15  
16          internal static MachineInf[] LoadMachineInfoFromMachinePoolStringSetting(string s)
17          {
18              if (s == null)
19              {
20                  throw new ArgumentNullException(s);
21              }
22  
23              string[] st = s.Split(Comma);
24  
25              if (st.Length < MachineStuff.MAX_MACHINE)
26              {
27                  throw new ArgumentException("Not enough elements in encoded MachinePool string");
28              }
29  
30              MachineInf[] rv = new MachineInf[MachineStuff.MAX_MACHINE];
31              for (int i = 0; i < MachineStuff.MAX_MACHINE; i++)
32              {
33                  string[] mc = st[i].Split(Colon);
34                  if (mc.Length == 2)
35                  {
36                      rv[i].Name = mc[0];
37                      rv[i].Id = uint.TryParse(mc[1], out uint ip) ? (ID)ip : ID.NONE;
38                      rv[i].Time = rv[i].Id == ID.NONE ? Common.GetTick() - MachineStuff.HEARTBEAT_TIMEOUT : Common.GetTick();
39                  }
40              }
41  
42              return rv;
43          }
44      }
45  }