/// <inheritdoc /> /// <summary> /// 命令轮询 /// </summary> /// <returns></returns> public sealed override bool Run() { lock (this) { if (RunState != StationState.Run) { RunState = StationState.Start; } if (_socket != null) { return(false); } } _inPoll = false; _socket = new SubscriberSocket(); try { _socket.Options.Identity = RealName.ToAsciiBytes(); _socket.Options.ReconnectInterval = new TimeSpan(0, 0, 0, 0, 200); _socket.Subscribe(Subscribe); _socket.Connect(Config.InnerAddress); } catch (Exception e) { LogRecorder.Exception(e); RunState = StationState.Failed; CloseSocket(); StationProgram.WriteLine($"【{StationName}】connect error =>{e.Message}"); return(false); } RunState = StationState.Run; _items = MulitToOneQueue <PublishItem> .Load(CacheFileName); Task.Factory.StartNew(CommandTask); var task1 = Task.Factory.StartNew(PollTask); task1.ContinueWith(OnTaskStop); while (!_inPoll) { Thread.Sleep(50); } StationProgram.WriteLine($"【{StationName}:{RealName}】runing..."); return(true); }
/// <inheritdoc /> /// <summary> /// 命令轮询 /// </summary> /// <returns></returns> public sealed override bool Run() { lock (this) { if (RunState != StationState.Run) { RunState = StationState.Start; } if (_socket != null) { return(false); } } _inPoll = false; _inHeart = false; _socket = new RequestSocket(); try { _socket.Options.Identity = RealName.ToAsciiBytes(); _socket.Options.ReconnectInterval = new TimeSpan(0, 0, 0, 0, 200); _socket.Connect(Config.InnerAddress); } catch (Exception e) { LogRecorder.Exception(e); RunState = StationState.Failed; CloseSocket(); StationProgram.WriteLine($"【{StationName}】connect error =>{e.Message}"); return(false); } try { var word = _socket.Request("@", JsonConvert.SerializeObject(Config)); if (word != "wecome") { CloseSocket(); RunState = StationState.Failed; StationProgram.WriteLine($"【{StationName}】proto error"); return(false); } } catch (Exception e) { LogRecorder.Exception(e); RunState = StationState.Failed; CloseSocket(); StationProgram.WriteLine($"【{StationName}】request error =>{e.Message}"); return(false); } RunState = StationState.Run; _items = MulitToOneQueue <List <string> > .Load(CacheFileName); Task.Factory.StartNew(CommandTask); var task1 = Task.Factory.StartNew(PollTask); task1.ContinueWith(OnTaskStop); var task2 = Task.Factory.StartNew(HeartbeatTask); task2.ContinueWith(OnTaskStop); while (!_inHeart || !_inPoll) { Thread.Sleep(50); } StationProgram.WriteLine($"【{StationName}:{RealName}】runing..."); return(true); }