コード例 #1
0
 public void ExitStateCallback(T owner)
 {
     // If we have states queued, enter the next state on that list
     if (StateQueue.Count > 0)
     {
         State <T> state = StateQueue[0];
         StateQueue.RemoveAt(0);
         UpdateStateHistory();
         currentState = null;
         ChangeState(state);
     }
     // If we don't have states queued trigger the OnStateFinish event that the owner can react to
     else if (OnStateFinish != null)
     {
         UpdateStateHistory();
         currentState = null;
         OnStateFinish?.Invoke();
     }
 }
コード例 #2
0
        public static void InitializeTCPserver(MainModel model)
        {
            _model = model;
            _model.PropertyChanged += ModelChanged;
            Task.Run(() =>
            {
                Task.Run(() =>
                {
                    while (ServerAlive)
                    {
                        try
                        {
                            Server1 = new TcpListener(IPAddress.Any, 2111);
                            Server1.Stop();
                            Server1.Start();
                            break;
                        }
                        catch { }
                        Thread.Sleep(100);
                    }
                    try
                    {
                        Server1.BeginAcceptTcpClient(new AsyncCallback(OMWinforming), Server1);
                    }
                    catch { }
                });
                Task.Run(() =>
                {
                    while (ServerAlive)
                    {
                        try
                        {
                            Server2 = new TcpListener(IPAddress.Any, 2112);
                            Server2.Stop();
                            Server2.Start();
                            break;
                        }
                        catch { }
                        Thread.Sleep(100);
                    }
                    try
                    {
                        if (ServerAlive)
                        {
                            using (TcpClient client = Server2.AcceptTcpClient())
                            {
                                using (NetworkStream stream = client.GetStream())
                                {
                                    try
                                    {
                                        OMWsendState(client, stream, (new ControlStruct
                                        {
                                            Profile = _model.Profile,
                                            Logging = _model.Loggong,
                                            InfPowerLimits = _model.InfPowerLimits,
                                            InfCoreClocks = _model.InfCoreClocks,
                                            InfMemoryClocks = _model.InfMemoryClocks,
                                            InfOHMCoreClocks = _model.InfOHMCoreClocks,
                                            InfOHMMemoryClocks = _model.InfOHMMemoryClocks,
                                            InfFanSpeeds = _model.InfFanSpeeds,
                                            InfTemperatures = _model.InfTemperatures,
                                            InfHashrates = _model.InfHashrates,
                                            TotalHashrate = _model.TotalHashrate,
                                            WachdogInfo = _model.WachdogInfo,
                                            LowHWachdog = _model.LowHWachdog,
                                            IdleWachdog = _model.IdleWachdog,
                                            Indication = _model.Indicator,
                                            Algoritms = _model.Algoritms,
                                            Miners = _model.Miners,
                                            DefClock = _model.DefClock,
                                        },
                                                                      ContolStateType.ControlStruct));
                                    }
                                    catch { }
                                    Task.Run(() =>
                                    {
                                        // Отправление статистики
                                        while (ServerAlive)
                                        {
                                            try
                                            {
                                                Server3 = new TcpListener(IPAddress.Any, 2113);
                                                Server3.Stop();
                                                Server3.Start();
                                                break;
                                            }
                                            catch { }
                                            Thread.Sleep(100);
                                        }
                                        try
                                        {
                                            using (var statclient = Server3.AcceptTcpClient())
                                            {
                                                using (var statstream = statclient.GetStream())
                                                {
                                                    StateServerActive = true;
                                                    (object, ContolStateType)? q;
                                                    while (statclient.Connected && ServerAlive)
                                                    {
                                                        q = null;
                                                        lock (ContolStateKey)
                                                        {
                                                            if (StateQueue.Count > 0)
                                                            {
                                                                q = StateQueue[0];
                                                                StateQueue.RemoveAt(0);
                                                            }
                                                        }
                                                        if (q != null)
                                                        {
                                                            OMWsendState(statclient, statstream, q.Value);
                                                        }
                                                        Thread.Sleep(100);
                                                    }
                                                    StateServerActive = false;
                                                    lock (ContolStateKey) StateQueue.Clear();
                                                }
                                            }
                                        }
                                        finally
                                        {
                                            Server3.Stop();
                                        }
                                    });
                                    string message;
                                    while (client.Connected && ServerAlive)
                                    {
                                        RootObject RO;

                                        try
                                        {
                                            message = ReadMessage(stream);
                                            RO      = JsonConvert.DeserializeObject <RootObject>(message, Convs);
                                            if (RO != null)
                                            {
                                                Task.Run(() => OMWsent?.Invoke(RO));
                                            }
                                        }
                                        catch { }
                                        Thread.Sleep(100);
                                    }
                                }
                            }
                        }
                    }
                    catch { }
                });
                Task.Run(() =>
                {
                    while (ServerAlive)
                    {
                        try
                        {
                            Server4 = new TcpListener(IPAddress.Any, 2114);
                            Server4.Stop();
                            Server4.Start();
                            break;
                        }
                        catch { }
                        Thread.Sleep(100);
                    }
                    try
                    {
                        while (ServerAlive)
                        {
                            using (TcpClient client = Server4.AcceptTcpClient())
                            {
                                using (NetworkStream stream = client.GetStream())
                                {
                                    stream.Write(new byte[] { 1 }, 0, 1);
                                }
                            }
                        }
                    }
                    catch { }
                });
            });
        }