Example #1
0
        private void Loop_Tick(object sender, EventArgs e)
        {
            switch (programState)
            {
            // idle
            default:
            case 0:
                break;

            // poll nodes
            case 1:
                CurrentNodes = new ArrayList();
                CurrentNodes.AddRange(Comms.PollNodes());
                DisplayNodes(CurrentNodes);
                break;

            // alert node
            case 2:
                AlertNodes(AlertingNodes);
                break;

            // alert failed
            case 3:
                _            = MessageBox.Show("Failed to alert");
                programState = 1;
                break;

            // poll alert responses and nodes
            case 4:
                CurrentNodes = new ArrayList();
                CurrentNodes.AddRange(Comms.PollNodes());
                AlertingNodes = new ArrayList();
                AlertingNodes.AddRange
                (
                    Comms.PollAlertingNodes((AlertNode[])CurrentNodes.ToArray(typeof(AlertNode)))
                );
                DisplayNodes(CurrentNodes);
                if (AlertingNodes.Count == 0)
                {
                    programState = 1;
                }
                break;
            }
        }
Example #2
0
 private void AlertNodes(ArrayList nodes)
 {
     if (alertAtempts == 5)
     {
         programState = 3;
     }
     else if (nodes.Count == 0)
     {
         programState = 1;
     }
     else
     {
         bool success = true;
         foreach (AlertNode alertNode in nodes)
         {
             success = success && Comms.AlertNode(alertNode);
         }
         programState = success ? 4 : 2;
         alertAtempts = success ? 0 : alertAtempts + 1;
     }
 }