private void ReceiveRoutingTable()
        {
            while (true)
            {
                try {
                    byte[] receivedBuffer = new byte[8192];
                    try {
                        stream.Read(receivedBuffer, 0, receivedBuffer.Length);
                    }
                    catch {
                        break;
                    }

                    Dictionary <int, int> routingTable = (Dictionary <int, int>)CloudConnection.DeserializeObject(receivedBuffer);
                    //foreach (int key in routingTable.Keys) {
                    //    routingTable.TryGetValue(key, out int value);
                    //    GUIWindow.PrintLog("ID: " + key + " port: " + value);
                    //}


                    foreach (int key in routingTable.Keys)
                    {
                        int val;
                        routingTable.TryGetValue(key, out val);
                        Program.routingTable.Add(new Tuple <int, int>(key, val));
                        GUIWindow.PrintLog("CC: Received MatrixConnection(" + key + ", " + val + ") from network's CC");
                        GUIWindow.PrintLog("CC: Sent MatrixConnectionResponse() to network's CC");
                    }

                    TimeSpan currentTime = DateTime.UtcNow - Process.GetCurrentProcess().StartTime.ToUniversalTime();
                    TimeSpan diff        = currentTime - timeSpan;
                    timeSpan = currentTime;

                    //if (diff.TotalMilliseconds > 500)


                    LinkedList <string[]> rows = new LinkedList <string[]>();
                    foreach (int key in routingTable.Keys)
                    {
                        routingTable.TryGetValue(key, out int val);
                        rows.AddLast(new string[] { key.ToString(), val.ToString() });
                    }
                    GUIWindow.UpdateRoutingTable(rows);
                }
                catch (Exception ex) {
                    GUIWindow.PrintLog(ex.StackTrace);
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            try {
                args = Environment.GetCommandLineArgs();

                new Thread(() => {
                    //Thread.Sleep(2000);
                    lock (waiterConfig) {
                        Monitor.Wait(Program.waiterConfig);
                        //String config = String.Concat(File.ReadAllLines("./../../../../sharedResources/tsst_config.xml"));
                        //ConfigLoader.LoadConfig(config, "1");

                        String config = String.Concat(File.ReadAllLines(args[1]));
                        ConfigLoader.LoadConfig(config, args[2]);
                        lock (Program.waiterManagement) {
                            Monitor.Pulse(Program.waiterManagement);
                        }
                    }
                }).Start();


                new Thread(() => {
                    //Thread.Sleep(2000);
                    lock (Program.waiterManagement) {
                        Monitor.Wait(Program.waiterManagement);
                    }
                    new ManagementCenterConnection();
                    new ControlCenterConnection();
                }).Start();

                new Thread(() => {
                    lock (Program.waiterCloud) {
                        Monitor.Wait(Program.waiterCloud);
                    }
                    cloudConnection = new CloudConnection();
                }).Start();



                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new GUIWindow());
            }catch (Exception e) {
                GUIWindow.PrintLog(e.StackTrace);
            }
        }