public MachineOperation(Machine m, ProgressToken t, string operationName, Logging.MachineControllerEventIds eventId) { Machine = m; Token = t; OperationName = operationName; EventId = eventId; _timer = new Stopwatch(); }
public void Execute(MachineOperationToken successfulOperatedMachines, Logging.MachineControllerEventIds onFailEventId) { _timer.Restart(); try { Token.Wait(); if (Token.WaitTimedOut) { _log.TraceEvent(TraceEventType.Warning, (int)EventId, "{0} on machine \"{1}\" timed out.", OperationName, Machine.Name); } else { successfulOperatedMachines.SuccessfullyOperatedMachine(this); } } catch (Exception ex) { _log.TraceEvent(TraceEventType.Error, (int)onFailEventId, "{0} on machine \"{1}\" failed because: {2}", OperationName, Machine.Name, ex.ToString()); } finally { _timer.Stop(); } }
void operatMachine(Func <ProgressToken> operation, Machine m, string operationDescription, MachineOperationToken successfulOperations, Logging.MachineControllerEventIds eventId, Logging.MachineControllerEventIds failEventId) { try { ProgressToken t = operation.Invoke(); estimateAndAnnounceTimeForProgressToken(t, successfulOperations); MachineOperation op = new MachineOperation(m, t, operationDescription, eventId); op.Execute(successfulOperations, Logging.MachineControllerEventIds.MachineStartupFailed); } catch (Exception ex) { _log.TraceEvent(TraceEventType.Error, (int)failEventId, "{0} on machine {1} resulted in an error: {2}", operationDescription, m.Name, ex.ToString()); //no rethrow, because we do not want to interrupt the other processes } }