internal void Invoke(string nodeName, CancellationTokenSource tokenSource, TimeSpan timeout) { try { var timeoutTime = timeout.GetTime(); var node = this._stateMachine.GetNode(nodeName); this._stateMachine.StateExecute(node, tokenSource.Token, timeoutTime); Completed?.Invoke(this, new StateMachineCompletedEventArgs(_stateMachine)); } catch (TimeoutException ex) when(ex.Message == "Timeout") { Faulted?.Invoke(this, new StateMachineFaultedEventArgs(_stateMachine, FaultType.ByTimeout, ex)); } catch (OperationCanceledException ex) { Faulted?.Invoke(this, new StateMachineFaultedEventArgs(_stateMachine, FaultType.ByToken, ex)); } catch (System.Exception ex) { Faulted?.Invoke(this, new StateMachineFaultedEventArgs(_stateMachine, FaultType.ByException, ex)); } finally { tokenSource.Dispose(); } }
private void serviceHost_Faulted(object sender, EventArgs e) { serviceHost.Close(); logError("WCF服务失败"); ReportError("状态:已停止,WCF服务失败"); Faulted?.Invoke(this, new ErrorEventArgs("WCF服务失败")); }
private void ChangeState(CommunicationState state) { this.State = state; switch (state) { case CommunicationState.Opening: Opening?.Invoke(this, EventArgs.Empty); break; case CommunicationState.Opened: Opened?.Invoke(this, EventArgs.Empty); break; case CommunicationState.Closing: Closing?.Invoke(this, EventArgs.Empty); break; case CommunicationState.Closed: Closed?.Invoke(this, EventArgs.Empty); break; case CommunicationState.Faulted: Faulted?.Invoke(this, EventArgs.Empty); break; } }
public void Handle(CoreProjectionStatusMessage.Faulted message) { var command = new Faulted { Id = message.ProjectionId.ToString("N"), FaultedReason = message.FaultedReason, }; _writer.PublishCommand("$faulted", command); }
protected void FireFaultEvent(Exception exception, Message message) { var ex = new ProtocolException(Strings.Plugin_ProtocolException, exception); var eventArgs = message == null ? new ProtocolErrorEventArgs(ex) : new ProtocolErrorEventArgs(ex, message); Faulted?.Invoke(this, eventArgs); }
private void FileChanged(object sender, FileSystemEventArgs fse) { if (Regions == null) { return; } try { ReflectDelta(fse); ConfigReloaded.Invoke(fse); } catch (Exception e) { Faulted.Invoke(fse, e); } }
public void Run() { Running?.Invoke(this); try { RunInternal(); } catch (Exception ex) { Faulted?.Invoke(this, ex); return; } Success?.Invoke(this); }
public void Shutdown(Exception e = null) { if (running) { if (e != null) { AppTools.TryInvoke(() => { Faulted?.Invoke(this, new EndPointExceptionEventArgs(e)); }); } shutdown = true; } }
/// <summary> /// Update current sensor Value with the reading. /// </summary> /// <param name="timestamp">Time when reading was sampled</param> /// <param name="val">Value that was read</param> /// <param name="bias">Optional bias to add to value</param> public void UpdateValue(DateTime timestamp, float?val, float?bias) { if (DeviceState == SensorDeviceState.Simulated && GetSimValue != null) { val = GetSimValue(); } if (DeviceState != SensorDeviceState.Offline && val.HasValue) { Value = val.Value; if (bias.HasValue) { Value += bias.Value; } var fault = new SensorFault(); if (Value > DangerHi) { fault.Type = SensorFaultType.FromDangerHi; } else if (Value < DangerLo) { fault.Type = SensorFaultType.FromDangerLo; } if (Triggers != null) { foreach (var t in Triggers) { if ((t.cmp > 0 && Value > t.val) || (t.cmp < 0 && Value < t.val)) { fault.Type = SensorFaultType.FromTrigger; fault.Id = t.id; } } } if (FaultState != SensorFaultState.Faulted && fault.Type != SensorFaultType.NoFault) { FaultState = SensorFaultState.Faulted; Faulted?.Invoke(this, fault, timestamp); } } }
/// <summary> /// Raise the Faulted event. /// </summary> protected virtual void OnExecutableFaulted(Exception ex, IUnityContainer runtimeContainer) { if (Faulted == null) { return; } try { var clock = runtimeContainer.TryGetTypeRegistration <IClock>(); Faulted?.Invoke(this, new FaultedEventArgs(ex, clock)); } catch (Exception nex) { var logger = runtimeContainer.TryGetTypeRegistration <ILog>(); //TODO: what if the logger is null? logger?.Error($"{nex.GetType().Name} while raising event '{nameof(Faulted)}' in behavior '{Name}': {nex.Message}.", nex); } }
void job() { using (source) using (manualResetEvent) { try { ReportStatus("状态:正在运行"); while (true) { if (source.Token.IsCancellationRequested) { break; } int millisecondsTimeout = ServiceCore(source.Token); //让服务歇一会儿 if (millisecondsTimeout > 0) { manualResetEvent.WaitOne(millisecondsTimeout); } } ReportStatus("状态:停止运行"); } catch (OperationCanceledException) { ReportStatus("状态:停止运行"); } //捕获掉取消操作异常,当作停止运行来处理 #if !DEBUG catch (Exception ex) { logError($"承载服务失败:{ex.Message}", ex); ReportError("状态:已停止,承载服务失败", ex); Faulted?.Invoke(this, new ErrorEventArgs(ex)); } #endif finally { } } source = null; manualResetEvent = null; }
private void CacheAllConfigs() { string extension = ConfigBuilder.GetExtension(); WriteDefaultConfig(extension); Regions.Add(new Region(ConfigBuilder)); foreach (string config in Directory.EnumerateFiles(RootPath, '*' + extension, SearchOption.AllDirectories)) { try { AddRegion(config); } catch (Exception exception) { WatcherChangeTypes type = WatcherChangeTypes.Created; string dir = Path.GetDirectoryName(config); string name = Path.GetFileName(config); var eventArgs = new FileSystemEventArgs(type, dir, name); Faulted.Invoke(eventArgs, exception); return; } } }
public bool FaultedIsHooked() { return(Faulted != null && Faulted.GetInvocationList().Length > 0); }
private void OnChannelFaulted(object sender, EventArgs e) { Faulted?.Invoke(sender, e); }
private void HandleFaulted(AggregateException exception) { IsFaulted = true; Faulted?.Invoke(exception); }
void ClientThread() { try { socket.Blocking = false; var check = new List <Socket>(); var buffer = new byte[0x1000]; var current = new StringBuilder(); while (!shutdown) { check.Add(socket); Socket.Select(check, null, null, 1000000); if (check.Count == 0) { continue; } var len = socket.Receive(buffer, buffer.Length, SocketFlags.None); if (len == 0) { break; } foreach (var c in PacketBase.Encoding.GetString(buffer, 0, len)) { if (c == PacketBase.Delimiter) { var result = false; AppTools.TryInvoke(() => { result = HandlePacket(current.ToString()); }); if (!result) { Flush(); goto Breakout; } current.Clear(); continue; } current.Append(c); } Flush(); } Breakout :; } catch (ThreadAbortException) { } catch (Exception e) { AppTools.TryInvoke(() => { Faulted?.Invoke(this, new EndPointExceptionEventArgs(e)); }); } finally { try { socket.Close(); socket = null; if (callback != null) { AppTools.TryInvoke(() => { callback(); }); } } catch (Exception ea) { AppTools.TryInvoke(() => { Faulted?.Invoke(this, new EndPointExceptionEventArgs(ea)); }); } shutdown = false; running = false; AppTools.TryInvoke(() => { Disconnected?.Invoke(this, new EventArgs()); }); } }
/// <summary> /// Invokes Faulted event /// </summary> /// <remarks>Deliberately not async as used only for interactive testing</remarks> /// <param name="e"></param> protected void OnFaulted(AsyncServiceFaultedEventArgs e) { Faulted?.Invoke(this, e); }
private void OnFaulted(object sender, ProtocolErrorEventArgs e) { Faulted?.Invoke(this, new FaultedPluginEventArgs(this, e.Exception)); }
protected virtual void OnFaulted() { Faulted?.Invoke(this, System.EventArgs.Empty); }
private void OnProcessFaulted(Task task) { Faulted?.Invoke(this, task.Exception); }
public bool IsStarted(ReceiveEndpoint instance) { return(Started.Equals(instance.CurrentState) || Ready.Equals(instance.CurrentState) || Faulted.Equals(instance.CurrentState)); }
/// <summary> /// Initializes a new instance of the <see cref="FaultedTest"/> class. /// </summary> public FaultedTest() { this._genome = new ImmutableGenome(new Genome()); this._faultedMessage = new Faulted <TestInstance>(this._genome, FaultedTest.instance, this._exception); }
public SensorFaultedMesssage(Faulted faultedEvent) { }
private void InnerDuplexChannel_Faulted(object sender, EventArgs e) { Faulted?.Invoke(this, e); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Faulted obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
private void OnFaulted(object sender, EventArgs e) { Faulted?.Invoke(this, e); }
private void OnFaulted(object sender, ProtocolErrorEventArgs e) { Faulted?.Invoke(this, e); }