internal void OnHeartbeat(long timeout) { if (_pingTimeoutTimer != null) { _pingTimeoutTimer.Stop(); _pingTimeoutTimer = null; } if (timeout <= 0) { timeout = PingInterval + PingTimeout; } _pingTimeoutTimer = EasyTimer.SetTimeout(() => { Logger.Log("EasyTimer OnHeartbeat start"); if (ReadyState == ReadyStateEnum.CLOSED) { Logger.Log("EasyTimer OnHeartbeat ReadyState == ReadyStateEnum.CLOSED finish"); return; } OnClose("ping timeout"); Logger.Log("EasyTimer OnHeartbeat finish"); }, (int)timeout); }
internal void Disable() { this.RunCommand(App.DefineCommand.DISABLE); EasyTimer.SetTimeout(() => { this.RunCommand(App.DefineCommand.ALARM_OFF); }, 500); this.status = false; }
private void ViewCCTV(object sender, MouseButtonEventArgs e) { if (this.Mode != Camera_Final.Mode.CCTV) { this.count--; if (this.count < 0) { //System.Diagnostics.Process p= System.Diagnostics.Process.Start(Application.ResourceAssembly.Location); ProcessStartInfo startInfo = new ProcessStartInfo(Application.ResourceAssembly.Location); startInfo.Arguments = string.Format("-u {0} -mode 2", App.User.Hash); System.Diagnostics.Process.Start(startInfo); Application.Current.Shutdown(); } // if (!isLoadCCTV) this.LoadCCTVLayout(); EasyTimer.SetTimeout(() => { if (App.setting.AutoRecord) { this.autoRecord(); } }, 3500); UIContent.Animation_Translate_Frame(double.NaN, double.NaN, -264, 0, 500, () => { isMenuShow = false; this.UIMap.Animation_Translate_Frame(double.NaN, double.NaN, double.NaN, 768); this.UICCTV.Animation_Translate_Frame(double.NaN, -768, double.NaN, 0); this.Mode = Camera_Final.Mode.CCTV; }); } }
private void grdArtículos_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { EasyTimer.SetTimeout(() => { ActualizarTotales(); }, 500); }
internal void OnHeartbeat(long timeout) { var log = LogManager.GetLogger(Global.CallerName()); if (timeout <= 0) { timeout = this.PingInterval + this.PingTimeout; } var PingTimeoutTimer = EasyTimer.SetTimeout(() => { var log2 = LogManager.GetLogger(Global.CallerName()); if (ReadyState == ReadyStateEnum.CLOSED) { log2.Info("EasyTimer OnHeartbeat ReadyState == ReadyStateEnum.CLOSED finish"); return; } OnClose("ping timeout"); }, (int)timeout); var original = Interlocked.Exchange(ref this.PingTimeoutTimer, PingTimeoutTimer); if (original != null) { original.Stop(); } }
private static void Проверка_Автокоманда1() { _лампочкаАвтомКоманда1 = false; if (timer_лампочкаАвтомКоманда1ON != null) { timer_лампочкаАвтомКоманда1ON.Dispose(); } if (timer_лампочкаАвтомКоманда1OFF != null) { timer_лампочкаАвтомКоманда1OFF.Dispose(); } timer_лампочкаАвтомКоманда1ON = EasyTimer.SetTimeout(() => { _лампочкаАвтомКоманда1 = true; OnParameterChanged(); }, 2000); timer_лампочкаАвтомКоманда1OFF = EasyTimer.SetTimeout(() => { _лампочкаАвтомКоманда1 = false; OnParameterChanged(); }, 5000); }
private void SetPing() { //var log = LogManager.GetLogger(Global.CallerName()); if (this.PingIntervalTimer != null) { PingIntervalTimer.Stop(); } var log = LogManager.GetLogger(Global.CallerName()); log.Info(string.Format("writing ping packet - expecting pong within {0}ms", PingTimeout)); PingIntervalTimer = EasyTimer.SetTimeout(() => { var log2 = LogManager.GetLogger(Global.CallerName()); log2.Info("EasyTimer SetPing start"); if (Upgrading) { // skip this ping during upgrade SetPing(); log2.Info("skipping Ping during upgrade"); } else { Ping(); OnHeartbeat(PingTimeout); log2.Info("EasyTimer SetPing finish"); } }, (int)PingInterval); }
private void OnClose(string reason, Exception desc = null) { if (this.ReadyState != Socket.ReadyStateEnum.OPENING && this.ReadyState != Socket.ReadyStateEnum.OPEN) { return; } LogManager logger = LogManager.GetLogger(Global.CallerName("", 0, "")); logger.Info(string.Format("OnClose socket close with reason: {0}", (object)reason)); if (this.PingIntervalTimer != null) { this.PingIntervalTimer.Stop(); } if (this.PingTimeoutTimer != null) { this.PingTimeoutTimer.Stop(); } EasyTimer.SetTimeout((ActionTrigger)(() => { this.WriteBuffer = ImmutableList <Packet> .Empty; this.CallbackBuffer = ImmutableList <ActionTrigger> .Empty; this.PrevBufferLen = 0; }), 1); if (this.mTransport != null) { this.mTransport.Off(Socket.EVENT_CLOSE); this.mTransport.Close(); this.mTransport.Off(); } this.ReadyState = Socket.ReadyStateEnum.CLOSED; logger.Info("Socket.ReadyState = CLOSE"); this.Id = (string)null; this.Emit(Socket.EVENT_CLOSE, (object)reason, (object)desc); }
internal void OnHeartbeat(long timeout) { if (this.PingTimeoutTimer != null) { PingTimeoutTimer.Stop(); PingTimeoutTimer = null; } if (timeout <= 0) { timeout = this.PingInterval + this.PingTimeout; } PingTimeoutTimer = EasyTimer.SetTimeout(() => { var log2 = LogManager.GetLogger(Global.CallerName()); log2.Info("EasyTimer OnHeartbeat start"); if (ReadyState == ReadyStateEnum.CLOSED) { log2.Info("EasyTimer OnHeartbeat ReadyState == ReadyStateEnum.CLOSED finish"); return; } OnClose("ping timeout"); log2.Info("EasyTimer OnHeartbeat finish"); }, (int)timeout); }
public static void АктивизироватьСтрелкуНапряжения() { Напряжение = 7; EasyTimer.SetTimeout((() => { Напряжение = 10; OnParameterChanged(); }), 300); }
private void OnClose(string reason, Exception desc = null) { if (this.ReadyState == ReadyStateEnum.OPENING || this.ReadyState == ReadyStateEnum.OPEN) { var log = LogManager.GetLogger(Global.CallerName()); log.Info(string.Format("OnClose socket close with reason: {0}", reason)); // clear timers if (this.PingIntervalTimer != null) { this.PingIntervalTimer.Stop(); } if (this.HeartbeatTimer != null) { this.HeartbeatTimer.Stop(); } //WriteBuffer = WriteBuffer.Clear(); //CallbackBuffer = CallbackBuffer.Clear(); //PrevBufferLen = 0; EasyTimer.SetTimeout(() => { lock (WriteBuffer){ WriteBuffer.Clear(); } CallbackBuffer = new List <Action>(); PrevBufferLen = 0; }, 1); if (this.Transport != null) { // stop event from firing again for transport this.Transport.Off(EVENT_CLOSE); // ensure transport won't stay open this.Transport.Close(); // ignore further transport communication this.Transport.Off(); } // set ready state this.ReadyState = ReadyStateEnum.CLOSED; // clear session id this.Id = null; // emit close events this.Emit(EVENT_CLOSE, reason, desc); } }
private void Reconnect() { var log = LogManager.GetLogger(Global.CallerName()); if (Reconnecting) { return; } Attempts++; if (Attempts > _reconnectionAttempts) { log.Info("reconnect failed"); EmitAll(EVENT_RECONNECT_FAILED); Reconnecting = false; } else { var delay = Attempts * ReconnectionDelay(); delay = Math.Min(delay, ReconnectionDelayMax()); log.Info(string.Format("will wait {0}ms before reconnect attempt", delay)); Reconnecting = true; var timer = EasyTimer.SetTimeout(() => { var log2 = LogManager.GetLogger(Global.CallerName()); log2.Info("EasyTimer Reconnect start"); log2.Info(string.Format("attempting reconnect")); EmitAll(EVENT_RECONNECT_ATTEMPT, Attempts); EmitAll(EVENT_RECONNECTING, Attempts); Open(new OpenCallbackImp((err) => { if (err != null) { log.Error("reconnect attempt error", (Exception)err); Reconnecting = false; Reconnect(); EmitAll(EVENT_RECONNECT_ERROR, (Exception)err); } else { log.Info("reconnect success"); OnReconnect(); } })); log2.Info("EasyTimer Reconnect finish"); }, (int)delay); lock (Subs){ Subs.Enqueue(new On.ActionHandleImpl(timer.Stop)); } } }
public void LoadData() { EasyTimer.SetTimeout(() => { this.Dispatcher.Invoke(() => { Application.Current.MainWindow = new MainWindow(); Application.Current.MainWindow.Show(); this.Close(); }); }, 3, System.Threading.ApartmentState.STA); }
private void OnClose(string reason, Exception desc = null) { if (_readyState == ReadyStateEnum.Opening || _readyState == ReadyStateEnum.Open) { var log = LogManager.GetLogger(Global.CallerName()); log.Info(string.Format("OnClose socket close with reason: {0}", reason)); // clear timers if (_pingIntervalTimer != null) { _pingIntervalTimer.Stop(); } if (_pingTimeoutTimer != null) { _pingTimeoutTimer.Stop(); } //WriteBuffer = WriteBuffer.Clear(); //CallbackBuffer = CallbackBuffer.Clear(); //PrevBufferLen = 0; EasyTimer.SetTimeout(() => { _writeBuffer = ImmutableList <Packet> .Empty; _callbackBuffer = ImmutableList <Action> .Empty; _prevBufferLen = 0; }, 1); if (Transport != null) { // stop event from firing again for transport Transport.Off(EventClose); // ensure transport won't stay open Transport.Close(); // ignore further transport communication Transport.Off(); } // set ready state _readyState = ReadyStateEnum.Closed; // clear session id Id = null; // emit close events Emit(EventClose, reason, desc); } }
private static void произвестиПередачу() { if (_таймерПередачиКоманды != null) { _таймерПередачиКоманды.Dispose(); } _идетПередачаКоманды = true; _таймерПередачиКоманды = EasyTimer.SetTimeout(() => { _идетПередачаКоманды = false; }, 3000); BMA_M_1Parameters.ResetParameters(); }
private void SetPing() { if (this.PingIntervalTimer != null) { this.PingIntervalTimer.Stop(); } this.PingIntervalTimer = EasyTimer.SetTimeout((ActionTrigger)(() => { LogManager.GetLogger(Global.CallerName("", 0, "")).Info(string.Format( "writing ping packet - expecting pong within {0}ms, ReadyState = {1}", (object)this.PingTimeout, (object)this.ReadyState)); this.Ping(); this.OnHeartbeat(this.PingTimeout); }), (int)this.PingInterval); }
private static void ПрокеркаКомплекта() { _лампочкаКонтрольНорм = true; _лампочкаКонтрольНенорм = true; if (timer_ЛампочкаКонтрольНенорм != null) { timer_ЛампочкаКонтрольНенорм.Dispose(); } timer_ЛампочкаКонтрольНенорм = EasyTimer.SetTimeout(() => { _лампочкаКонтрольНенорм = false; OnParameterChanged(); }, 4000); }
/// <summary> /// Метод мерцания лампочки перюключателя направления при включении БМА /// </summary> public static void МерцаниеЛампочиНаправления(int НомерНаправления) { if (КнопкаПитание == Кнопка.Горит) { _номерМерцающейЛампочкиНаправления = НомерНаправления; _мерцаниеЛампочкиДк = true; _мерцаниеЛампочкиТч = true; ResetParameters(); EasyTimer.SetTimeout(() => { _номерМерцающейЛампочкиНаправления = -1; _мерцаниеЛампочкиДк = false; _мерцаниеЛампочкиТч = false; ResetParameters(); }, 500); } }
protected override void Write(ImmutableList <Parser.Packet> packets) { Writable = false; foreach (var packet in packets) { Parser.Parser.EncodePacket(packet, new WriteEncodeCallback(this)); } //Parser.Parser.EncodePayload(packets.ToArray(), new WriteEncodeCallback(this)); // fake drain // defer to next tick to allow Socket to clear writeBuffer EasyTimer.SetTimeout(() => { Writable = true; Emit(EVENT_DRAIN); }, 1); }
internal void OnClose(string reason, Exception desc = null) { if (ReadyState == ReadyStateEnum.OPENING || ReadyState == ReadyStateEnum.OPEN) { Logger.Log($"OnClose socket close with reason: {reason}"); // clear timers _pingIntervalTimer?.Stop(); _pingTimeoutTimer?.Stop(); //WriteBuffer = WriteBuffer.Clear(); //CallbackBuffer = CallbackBuffer.Clear(); //PrevBufferLen = 0; EasyTimer.SetTimeout(() => { WriteBuffer = ImmutableList <Packet> .Empty; CallbackBuffer = ImmutableList <Action> .Empty; PrevBufferLen = 0; }, 1); if (Transport != null) { // stop event from firing again for transport Transport.Off(EVENT_CLOSE); // ensure transport won't stay open Transport.Close(); // ignore further transport communication Transport.Off(); } // set ready state ReadyState = ReadyStateEnum.CLOSED; // clear session id Id = null; // emit close events Emit(EVENT_CLOSE, reason, desc); } }
private void SetPing() { var log = LogManager.GetLogger(Global.CallerName()); if (this.PingIntervalTimer != null) { log.Info("SetPing::Stopping the PingIntervalTimer."); PingIntervalTimer.Stop(); } log.Info(string.Format("writing ping packet - expecting pong within {0}ms", PingTimeout)); log.Info(string.Format("PingInterval is {0}ms", PingInterval)); PingIntervalTimer = EasyTimer.SetTimeout(() => { var log2 = LogManager.GetLogger(Global.CallerName()); log2.Info("EasyTimer SetPing start"); Ping(); log2.Info("EasyTimer SetPing finish"); }, (int)PingInterval); }
public void EasyTimer_ShouldCancelThread() { // Arrange var workDone1 = false; var watch = System.Diagnostics.Stopwatch.StartNew(); // Act var timer = EasyTimer.SetTimeout(() => { workDone1 = true; }, 5000); timer.Stop(); watch.Stop(); // Assert if (workDone1) { throw new Exception("Task 1 has done work. Expected to cancel."); } Assert.InRange(watch.ElapsedMilliseconds, 0, 500); //should be more than enough }
internal void OnHeartbeat(long timeout) { if (this.PingTimeoutTimer != null) { this.PingTimeoutTimer.Stop(); this.PingTimeoutTimer = (EasyTimer)null; } if (timeout <= 0L) { timeout = this.PingInterval + this.PingTimeout; } this.PingTimeoutTimer = EasyTimer.SetTimeout((ActionTrigger)(() => { LogManager logger = LogManager.GetLogger(Global.CallerName("", 0, "")); logger.Info("EasyTimer OnHeartbeat start"); if (this.ReadyState == Socket.ReadyStateEnum.CLOSED) { return; } this.OnClose("ping timeout", (Exception)null); logger.Info("EasyTimer OnHeartbeat finish"); }), (int)timeout); }
public void EasyTimer_ShouldDoWork() { // Arrange var workDone1 = false; var watch = System.Diagnostics.Stopwatch.StartNew(); var manualResetEvent = new ManualResetEvent(false); // Act var timer = EasyTimer.SetTimeout(() => { workDone1 = true; manualResetEvent.Set(); // continue wait }, 0); watch.Stop(); manualResetEvent.WaitOne(1000); // pause until set // Assert if (!workDone1) { throw new Exception("Task 1 must do work."); } Assert.InRange(watch.ElapsedMilliseconds, 0, 500); //should be more than enough }
internal void SetPing() { _pingIntervalTimer?.Stop(); Logger.Log($"writing ping packet - expecting pong within {PingTimeout}ms"); _pingIntervalTimer = EasyTimer.SetTimeout(() => { Logger.Log("EasyTimer SetPing start"); if (Upgrading) { // skip this ping during upgrade SetPing(); Logger.Log("skipping Ping during upgrade"); } else if (ReadyState == ReadyStateEnum.OPEN) { Ping(); OnHeartbeat(PingTimeout); Logger.Log("EasyTimer SetPing finish"); } }, (int)PingInterval); }
protected override void Write(ImmutableList <Parser.Packet> packets) { Writable = false; try { foreach (var packet in packets) { Parser.Parser.EncodePacket(packet, new WriteEncodeCallback(this)); } // fake drain // defer to next tick to allow Socket to clear writeBuffer EasyTimer.SetTimeout(() => { Writable = true; Emit(EVENT_DRAIN); }, 1); } catch (Exception e) { this.OnError("Write", e); } }
private Manager Open(IOpenCallback fn) { var log = LogManager.GetLogger(Global.CallerName()); log.Info(string.Format("readyState {0}", ReadyState)); if (ReadyState == ReadyStateEnum.OPEN) { return(this); } log.Info(string.Format("opening {0}", Uri)); EngineSocket = new Engine(Uri, Opts); Quobject.EngineIoClientDotNet.Client.Socket socket = EngineSocket; ReadyState = ReadyStateEnum.OPENING; OpeningSockets.Add(Socket(Uri.PathAndQuery)); SkipReconnect = false; var openSub = SocketIoClientDotNet.Client.On.Create(socket, Engine.EVENT_OPEN, new ListenerImpl(() => { OnOpen(); if (fn != null) { fn.Call(null); } })); var errorSub = Client.On.Create(socket, Engine.EVENT_ERROR, new ListenerImpl((data) => { log.Info("connect_error"); Cleanup(); ReadyState = ReadyStateEnum.CLOSED; EmitAll(EVENT_CONNECT_ERROR, data); if (fn != null) { var err = new SocketIOException("Connection error", data is Exception ? (Exception)data : null); fn.Call(err); } MaybeReconnectOnOpen(); })); if (_timeout >= 0) { var timeout = (int)_timeout; log.Info(string.Format("connection attempt will timeout after {0}", timeout)); var timer = EasyTimer.SetTimeout(() => { var log2 = LogManager.GetLogger(Global.CallerName()); log2.Info("Manager Open start"); log2.Info(string.Format("connect attempt timed out after {0}", timeout)); openSub.Destroy(); socket.Close(); socket.Emit(Engine.EVENT_ERROR, new SocketIOException("timeout")); EmitAll(EVENT_CONNECT_TIMEOUT, timeout); log2.Info("Manager Open finish"); }, timeout); Subs.Enqueue(new On.ActionHandleImpl(timer.Stop)); ; } Subs.Enqueue(openSub); Subs.Enqueue(errorSub); EngineSocket.Open(); return(this); }
private Manager Open(Manager.IOpenCallback fn) { LogManager log = LogManager.GetLogger(Global.CallerName("", 0, "")); log.Info(string.Format("readyState {0}", (object)this.ReadyState)); if (this.ReadyState == Manager.ReadyStateEnum.OPEN) { return(this); } log.Info(string.Format("opening {0}", (object)this.Uri)); this.EngineSocket = (Quobject.EngineIoClientDotNet.Client.Socket) new Engine(this.Uri, this.Opts); Quobject.EngineIoClientDotNet.Client.Socket socket = this.EngineSocket; this.ReadyState = Manager.ReadyStateEnum.OPENING; this.OpeningSockets.Add(this.Socket(this.Uri.PathAndQuery)); this.SkipReconnect = false; ClientOn.IHandle openSub = ClientOn.Create((Emitter)socket, EngineIoClientDotNet.Client.Socket.EVENT_OPEN, (IListener) new ListenerImpl((ActionTrigger)(() => { this.OnOpen(); if (fn == null) { return; } fn.Call((Exception)null); }))); ClientOn.IHandle handle = ClientOn.Create((Emitter)socket, EngineIoClientDotNet.Client.Socket.EVENT_ERROR, (IListener) new ListenerImpl((Action <object>)(data => { log.Info("connect_error"); this.Cleanup(); this.ReadyState = Manager.ReadyStateEnum.CLOSED; this.EmitAll(Manager.EVENT_CONNECT_ERROR, data); if (fn != null) { fn.Call((Exception) new SocketIOException("Connection error", data is Exception ? (Exception)data : (Exception)null)); } else { this.MaybeReconnectOnOpen(); } }))); if (this._timeout >= 0L && this.ReadyState == Manager.ReadyStateEnum.CLOSED) { int timeout = (int)this._timeout; log.Info(string.Format("connection attempt will timeout after {0}", (object)timeout)); this.Subs.Enqueue((ClientOn.IHandle) new ClientOn.ActionHandleImpl(new ActionTrigger(EasyTimer .SetTimeout((ActionTrigger)(() => { LogManager logger = LogManager.GetLogger(Global.CallerName("", 0, "")); logger.Info("Manager Open start"); logger.Info(string.Format("connect attempt timed out after {0}", (object)timeout)); openSub.Destroy(); socket.Close(); socket.Emit(Quobject.EngineIoClientDotNet.Client.Socket.EVENT_ERROR, (object)new SocketIOException("timeout")); this.EmitAll(Manager.EVENT_CONNECT_TIMEOUT, (object)timeout); logger.Info("Manager Open finish"); }), timeout).Stop))); } this.Subs.Enqueue(openSub); this.Subs.Enqueue(handle); this.EngineSocket.Open(); return(this); }
private void Reconnect() { LogManager log = LogManager.GetLogger(Global.CallerName("", 0, "")); if (this.Reconnecting || this.SkipReconnect) { return; } ++this.Attempts; if (this.Attempts > this._reconnectionAttempts) { log.Info("reconnect failed"); this.EmitAll(Manager.EVENT_RECONNECT_FAILED); this.Reconnecting = false; } else { long num = Math.Min((long)this.Attempts * this.ReconnectionDelay(), this.ReconnectionDelayMax()); log.Info(string.Format("will wait {0}ms before reconnect attempt", (object)num)); this.Reconnecting = true; this.Subs.Enqueue((ClientOn.IHandle) new ClientOn.ActionHandleImpl(new ActionTrigger(EasyTimer .SetTimeout((ActionTrigger)(() => { LogManager logger = LogManager.GetLogger(Global.CallerName("", 0, "")); logger.Info("EasyTimer Reconnect start"); logger.Info(string.Format("attempting reconnect")); this.EmitAll(Manager.EVENT_RECONNECT_ATTEMPT, (object)this.Attempts); this.EmitAll(Manager.EVENT_RECONNECTING, (object)this.Attempts); this.Open((Manager.IOpenCallback) new Manager.OpenCallbackImp((Action <object>)(err => { if (err != null) { log.Error("reconnect attempt error", (Exception)err); this.Reconnecting = false; this.Reconnect(); this.EmitAll(Manager.EVENT_RECONNECT_ERROR, (object)(Exception)err); } else { log.Info("reconnect success"); this.OnReconnect(); } }))); logger.Info("EasyTimer Reconnect finish"); }), (int)num).Stop))); } }