private void Logger_LogError(object sender, LogErrorEventArgs args) { if (this.logError != null) { this.logError(this, args); } }
/// <summary> /// Hook LogError events and schedule a restart /// </summary> private void Logger_LogError(object sender, LogErrorEventArgs args) { Trace.WriteLine("SsmLogger.Logger_LogError: " + SsmUtility.GetExceptionMessage(args.Exception)); if (this.logError != null) { this.logError(sender, args); } this.TryStateTransition(State.Resyncing, delegate { this.ScheduleRestart(TimeSpan.FromSeconds(1.0)); }); }
private void EndMultipleReadCallback(IAsyncResult asyncResult) { byte[] rawValues; Exception exception = null; InternalLogProfile oldProfile = (InternalLogProfile)asyncResult.AsyncState; try { rawValues = this.ecu.EndMultipleRead(asyncResult); oldProfile.StoreSsmValues(rawValues); if (this.LogEntry != null) { this.LogEntry(this, oldProfile.LogEventArgs); } if (this.state == LoggerState.Logging) { InternalLogProfile newProfile = this.internalProfile; if (newProfile != oldProfile) { if (this.LogStop != null) { LogStopEventArgs stopArgs = new LogStopEventArgs(oldProfile.LogEventArgs.UserData); this.LogStop(this, stopArgs); } if (this.LogStart != null) { this.LogStart(this, newProfile.LogEventArgs); } } if (this.queryAddress != 0) { // Read a single value from the ECU before resuming logging. int address = this.queryAddress; this.queryAddress = 0; this.ecu.BeginBlockRead(address, 4, QueryCallback, newProfile); } else { // Continue logging rows as usual. this.ecu.BeginMultipleRead(newProfile.Addresses, EndMultipleReadCallback, newProfile); } } else { this.SetState(LoggerState.Stopped, "EndMultipleReadCallback", delegate { if (this.stopLoggingAsyncResult != null) { this.stopLoggingAsyncResult.Completed(); this.stopLoggingAsyncResult = null; } }); if (this.LogStop != null) { LogStopEventArgs stopArgs = new LogStopEventArgs(oldProfile.LogEventArgs.UserData); this.LogStop(this, stopArgs); } } } catch (UnauthorizedAccessException ex) { exception = ex; } catch (IOException ex) { exception = ex; } if (exception != null) { Trace.WriteLine("SsmBasicLogger.EndMultipleReadCallback: Exception thrown from consumer's log event handler"); LogErrorEventArgs args = new LogErrorEventArgs(exception); if (this.LogError != null) { this.LogError(this, args); } this.SetState(LoggerState.Stopped, "EndMultipleReadCallback, exception thrown"); if (this.LogStop != null) { LogStopEventArgs stopArgs = new LogStopEventArgs(oldProfile.LogEventArgs.UserData); this.LogStop(this, stopArgs); } if (this.stopLoggingAsyncResult != null) { this.stopLoggingAsyncResult.Completed(); this.stopLoggingAsyncResult = null; } } }