Esempio n. 1
0
 private void BuildTestFrame()
 {
     AliveTestSet               = new ConcurrentDictionary <IPAddress, AliveTestHeartBeat>();
     TTLCountdown               = new System.Timers.Timer(600);
     aliveRefreshTimer          = new System.Timers.Timer();
     aliveRefreshTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
     aliveRefreshTimer.Interval = 600000;
     indicator = new ActivityIndicator();
     MainStack.Children.Add(indicator);
     TTLCountdown.Elapsed += (object source, System.Timers.ElapsedEventArgs e) => {
         Dictionary <IPAddress, AliveTestHeartBeat> DeadSet = new Dictionary <IPAddress, AliveTestHeartBeat>();
         foreach (KeyValuePair <IPAddress, AliveTestHeartBeat> keyValue in AliveTestSet)
         {
             AliveTestHeartBeat temp = keyValue.Value;
             temp.TTL -= 1;
             AliveTestSet[keyValue.Key] = temp;
             if (temp.TTL <= 0)
             {
                 DeadSet.Add(keyValue.Key, keyValue.Value);
             }
         }
         foreach (KeyValuePair <IPAddress, AliveTestHeartBeat> keyValue in DeadSet)
         {
             AliveTestHeartBeat temp;
             AliveTestSet.TryRemove(keyValue.Key, out temp);
             if (null != temp.controller)
             {
                 Task.Run(() =>
                 {
                     ((MainPage)Application.Current.MainPage)._Controllers.FindByIP(temp.controller.IPAddress).UDP = false;
                     ((MainPage)Application.Current.MainPage).SaveController();
                 });
                 temp.controller.AliveTest();
             }
         }
     };
     TTLCountdown.Start();
 }
 public AliveTest()
 {
     InitializeComponent();
     AliveTestSet               = new ConcurrentDictionary <IPAddress, AliveTestHeartBeat>();
     TTLCountdown               = new System.Timers.Timer(600);
     aliveRefreshTimer          = new System.Timers.Timer();
     aliveRefreshTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
     aliveRefreshTimer.Interval = 600000;
     TTLCountdown.Elapsed      += (object source, System.Timers.ElapsedEventArgs e) => {
         Dictionary <IPAddress, AliveTestHeartBeat> DeadSet = new Dictionary <IPAddress, AliveTestHeartBeat>();
         foreach (KeyValuePair <IPAddress, AliveTestHeartBeat> keyValue in AliveTestSet)
         {
             AliveTestHeartBeat temp = keyValue.Value;
             temp.TTL -= 1;
             AliveTestSet[keyValue.Key] = temp;
             if (temp.TTL <= 0)
             {
                 DeadSet.Add(keyValue.Key, keyValue.Value);
             }
         }
         foreach (KeyValuePair <IPAddress, AliveTestHeartBeat> keyValue in DeadSet)
         {
             AliveTestHeartBeat temp;
             AliveTestSet.TryRemove(keyValue.Key, out temp);
             if (null != temp.controller)
             {
                 Dispatcher.Invoke(() =>
                 {
                     ((MainWindow)Application.Current.MainWindow)._1337.FindByIP(temp.controller.IPAddress).UDP = false;
                     ((MainWindow)Application.Current.MainWindow).SaveController();
                 });
                 temp.controller.AliveTest();
             }
         }
     };
     TTLCountdown.Start();
 }
Esempio n. 3
0
        public async void RunAliveTest()  // called when scheduler sends command
        {
            // Sends a process request to all controllers and returns their status

            DataRowCollection drc = null;
            await Task.Run(() => {
                deadPick  = new Picker();
                alivePick = new Picker();
            });

            await Task.Run(() => {
                ((MainPage)Application.Current.MainPage).LoadControllerDB();
                drc = ((MainPage)Application.Current.MainPage)._Controllers.Rows;
            });

            Task.Run(() => {
                foreach (DataRow dr in drc)
                {
                    Task.Run(() =>
                    {
                        string building    = dr["Building"].ToString();
                        string room        = dr["Room"].ToString();
                        string ip          = dr["IP"].ToString();
                        string designation = dr["Designation"].ToString();

                        AMXController mXController = new AMXController();
                        mXController.Connect(ip, 8888);
                        mXController.ControllerHealthChanged += ((AMXController.ControllerHealthState newState) => {
                            Task.Run(() =>
                            {
                                string roomName = building + " " + room;

                                var childName = (building + room).Replace(" ", "");

                                if (PendingList.Contains(ip))
                                {
                                    PendingList.Remove(ip);
                                }

                                if (newState == AMXController.ControllerHealthState.Alive)
                                {
                                    alivePick.Items.Add(roomName);
                                    RoomIPs.Add(roomName, ip);
                                }
                                else
                                {
                                    deadPick.Items.Add(roomName);
                                    RoomIPs.Add(roomName, ip);
                                }

                                dr["LastChecked"] = DateTime.Now;

                                ((MainPage)Application.Current.MainPage).SaveController();
                                if (PendingList.Count == 0)
                                {
                                    indicator.IsRunning = false;
                                }
                            });
                        });
                        AliveTestHeartBeat alive = new AliveTestHeartBeat {
                            TTL = DEFAULT_TTL, controller = mXController
                        };
                        AliveTestSet.TryAdd(IPAddress.Parse(ip), alive);
                        PendingList.Add(ip);
                        Task.Factory.StartNew(() => mXController.AliveTestUDP());
                    });
                }
            });
        }
        public void RunAliveTest()
        {
            Spinny.Dispatcher.Invoke(() =>
            {
                Spinny.IsActive = false;
            });
            DataRowCollection drc = null;

            spPass.Dispatcher.Invoke(() => { spPass.Children.Clear(); });
            spFail.Dispatcher.Invoke(() => { spFail.Children.Clear(); });
            Dispatcher.Invoke(() => {
                ((MainWindow)Application.Current.MainWindow).LoadControllerDB();
                drc = ((MainWindow)Application.Current.MainWindow)._1337.Rows;
            });
            Task.Run(() => {
                foreach (DataRow dr in drc)
                {
                    Task.Run(() =>
                    {
                        string building = dr["Building"].ToString();
                        string room     = dr["Room"].ToString();
                        string ip       = dr["IP"].ToString();

                        AMXController mXController = new AMXController();
                        mXController.Connect(ip, 8888);
                        mXController.ControllerHealthChanged += ((AMXController.ControllerHealthState newState) => {
                            Dispatcher.Invoke(() =>
                            {
                                Button tb = new Button
                                {
                                    Name = (building + room).Replace(" ", ""),
                                    Content = building + " " + room,
                                    Tag = ip,
                                    Foreground = Brushes.White,
                                    HorizontalAlignment = HorizontalAlignment.Center,
                                    VerticalAlignment = VerticalAlignment.Center
                                };

                                var childName = (building + room).Replace(" ", "");
                                TextBlock child = PendingFindChildByName(childName);
                                if (null != child)
                                {
                                    spPending.Children.Remove(child);
                                }

                                if (newState == AMXController.ControllerHealthState.Alive)
                                {
                                    AddToStackPanel(spPass, tb);//spPass.Children.Add(tb);
                                }
                                else
                                {
                                    AddToStackPanel(spFail, tb);//spFail.Children.Add(tb);
                                }
                                dr["LastChecked"] = DateTime.Now;

                                ((MainWindow)Application.Current.MainWindow).SaveController();
                            });
                        });
                        AliveTestHeartBeat alive = new AliveTestHeartBeat {
                            TTL = DEFAULT_TTL, controller = mXController
                        };
                        AliveTestSet.TryAdd(IPAddress.Parse(ip), alive);
                        Dispatcher.Invoke(() =>
                        {
                            TextBlock tbPending = new TextBlock
                            {
                                Name                = (building + room).Replace(" ", ""),
                                Text                = building + " " + room,
                                Foreground          = Brushes.White,
                                HorizontalAlignment = HorizontalAlignment.Center,
                                VerticalAlignment   = VerticalAlignment.Center
                            };
                            spPending.Children.Add(tbPending);
                            spPending.ApplyTemplate();
                        });
                        Task.Factory.StartNew(() => mXController.AliveTestUDP());
                    });
                }
            });
        }