Esempio n. 1
0
        public RGOClientManager()
        {
            InstanceCounter++;
            if (InstanceCounter > 1)
            {
                throw new Exception("Only one instance of the RGOclientManager may be created in this scope");
            }

            SM.FirstAction = () =>
            {
                //run the state machines of all clients
                for (int i = 0; i < RGOClientBase.AllClients.Count; i++)
                {
                    RGOClientBase.AllClients[i].Run();
                }
            };

            SM.AddState(RGOStates.ConnectingToServer, new List <Transition>
            {
                new Transition("ServerConnected", () => ServerComm.ServerConnected, () => RGOClientDownloader.Connect(), RGOStates.DownloadingAllRGO),
                new Transition("ConnectionRejected", () => ServerComm.ConnectionRejected, () => log.Error("The connection was rejected by the server."), RGOStates.ConnectingToServer)
            }, () => ServerCommError = false, StateType.entry);

            SM.AddState(RGOStates.DownloadingAllRGO, new List <Transition>
            {
                new Transition("DownloadDone", () => RGOClientDownloader.RGODownloadDone == true, () => DSCClient.Connect(), RGOStates.DownloadingDSC),
            }, null, StateType.transition);

            SM.AddState(RGOStates.DownloadingDSC, new List <Transition>
            {
                new Transition("DescriptionsReceived", () => DSCClient.DSCsReceived == true, () =>
                {
                    log.Info("All RGO downloads done");
                    foreach (var C in RGOClientBase.AllClients)
                    {
                        C.Connect();
                    }
                }, RGOStates.Running),
            }, null, StateType.transition);

            SM.AddState(RGOStates.Running, new List <Transition>
            {
                new Transition("ServerCommDisconnected", () => ServerComm.ServerConnected == false, null, RGOStates.Disconnecting),
                new Transition("ServerCommErrorReported", () => ServerCommError == true, null, RGOStates.Disconnecting),
            }, null, StateType.idle);

            SM.AddState(RGOStates.Disconnecting, new List <Transition>
            {
                new Transition("AllClientsDisconnected", () => true, null, RGOStates.Disconnected),
            },
                        () =>
            {
                foreach (var C in RGOClientBase.AllClients)
                {
                    C.Disconnect();
                }
            }, StateType.transition);

            SM.AddState(RGOStates.Disconnected, new List <Transition>
            {
                new Transition("Reconnect", () => Reconnect == true, () =>
                {
                    ServerComm.Connect();
                }
                               , RGOStates.ConnectingToServer)
            }, null, StateType.end);

            SM.Finalize();
        }