protected override string Insert(StepLog log) { FileInfo filePath = EnsureFilePath(log.TaskLog); File.AppendAllText(filePath.FullName, Line(log)); return(log.TaskLog.Id); }
protected override void Update(StepLog log) { Persist(session => session.Execute($@" UPDATE [{_configuration.TableName(IntegrationDbTable.TaskLog)}] SET ExecutionTimeSeconds = @ExecutionTimeSeconds, ErrorLog_Id = @ErrorLog_Id WHERE Id = @Id", new { log.Id, ExecutionTimeSeconds = log.ExecutionTimeSeconds.GetValueOrDefault(), ErrorLog_Id = log.ErrorLog?.Id })); }
protected override void Update(StepLog log) { FileInfo fileInfo = this.EnsureFilePath(log.TaskLog); StringBuilder stringBuilder = new StringBuilder(); if (log.ErrorLog != null) { stringBuilder.Append(this.ErrorLine(log.ErrorLog, log.Name)); } stringBuilder.Append(this.EndLine(log)); File.AppendAllText(fileInfo.FullName, stringBuilder.ToString()); }
public override bool NextStep() { if (ProductionState.FutureProductionPlan.Count == 0) { return(false); } #if HISTORY History.Push(ProductionState.Copy()); #endif var needed = ProductionState.FutureProductionPlan.Dequeue(); var current = ProductionState.ProductionHistory.Dequeue(); ProductionState.ProductionHistory.Enqueue(needed); var nearestFreePosition = GetNearestEmptyPosition(ProductionState); (int r, int c) = ProductionState.GetWarehouseIndex(nearestFreePosition); ProductionState.WarehouseState[r, c] = current; var nearestNeededPosition = GetNearesElementWarehousePosition(ProductionState, needed); (r, c) = ProductionState.GetWarehouseIndex(nearestNeededPosition); ProductionState.WarehouseState[r, c] = ItemState.Empty; var insertTime = ProductionState.TimeMatrix[ProductionState.GetTimeMatrixIndex(PositionCodes.Stacker), ProductionState.GetTimeMatrixIndex(nearestFreePosition)]; var moveToDifferentCellTime = ProductionState.TimeMatrix[ProductionState.GetTimeMatrixIndex(nearestFreePosition), ProductionState.GetTimeMatrixIndex(nearestNeededPosition)] - 5; // TODO: Validate this calculation moveToDifferentCellTime = moveToDifferentCellTime < 0 ? 0 : moveToDifferentCellTime; var withdrawTime = ProductionState.TimeMatrix[ProductionState.GetTimeMatrixIndex(nearestNeededPosition), ProductionState.GetTimeMatrixIndex(PositionCodes.Stacker)]; var totalTime = insertTime + moveToDifferentCellTime + withdrawTime; ProductionState.CurrentStepTime = totalTime; ProductionState.TimeSpentInSimulation += totalTime; ProductionState.ProductionStateIsOk = ProductionState.ProductionStateIsOk && totalTime <= TimeLimit; RealTime += ClockTime; if (totalTime > TimeLimit) { Delay += totalTime - TimeLimit; RealTime += totalTime - TimeLimit; } ProductionState.StepCounter++; StepLog.Add(new StepModel { InsertToCell = nearestFreePosition, WithdrawFromCell = nearestNeededPosition, InsertType = current, WithdrawType = needed, InsertTime = insertTime, MoveToDifferentCellTime = moveToDifferentCellTime, WithdrawTime = withdrawTime }); return(true); }
protected override string Insert(StepLog log) { return(Persist(session => session.ExecuteScalar <int>($@" INSERT INTO [{_configuration.TableName(IntegrationDbTable.TaskLog)}] (Type, TaskName, StepName, TimeStamp, TaskLog_Id) VALUES ('S', @TaskName, @StepName, @TimeStamp, @TaskLog_Id) SELECT CAST(SCOPE_IDENTITY() AS INT)", new { TaskName = log.TaskLog.Name, StepName = log.Name, log.TimeStamp, TaskLog_Id = log.TaskLog.Id })).ToString()); }
public override void GetHandler() { var nearestNeededPosition = GetNearesElementWarehousePosition(ProductionState, ItemState.Empty); var stackerRoundtripForItem = ProductionState[PositionCodes.Stacker, nearestNeededPosition] + ProductionState[nearestNeededPosition, PositionCodes.Stacker] - StackerOperationTime * 2; ProductionState[nearestNeededPosition] = Current; var nextIntake = GetClosestNextIntakeTime(); var realTimeBeforeOp = RealTime; RealTime += stackerRoundtripForItem; IsReadyForBreak = true; AsyncStepModel step = new AsyncStepModel { CurrentState = AsyncControllerState.Get, Message = $"RealTime: {RealTime}, Current: {Current}, Took item to position: {nearestNeededPosition} with time {stackerRoundtripForItem}, Next intake in: {nextIntake}, Time before get: {realTimeBeforeOp}" }; /*if (RealTime > nextIntake) * { * Delay += RealTime - nextIntake; * nextIntake = GetClosestNextIntakeTime(); * }*/ ProductionState.ProductionHistory.Dequeue(); if (ProductionState.FutureProductionPlan.Peek() == ProductionState.ProductionHistory.Peek()) { CurrentState = AsyncControllerState.Start; RealTime = nextIntake; IntakeItem = ItemState.Empty; step.Message += $", Going to state: {CurrentState}, Skipped to intake {nextIntake}"; StepLog.Add(step); return; } double closestOuttake = GetClosestNextOuttakeTime(); double previousOuttake = GetPreviousOuttakeTime(); if (RealTime < closestOuttake && RealTime < previousOuttake) { RealTime = closestOuttake; step.Message += $", Skipped to outtake: {RealTime}"; } CurrentState = AsyncControllerState.Put; PreviousStateForPut = AsyncControllerState.Get; Needed = ProductionState.FutureProductionPlan.Peek(); step.Message += $", Going to state: {CurrentState}"; StepLog.Add(step); }
public static void LogStep <T>(string data = "") { var newFlowStep = new StepLog(); newFlowStep.FlowAndStep = typeof(T).ToString(); newFlowStep.Data = data; string stepLogJson = Newtonsoft.Json.JsonConvert.SerializeObject(newFlowStep); WriteInfoToLogFile("Flow: " + typeof(T) + ". Data: " + data); if (AppsLog.LogFlows) { logger.Info(stepLogJson); } }
protected override void Update(StepLog log) { FileInfo filePath = EnsureFilePath(log.TaskLog); var sb = new StringBuilder(); if (log.ErrorLog != null) { sb.Append(ErrorLine(log.ErrorLog, log.Name)); } sb.Append(EndLine(log)); File.AppendAllText(filePath.FullName, sb.ToString()); }
private TaskExecutionResult ExecuteInternal <TWorkItem>(ITask <TWorkItem> task, Arguments arguments) { if (task == null) { throw new ArgumentNullException(nameof(task)); } if (arguments == null) { throw new ArgumentNullException(nameof(arguments)); } var output = new List <string>(); void Outputter(string message) { message = $"[{Time.Now:HH:mm:ss}] {message}"; _console.WriteLine(message); output.Add(message); } using (var taskLog = new TaskLog(task, _logger.LogEntry, new Output(Outputter))) using (ConcurrentTaskExecutionResult taskExecution = HandleConcurrentTaskExecution(task, arguments, taskLog)) { if (taskExecution.StopTask) { return(new TaskExecutionResult(output.ToArray())); } Action <string>[] logMessage = { x => { } }; var log = new Log(message => logMessage[0]?.Invoke(message), _logger); var context = new TaskExecutionContext <TWorkItem>(taskLog, log, arguments, _shutdown.Token); if (task.IsDisabled(context)) { Outputter($"Task '{task.Name()}' is disabled."); return(new TaskExecutionResult(output.ToArray())); } try { logMessage[0] = taskLog.LogMessage; context.ThrowIfCancelled(); context.WorkItem = task.Start(context); } catch (Exception ex) { ErrorLog errorLog = _logger.LogError(ex); taskLog.ErrorLog = errorLog; throw new TaskExecutionFailedException($"Starting Task '{taskLog.Name}' failed with message: '{ex.DestructMessage()}'. ErrorID: {errorLog?.Id ?? "<null>"}.", ex); } try { foreach (IStep <TWorkItem> step in task.Steps) { using (StepLog stepLog = taskLog.LogStep(step)) { try { logMessage[0] = stepLog.LogMessage; context.ThrowIfCancelled(); Execution continueWith = step.ContinueWith(context); if (continueWith == Execution.StepOut) { break; } if (continueWith == Execution.StepOver) { continue; } context.ThrowIfCancelled(); step.Execute(context); } catch (Exception ex) { ErrorLog errorLog = _logger.LogError(ex); taskLog.ErrorLog = errorLog; stepLog.ErrorLog = errorLog; throw new TaskExecutionFailedException($"Step '{stepLog.Name}' on Task '{taskLog.Name}' failed with message: '{ex.Message}'. ErrorID: {errorLog?.Id ?? "<null>"}.", ex); } } } try { logMessage[0] = taskLog.LogMessage; context.ThrowIfCancelled(); task.End(context); } catch (Exception ex) { ErrorLog errorLog = _logger.LogError(ex); taskLog.ErrorLog = errorLog; throw new TaskExecutionFailedException($"Ending Task '{taskLog.Name}' failed with message: '{ex.Message}'. ErrorID: {errorLog?.Id ?? "<null>"}.", ex); } } finally { context.WorkItem.DisposeIfDisposable(); } } return(new TaskExecutionResult(output.ToArray())); }
protected abstract void Update(StepLog log);
protected abstract string Insert(StepLog log);
protected override void Update(StepLog log) { }
protected override string Insert(StepLog log) { return(null); }
protected override string Insert(StepLog log) { File.AppendAllText(this.EnsureFilePath(log.TaskLog).FullName, this.Line(log, null, new object[0])); return(log.TaskLog.Id); }
public override void PutHandler() { var nearestNeededPosition = GetNearesElementWarehousePosition(ProductionState, Needed); var stackerRoundtripForItem = ProductionState[PositionCodes.Stacker, nearestNeededPosition] + ProductionState[nearestNeededPosition, PositionCodes.Stacker] - StackerOperationTime * 2; ProductionState[nearestNeededPosition] = ItemState.Empty; var realTimeBeforeOp = RealTime; var nextOuttake = GetClosestNextOuttakeTime(); var nextIntake = GetClosestNextIntakeTime(); RealTime += stackerRoundtripForItem; Current = ProductionState.ProductionHistory.Peek(); IsReadyForBreak = false; AsyncStepModel step = new AsyncStepModel { CurrentState = AsyncControllerState.Put, Message = $"RealTime: {RealTime}, Need: {Needed}, Took item from position: {nearestNeededPosition} with time {stackerRoundtripForItem}, Next outtake in: {nextOuttake}, Came here from: {PreviousStateForPut}, Time before put: {realTimeBeforeOp}" }; switch (PreviousStateForPut) { case AsyncControllerState.Start: if (RealTime > nextOuttake) { Delay += RealTime - nextOuttake; CurrentState = AsyncControllerState.Get; nextOuttake = GetClosestNextOuttakeTime(); } if (RealTime <= nextOuttake) { OuttakeItem = Needed; CurrentState = AsyncControllerState.Get; //double closestIntake = GetClosestNextIntakeTime(); double closestIntake = nextIntake; if (RealTime < closestIntake) { RealTime = closestIntake; step.Message += $", Skipped to intake: {RealTime}"; } } break; //TODO: 7205 ma byt 131 tzn 1309 je zbytek //TODO: 2750 ma byt 50 aut a 1390 zbyva case AsyncControllerState.SwapChain: var deq = ProductionState.FutureProductionPlan.Dequeue(); ProductionState.ProductionHistory.Enqueue(deq); CurrentState = AsyncControllerState.Get; if (RealTime <= nextIntake) { //RealTime = GetClosestNextIntakeTime(); RealTime = nextIntake; step.Message += $", Skipped to intake: {RealTime}"; } OuttakeItem = Needed; Current = ProductionState.ProductionHistory.Peek(); IntakeItem = Current; break; case AsyncControllerState.Get: if (RealTime > nextOuttake) { Delay += RealTime - nextOuttake; CurrentState = AsyncControllerState.Get; nextOuttake = GetClosestNextOuttakeTime(); } if (RealTime <= nextOuttake) { OuttakeItem = Needed; Current = ProductionState.ProductionHistory.Peek(); CurrentState = AsyncControllerState.Get; var deq1 = ProductionState.FutureProductionPlan.Dequeue(); ProductionState.ProductionHistory.Enqueue(deq1); double closestIntake = GetClosestNextIntakeTime(); double previousIntake = GetPreviousOuttakeTime() - IntakeOuttakeDifference; if (RealTime < closestIntake & RealTime < previousIntake) { RealTime = closestIntake; step.Message += $", Skipped to intake: {RealTime}"; } } break; } step.Message += $", Going to state: {CurrentState}"; StepLog.Add(step); }
protected override void Update(StepLog log) { this.Persist((IDbSession session) => session.Execute("\r\nUPDATE TaskLog SET ExecutionTimeSeconds = @ExecutionTimeSeconds, ErrorLog_Id = @ErrorLog_Id WHERE Id = @Id", new { Id = log.Id, ExecutionTimeSeconds = log.ExecutionTimeSeconds.GetValueOrDefault(), ErrorLog_Id = (log.ErrorLog != null ? log.ErrorLog.Id : null) })); }
protected override string Insert(StepLog log) { int num = this.Persist((IDbSession session) => session.ExecuteScalar <int>("\r\nINSERT INTO TaskLog (Type, TaskName, StepName, TimeStamp, TaskLog_Id)\r\nVALUES ('S', @TaskName, @StepName, @TimeStamp, @TaskLog_Id)\r\nSELECT CAST(SCOPE_IDENTITY() AS INT)", new { TaskName = log.TaskLog.Name, StepName = log.Name, TimeStamp = log.TimeStamp, TaskLog_Id = log.TaskLog.Id })); return(num.ToString()); }
private TaskExecutionResult ExecuteInternal <TWorkItem>(ITask <TWorkItem> task, Arguments arguments) { TWorkItem tWorkItem; if (task == null) { throw new ArgumentNullException("task"); } if (arguments == null) { throw new ArgumentNullException("arguments"); } List <string> strs = new List <string>(); Action <string> action = (string message) => { message = string.Format("[{0:HH:mm:ss}] {1}", Time.Now, message); this._outputter.WriteLine(message); strs.Add(message); }; ILogger logger = this._logger; using (TaskLog taskLog = new TaskLog(task, new Action <LogEntry>(logger.LogEntry), new Output(action))) { try { tWorkItem = task.Start(new TaskExecutionContext(new Log(new Action <string>(taskLog.LogMessage), this._logger), arguments)); } catch (Exception exception1) { Exception exception = exception1; taskLog.ErrorLog = this._logger.LogError(exception, null); throw new TaskExecutionFailedException("Starting task failed.", exception); } try { foreach (IStep <TWorkItem> step in task.Steps) { Execution execution = step.ContinueWith(tWorkItem); if (execution != Execution.StepOut) { if (execution == Execution.StepOver) { continue; } using (StepLog stepLog = taskLog.LogStep(step)) { try { step.Execute(tWorkItem, new TaskExecutionContext(new Log(new Action <string>(stepLog.LogMessage), this._logger), arguments)); } catch (Exception exception3) { Exception exception2 = exception3; ErrorLog errorLog = this._logger.LogError(exception2, null); taskLog.ErrorLog = errorLog; stepLog.ErrorLog = errorLog; throw new TaskExecutionFailedException(string.Format("Step '{0}' failed.", stepLog.Name), exception2); } } } else { goto Label0; } } Label0: try { task.End(tWorkItem, new TaskExecutionContext(new Log(new Action <string>(taskLog.LogMessage), this._logger), arguments)); } catch (Exception exception5) { Exception exception4 = exception5; taskLog.ErrorLog = this._logger.LogError(exception4, null); throw new TaskExecutionFailedException("Ending task failed.", exception4); } } finally { tWorkItem.DisposeIfDisposable(); } } return(new TaskExecutionResult(strs.ToArray())); }
protected override string Insert(StepLog log) { // Text writer will not do anything, as TextWriter is already used by TaskRunner return(null); }