/// <summary> /// This method adds a DispatchTaskResultEntity to _context, but does NOT save the changes /// </summary> /// <param name="dispatchTaskEntity"></param> /// <returns>the new DispatchTaskResultEntity</returns> private DispatchTaskResultEntity NewDispatchTaskResultEntity(DispatchTaskEntity dispatchTaskEntity) { var expirationSeconds = dispatchTaskEntity.ExpirationSeconds; if (expirationSeconds <= 0) { expirationSeconds = _options.DispatchTaskProcessMaxWaitSeconds; } var dispatchTaskResultEntity = new DispatchTaskResultEntity() { DispatchTaskId = dispatchTaskEntity.Id, ApiUrl = dispatchTaskEntity.ApiUrl, InputString = dispatchTaskEntity.InputString, ExpirationSeconds = expirationSeconds, Iterations = dispatchTaskEntity.Iterations, IntervalSeconds = dispatchTaskEntity.IntervalSeconds, Status = Data.TaskStatus.pending, ExpectedOutput = dispatchTaskEntity.ExpectedOutput, SentDate = DateTime.UtcNow, StatusDate = DateTime.UtcNow, DateCreated = DateTime.UtcNow }; return(dispatchTaskResultEntity); }
private async Task <DispatchTaskEntity> CopyDispatchTaskEntity(DispatchTaskEntity oldDispatchTaskEntity, Guid?triggerTaskId, Guid?scenarioId, CancellationToken ct) { var newDispatchTaskEntity = new DispatchTaskEntity() { ScenarioId = scenarioId, SessionId = null, CreatedBy = _user.GetId(), TriggerTaskId = triggerTaskId, Name = oldDispatchTaskEntity.Name, Description = oldDispatchTaskEntity.Description, Action = oldDispatchTaskEntity.Action, VmMask = oldDispatchTaskEntity.VmMask, ApiUrl = oldDispatchTaskEntity.ApiUrl, InputString = oldDispatchTaskEntity.InputString, ExpectedOutput = oldDispatchTaskEntity.ExpectedOutput, ExpirationSeconds = oldDispatchTaskEntity.ExpirationSeconds, DelaySeconds = oldDispatchTaskEntity.DelaySeconds, IntervalSeconds = oldDispatchTaskEntity.IntervalSeconds, Iterations = oldDispatchTaskEntity.Iterations, TriggerCondition = oldDispatchTaskEntity.TriggerCondition }; _context.DispatchTasks.Add(newDispatchTaskEntity); return(newDispatchTaskEntity); }
private void VerifyManualTaskAsync(DispatchTaskEntity dispatchTaskToExecute) { var dispatchTaskResults = _context.DispatchTaskResults.Where(dtr => dtr.DispatchTaskId == dispatchTaskToExecute.Id && dtr.Status == Data.TaskStatus.pending); if (dispatchTaskResults.Any()) { var message = $"DispatchTask {dispatchTaskToExecute.Id} has a pending result {dispatchTaskResults.First().Id}, so it cannot be manually executed."; _logger.LogInformation(message); throw new ArgumentException(message); } }
private async Task <bool> CopySubTasks(Guid oldDispatchTaskEntityId, DispatchTaskEntity newDispatchTaskEntity, CancellationToken ct) { var oldSubTaskEntities = _context.DispatchTasks.Where(dt => dt.TriggerTaskId == oldDispatchTaskEntityId); foreach (var oldSubTaskEntity in oldSubTaskEntities) { var newSubTaskEntity = await CopyDispatchTaskEntity(oldSubTaskEntity, newDispatchTaskEntity.Id, newDispatchTaskEntity.SessionId, ct); await CopySubTasks(oldSubTaskEntity.Id, newSubTaskEntity, ct); } return(true); }
private async Task <bool> ScheduleSubtask(DispatchTaskEntity subtaskEntity) { var startTime = DateTime.UtcNow.AddSeconds(subtaskEntity.DelaySeconds).ToString("yyyy-MM-ddTHH:mm:ss.fffffffK"); var endTime = DateTime.UtcNow.AddSeconds(subtaskEntity.DelaySeconds + (subtaskEntity.Iterations * subtaskEntity.IntervalSeconds)).ToString("yyyy-MM-ddTHH:mm:ss.fffffffK"); var workorder = new { groupName = "steamfitter", start = startTime, end = endTime, job = "WebHook", webhookid = _options.ForemanWebhookId, woTriggers = new[] { new { groupName = "steamfitter", interval = subtaskEntity.IntervalSeconds } }, woParams = new [] { new { name = "[task.id]", value = subtaskEntity.Id } } }; var jsonString = JsonConvert.SerializeObject(workorder); jsonString = jsonString.Replace("woTriggers", "triggers").Replace("woParams", "params"); var client = _httpClientFactory.CreateClient(); client.BaseAddress = new Uri(_options.ForemanUrl); var relativeAddress = $"api/WorkOrders/"; client.DefaultRequestHeaders.Add("authorization", new List <string>() { CurrentHttpContext.Authorization }); var httpContent = new StringContent(jsonString, Encoding.UTF8, "application/json-patch+json"); try { var scheduleResponse = await client.PostAsync(relativeAddress, httpContent); if (!scheduleResponse.IsSuccessStatusCode) { _logger.LogError($"Error scheduling DispatchTask {subtaskEntity.Id}! Response was {scheduleResponse.StatusCode}: {scheduleResponse.ReasonPhrase} - {scheduleResponse.RequestMessage}"); } return(scheduleResponse.IsSuccessStatusCode); } catch (Exception ex) { _logger.LogError($"Error scheduling DispatchTask {subtaskEntity.Id}! {ex.Message}. Check to make sure that the Foreman DispatchTask Scheduler is up and running."); return(false); } }
private async Task VerifySessionTaskAsync(DispatchTaskEntity dispatchTaskToExecute, CancellationToken ct) { var session = await _context.Sessions.FindAsync(dispatchTaskToExecute.SessionId); if (session.Status != SessionStatus.active) { var message = $"DispatchTask {dispatchTaskToExecute.Id} is part of session {session.Id}, which is not currently active. A Session must be active in order to execute its DispatchTask."; _logger.LogInformation(message); throw new ArgumentException(message); } else { // TODO: add session specific restraints on whether or not this task can run } }
private async Task CreateDispatchTaskResultsAsync(DispatchTaskEntity dispatchTaskToExecute, CancellationToken ct) { var dispatchTaskResultEntities = new List <DispatchTaskResultEntity>(); var sessionEntity = dispatchTaskToExecute.SessionId == null ? null : _context.Sessions.First(s => s.Id == dispatchTaskToExecute.SessionId); if (sessionEntity != null && sessionEntity.ExerciseId != null) { // if this task has a Session associated to an Exercise, create a VmList from the VmMask var exerciseVms = await _playerVmService.GetExerciseVmsAsync((Guid)sessionEntity.ExerciseId, ct); foreach (var vm in exerciseVms) { if (vm.Name.ToLower().Contains(dispatchTaskToExecute.VmMask.ToLower())) { var dispatchTaskResultEntity = NewDispatchTaskResultEntity(dispatchTaskToExecute); dispatchTaskResultEntity.VmId = vm.Id; dispatchTaskResultEntity.VmName = vm.Name; dispatchTaskResultEntities.Add(dispatchTaskResultEntity); } } } else if (dispatchTaskToExecute.VmMask.Count() > 0) { var vmIdList = dispatchTaskToExecute.VmMask.Split(",").ToList().ConvertAll(Guid.Parse); // if this task has no Session check the VmMask for a list of VM ID's foreach (var id in vmIdList) { var dispatchTaskResultEntity = NewDispatchTaskResultEntity(dispatchTaskToExecute); dispatchTaskResultEntity.VmId = id; dispatchTaskResultEntities.Add(dispatchTaskResultEntity); } } else { // this task has no VM's associated. Create one result entity var dispatchTaskResultEntity = NewDispatchTaskResultEntity(dispatchTaskToExecute); dispatchTaskResultEntities.Add(dispatchTaskResultEntity); } await _context.DispatchTaskResults.AddRangeAsync(dispatchTaskResultEntities); await _context.SaveChangesAsync(ct); return; }
private async Task VerifyDispatchTaskToExecuteAsync(DispatchTaskEntity dispatchTaskToExecute, CancellationToken ct) { if (dispatchTaskToExecute == null) { throw new EntityNotFoundException <DispatchTask>(); } else if (dispatchTaskToExecute.ScenarioId != null) { throw new ArgumentException($"DispatchTask {dispatchTaskToExecute.Id} is part of a scenario {dispatchTaskToExecute.ScenarioId} and cannot be executed."); } else if (dispatchTaskToExecute.SessionId != null) { await VerifySessionTaskAsync(dispatchTaskToExecute, ct); } else { VerifyManualTaskAsync(dispatchTaskToExecute); } }
private async Task <Data.TaskStatus> ExecuteStackstormTaskAsync(DispatchTaskEntity dispatchTaskToExecute, List <DispatchTaskResultEntity> resultEntityList, CancellationToken ct) { var overallStatus = Data.TaskStatus.succeeded; foreach (var resultEntity in resultEntityList) { Task <string> task = null; resultEntity.InputString = resultEntity.InputString.Replace("VmGuid", "Moid").Replace("{moid}", resultEntity.VmId.ToString()); resultEntity.VmName = _stackStormService.GetVmName((Guid)resultEntity.VmId); switch (dispatchTaskToExecute.Action) { case TaskAction.guest_file_read: { task = Task.Run(() => _stackStormService.GuestReadFile(resultEntity.InputString)); break; } case TaskAction.guest_process_run: { task = Task.Run(() => _stackStormService.GuestCommand(resultEntity.InputString)); break; } case TaskAction.vm_hw_power_on: { task = Task.Run(() => _stackStormService.VmPowerOn(resultEntity.InputString)); break; } case TaskAction.vm_hw_power_off: { task = Task.Run(() => _stackStormService.VmPowerOff(resultEntity.InputString)); break; } case TaskAction.vm_create_from_template: { task = Task.Run(() => _stackStormService.CreateVmFromTemplate(resultEntity.InputString)); break; } case TaskAction.vm_hw_remove: { task = Task.Run(() => _stackStormService.VmRemove(resultEntity.InputString)); break; } default: { var message = $"Task Action {dispatchTaskToExecute.Action} has not been implemented."; _logger.LogError(message); resultEntity.Status = Data.TaskStatus.failed; resultEntity.StatusDate = DateTime.UtcNow; break; } } if (task.Wait(TimeSpan.FromSeconds(resultEntity.ExpirationSeconds))) { resultEntity.ActualOutput = task.Result.ToString(); resultEntity.Status = ProcessDispatchTaskResult(resultEntity, ct); } else { resultEntity.ActualOutput = task.Result.ToString(); resultEntity.Status = Data.TaskStatus.expired; } resultEntity.StatusDate = DateTime.UtcNow; if (resultEntity.Status != Data.TaskStatus.succeeded) { if (overallStatus != Data.TaskStatus.failed) { overallStatus = resultEntity.Status; } } } await _context.SaveChangesAsync(); return(overallStatus); }
public static void Run(SteamfitterContext context) { // sketch users var uAdministrator = new UserEntity { Id = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), Name = "admin user" }; context.Users.Add(uAdministrator); // scenarios var scenario1 = new ScenarioEntity { Name = "First Scenario", Description = "My first scenario", CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow, DurationHours = 1 }; context.Scenarios.Add(scenario1); var scenario2 = new ScenarioEntity { Name = "Second Scenario", Description = "My second scenario", CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow, DurationHours = 2 }; context.Scenarios.Add(scenario2); var scenario3 = new ScenarioEntity { Name = "Third Scenario", Description = "My third scenario", CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow, DurationHours = 3 }; context.Scenarios.Add(scenario3); context.SaveChanges(); // sessions var session1 = new SessionEntity { Name = "Session001", Description = "Session #1", ScenarioId = scenario1.Id, StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddMonths(1), DateCreated = DateTime.UtcNow, CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), ExerciseId = Guid.Parse("453d394e-bf18-499b-9786-149b0f8d69ec"), Exercise = "RCC -E EM 2018", Status = SessionStatus.ready, OnDemand = false }; context.Sessions.Add(session1); var session2 = new SessionEntity { Name = "Session002", Description = "Session #2", ScenarioId = scenario1.Id, StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddMonths(2), DateCreated = DateTime.UtcNow, CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), ExerciseId = Guid.Parse("453d394e-bf18-499b-9786-149b0f8d69ec"), Exercise = "RCC -E EM 2018", Status = SessionStatus.ready, OnDemand = false }; context.Sessions.Add(session2); context.SaveChanges(); // //sessionVms (or 5209fff8-8098-f1de-40c3-ac0eb1c8d515?) // var vm1 = new SessionVmEntity {SessionId =session1.Id, Vm = Guid.Parse("0539a863-ece6-4ca7-ae8d-f46a909526e9")}; // context.SessionVms.Add(vm1); // context.SaveChanges(); // VmId = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9") // scenario #1 dispatchTasks var dispatchTask2 = new DispatchTaskEntity { Name = "Get host name", Description = "For scenario #1 get the host name from s3-vm", ScenarioId = scenario1.Id, ApiUrl = "stackstorm", Action = TaskAction.guest_process_run, InputString = "{\"VmGuid\": \"42313053-c2e6-42af-cf2a-6db9f791794a\", \"Username\": \"Developer\", \"Password\": \"develop@1\", \"CommandText\": \"CMD.EXE\", \"CommandArgs\": \"/c hostname\"}", ExpectedOutput = "DESKTOP-OM1GOK7", TriggerCondition = TaskTrigger.Manual, ExpirationSeconds = 0, IntervalSeconds = 0, Iterations = 0, CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow }; context.DispatchTasks.Add(dispatchTask2); var dispatchTask2b = new DispatchTaskEntity { Name = "Run netstat -an", Description = "For sceanrion #1 run netstat -an against all of the vm's", ScenarioId = scenario1.Id, ApiUrl = "stackstorm", Action = TaskAction.guest_process_run, InputString = "{\"VmGuid\": \"42313053-c2e6-42af-cf2a-6db9f791794a\", \"Username\": \"Developer\", \"Password\": \"develop@1\", \"CommandText\": \"CMD.EXE\", \"CommandArgs\": \"/c netstat -an\"}", ExpectedOutput = "This will never work!", TriggerCondition = TaskTrigger.Manual, ExpirationSeconds = 0, IntervalSeconds = 0, Iterations = 0, CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow }; context.DispatchTasks.Add(dispatchTask2b); // sceanrio #2 dispatchTasks var dispatchTaskC1 = new DispatchTaskEntity { Name = "Parent Task #1", Description = "Read the test file from s3-vm", ScenarioId = scenario2.Id, ApiUrl = "stackstorm", Action = TaskAction.guest_file_read, InputString = "{\"VmGuid\": \"42313053-c2e6-42af-cf2a-6db9f791794a\", \"Username\": \"Developer\", \"Password\": \"develop@1\", \"GuestFilePath\": \"C:\\\\Users\\\\Developer\\\\testGet.txt\"}", ExpectedOutput = "This is the text from the TEST file.", TriggerCondition = TaskTrigger.Manual, ExpirationSeconds = 0, IntervalSeconds = 0, Iterations = 0, CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow }; context.DispatchTasks.Add(dispatchTaskC1); var dispatchTaskC1b = new DispatchTaskEntity { Name = "Success Task", Description = "Read the success file from s3-vm", ScenarioId = scenario2.Id, ApiUrl = "stackstorm", Action = TaskAction.guest_file_read, InputString = "{\"VmGuid\": \"42313053-c2e6-42af-cf2a-6db9f791794a\", \"Username\": \"Developer\", \"Password\": \"develop@1\", \"GuestFilePath\": \"C:\\\\Users\\\\Developer\\\\testSuccess.txt\"}", ExpectedOutput = "This is the text from the SUCCESS file.", TriggerTask = dispatchTaskC1, TriggerCondition = TaskTrigger.Success, ExpirationSeconds = 0, IntervalSeconds = 0, Iterations = 0, CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow }; context.DispatchTasks.Add(dispatchTaskC1b); var dispatchTaskC3 = new DispatchTaskEntity { Name = "Failure Task", Description = "Read the failure file from s3-vm", ScenarioId = scenario2.Id, ApiUrl = "stackstorm", Action = TaskAction.guest_file_read, InputString = "{\"VmGuid\": \"42313053-c2e6-42af-cf2a-6db9f791794a\", \"Username\": \"Developer\", \"Password\": \"develop@1\", \"GuestFilePath\": \"C:\\\\Users\\\\Developer\\\\testFailure.txt\"}", ExpectedOutput = "This is the text from the FAILURE file.", TriggerTask = dispatchTaskC1, TriggerCondition = TaskTrigger.Failure, ExpirationSeconds = 0, IntervalSeconds = 0, Iterations = 0, CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow }; context.DispatchTasks.Add(dispatchTaskC3); var dispatchTaskC4 = new DispatchTaskEntity { Name = "Completion Task", Description = "Read the completion file from s3-vm", ScenarioId = scenario2.Id, ApiUrl = "stackstorm", Action = TaskAction.guest_file_read, InputString = "{\"VmGuid\": \"42313053-c2e6-42af-cf2a-6db9f791794a\", \"Username\": \"Developer\", \"Password\": \"develop@1\", \"GuestFilePath\": \"C:\\\\Users\\\\Developer\\\\testCompletion.txt\"}", ExpectedOutput = "This is the text from the COMPLETION file.", TriggerTask = dispatchTaskC1, TriggerCondition = TaskTrigger.Completion, ExpirationSeconds = 0, IntervalSeconds = 0, Iterations = 0, CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow }; context.DispatchTasks.Add(dispatchTaskC4); var dispatchTaskC5 = new DispatchTaskEntity { Name = "Expiration Task", Description = "Read the expiration file from s3-vm", ScenarioId = scenario2.Id, ApiUrl = "stackstorm", Action = TaskAction.guest_file_read, InputString = "{\"VmGuid\": \"42313053-c2e6-42af-cf2a-6db9f791794a\", \"Username\": \"Developer\", \"Password\": \"develop@1\", \"GuestFilePath\": \"C:\\\\Users\\\\Developer\\\\testExpiration.txt\"}", ExpectedOutput = "This is the text from the EXPIRATION file.", TriggerTask = dispatchTaskC1, TriggerCondition = TaskTrigger.Expiration, ExpirationSeconds = 0, IntervalSeconds = 0, Iterations = 0, CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow }; context.DispatchTasks.Add(dispatchTaskC5); var dispatchTaskC6 = new DispatchTaskEntity { Name = "Delayed Task", Description = "Read the delay file from s3-vm", ScenarioId = scenario2.Id, ApiUrl = "stackstorm", Action = TaskAction.guest_file_read, InputString = "{\"VmGuid\": \"42313053-c2e6-42af-cf2a-6db9f791794a\", \"Username\": \"Developer\", \"Password\": \"develop@1\", \"GuestFilePath\": \"C:\\\\Users\\\\Developer\\\\testDelay.txt\"}", ExpectedOutput = "This is the text from the DELAY file.", TriggerTask = dispatchTaskC4, TriggerCondition = TaskTrigger.Completion, ExpirationSeconds = 0, IntervalSeconds = 0, Iterations = 0, DelaySeconds = 10, CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow }; context.DispatchTasks.Add(dispatchTaskC6); // session #1 dispatchTasks var dispatchTask1 = new DispatchTaskEntity { Name = "Parent Task", Description = "Parent Task #1a", SessionId = session1.Id, ApiUrl = "stackstorm", Action = TaskAction.guest_file_read, InputString = "{\"VmGuid\": \"42313053-c2e6-42af-cf2a-6db9f791794a\", \"Username\": \"Developer\", \"Password\": \"develop@1\", \"GuestFilePath\": \"C:\\\\Users\\\\Developer\\\\testGet.txt\"}", ExpectedOutput = "This is the text from the TEST file.", TriggerCondition = TaskTrigger.Manual, ExpirationSeconds = 0, IntervalSeconds = 0, Iterations = 0, CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow }; context.DispatchTasks.Add(dispatchTask1); var dispatchTask1b = new DispatchTaskEntity { Name = "Success Task", Description = "Success Task #1b", SessionId = session1.Id, ApiUrl = "stackstorm", Action = TaskAction.guest_file_read, InputString = "{\"VmGuid\": \"42313053-c2e6-42af-cf2a-6db9f791794a\", \"Username\": \"Developer\", \"Password\": \"develop@1\", \"GuestFilePath\": \"C:\\\\Users\\\\Developer\\\\testSuccess.txt\"}", ExpectedOutput = "This is the text from the SUCCESS file.", TriggerTask = dispatchTask1, TriggerCondition = TaskTrigger.Success, ExpirationSeconds = 0, IntervalSeconds = 0, Iterations = 0, CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow }; context.DispatchTasks.Add(dispatchTask1b); context.DispatchTasks.Add(dispatchTask2b); var dispatchTask3 = new DispatchTaskEntity { Name = "Failure Task", Description = "Failure Task #3", SessionId = session1.Id, ApiUrl = "stackstorm", Action = TaskAction.guest_file_read, InputString = "{\"VmGuid\": \"42313053-c2e6-42af-cf2a-6db9f791794a\", \"Username\": \"Developer\", \"Password\": \"develop@1\", \"GuestFilePath\": \"C:\\\\Users\\\\Developer\\\\testFailure.txt\"}", ExpectedOutput = "This is the text from the FAILURE file.", TriggerTask = dispatchTask1, TriggerCondition = TaskTrigger.Failure, ExpirationSeconds = 0, IntervalSeconds = 0, Iterations = 0, CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow }; context.DispatchTasks.Add(dispatchTask3); var dispatchTask4 = new DispatchTaskEntity { Name = "Completion Task", Description = "Completion Task #4", SessionId = session1.Id, ApiUrl = "stackstorm", Action = TaskAction.guest_file_read, InputString = "{\"VmGuid\": \"42313053-c2e6-42af-cf2a-6db9f791794a\", \"Username\": \"Developer\", \"Password\": \"develop@1\", \"GuestFilePath\": \"C:\\\\Users\\\\Developer\\\\testCompletion.txt\"}", ExpectedOutput = "This is the text from the COMPLETION file.", TriggerTask = dispatchTask1, TriggerCondition = TaskTrigger.Completion, ExpirationSeconds = 0, IntervalSeconds = 0, Iterations = 0, CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow }; context.DispatchTasks.Add(dispatchTask4); var dispatchTask5 = new DispatchTaskEntity { Name = "Expiration Task", Description = "Expiration Task #5", SessionId = session1.Id, ApiUrl = "stackstorm", Action = TaskAction.guest_file_read, InputString = "{\"VmGuid\": \"42313053-c2e6-42af-cf2a-6db9f791794a\", \"Username\": \"Developer\", \"Password\": \"develop@1\", \"GuestFilePath\": \"C:\\\\Users\\\\Developer\\\\testExpiration.txt\"}", ExpectedOutput = "This is the text from the EXPIRATION file.", TriggerTask = dispatchTask1, TriggerCondition = TaskTrigger.Expiration, ExpirationSeconds = 0, IntervalSeconds = 0, Iterations = 0, CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow }; context.DispatchTasks.Add(dispatchTask5); var dispatchTask6 = new DispatchTaskEntity { Name = "Delayed Task", Description = "Delayed Task #6", SessionId = session1.Id, ApiUrl = "stackstorm", Action = TaskAction.guest_file_read, InputString = "{\"VmGuid\": \"42313053-c2e6-42af-cf2a-6db9f791794a\", \"Username\": \"Developer\", \"Password\": \"develop@1\", \"GuestFilePath\": \"C:\\\\Users\\\\Developer\\\\testDelay.txt\"}", ExpectedOutput = "This is the text from the DELAY file.", TriggerTask = dispatchTask4, TriggerCondition = TaskTrigger.Completion, ExpirationSeconds = 0, IntervalSeconds = 0, Iterations = 0, DelaySeconds = 10, CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow }; context.DispatchTasks.Add(dispatchTask6); // independent task var dispatchTask1c = new DispatchTaskEntity { Name = "Independent Task", Description = "Independent Task #1c", ApiUrl = "stackstorm", Action = TaskAction.guest_file_read, InputString = "{\"VmGuid\": \"42313053-c2e6-42af-cf2a-6db9f791794a\", \"Username\": \"Developer\", \"Password\": \"develop@1\", \"GuestFilePath\": \"C:\\\\Users\\\\Developer\\\\testGet.txt\"}", ExpectedOutput = "This is the text from the TEST file.", TriggerCondition = TaskTrigger.Manual, ExpirationSeconds = 0, IntervalSeconds = 0, Iterations = 0, CreatedBy = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), UserId = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), DateCreated = DateTime.UtcNow }; context.DispatchTasks.Add(dispatchTask1c); context.SaveChanges(); // // DispatchTaskResults context.DispatchTaskResults.Add(new DispatchTaskResultEntity { DispatchTaskId = dispatchTask1.Id, VmId = Guid.Parse("0539a863-ece6-4ca7-ae8d-f46a909526e9"), VmName = "S3-VM2", Status = TaskStatus.queued, InputString = "copy test1.txt success.txt", ExpectedOutput = "Copied", ExpirationSeconds = 61, Iterations = 1, IntervalSeconds = 0, DateCreated = DateTime.Now.AddMinutes(-33) }); context.DispatchTaskResults.Add(new DispatchTaskResultEntity { DispatchTaskId = dispatchTask2.Id, VmId = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), VmName = "S3-VM3", Status = TaskStatus.queued, InputString = "copy test2.txt success.txt", ExpectedOutput = "Oh boy!", ExpirationSeconds = 62, Iterations = 2, IntervalSeconds = 120, DateCreated = DateTime.Now.AddMinutes(-43) }); context.DispatchTaskResults.Add(new DispatchTaskResultEntity { DispatchTaskId = dispatchTask2.Id, VmId = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), VmName = "S3-VM3", Status = TaskStatus.succeeded, InputString = "copy test.txt success.txt", ExpectedOutput = "Completed", ActualOutput = "Completed", ExpirationSeconds = 62, Iterations = 2, IntervalSeconds = 120, DateCreated = DateTime.Now.AddMinutes(-53) }); context.DispatchTaskResults.Add(new DispatchTaskResultEntity { DispatchTaskId = dispatchTask2.Id, VmId = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), VmName = "S3-VM3", Status = TaskStatus.failed, InputString = "copy test.txt success.txt", ExpectedOutput = "Completed", ActualOutput = "Failure", ExpirationSeconds = 62, Iterations = 2, IntervalSeconds = 120, DateCreated = DateTime.Now.AddMinutes(-55) }); context.DispatchTaskResults.Add(new DispatchTaskResultEntity { DispatchTaskId = dispatchTask2.Id, VmId = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), VmName = "S3-VM3", Status = TaskStatus.succeeded, InputString = "copy test.txt success.txt", ExpectedOutput = "Completed", ActualOutput = "Completed", ExpirationSeconds = 62, Iterations = 2, IntervalSeconds = 120, DateCreated = DateTime.Now.AddMinutes(-153) }); context.DispatchTaskResults.Add(new DispatchTaskResultEntity { DispatchTaskId = dispatchTask2.Id, VmId = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), VmName = "S3-VM3", Status = TaskStatus.sent, InputString = "copy test.txt success.txt", ExpectedOutput = "Completed", ExpirationSeconds = 62, Iterations = 2, IntervalSeconds = 120, DateCreated = DateTime.Now.AddMinutes(-155) }); context.DispatchTaskResults.Add(new DispatchTaskResultEntity { DispatchTaskId = dispatchTask2.Id, VmId = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), VmName = "S3-VM3", Status = TaskStatus.error, InputString = "copy test.txt success.txt", ExpectedOutput = "Completed", ExpirationSeconds = 62, Iterations = 2, IntervalSeconds = 120, DateCreated = DateTime.Now.AddMinutes(-156) }); context.DispatchTaskResults.Add(new DispatchTaskResultEntity { DispatchTaskId = dispatchTask2.Id, VmId = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), VmName = "S3-VM3", Status = TaskStatus.queued, InputString = "copy test.txt success.txt", ExpectedOutput = "Completed", ExpirationSeconds = 62, Iterations = 2, IntervalSeconds = 120, DateCreated = DateTime.Now.AddMinutes(-157) }); context.DispatchTaskResults.Add(new DispatchTaskResultEntity { DispatchTaskId = dispatchTask2.Id, VmId = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), VmName = "S3-VM3", Status = TaskStatus.expired, InputString = "copy test.txt success.txt", ExpectedOutput = "Completed", ExpirationSeconds = 62, Iterations = 2, IntervalSeconds = 120, DateCreated = DateTime.Now.AddMinutes(-158) }); context.DispatchTaskResults.Add(new DispatchTaskResultEntity { DispatchTaskId = dispatchTask2.Id, VmId = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), VmName = "S3-VM3", Status = TaskStatus.pending, InputString = "copy test.txt success.txt", ExpectedOutput = "Completed", ExpirationSeconds = 62, Iterations = 2, IntervalSeconds = 120, DateCreated = DateTime.Now.AddMinutes(-159) }); context.DispatchTaskResults.Add(new DispatchTaskResultEntity { DispatchTaskId = dispatchTask2.Id, VmId = Guid.Parse("9fd3c38e-58b0-4af1-80d1-1895af91f1f9"), VmName = "S3-VM3", Status = TaskStatus.cancelled, InputString = "copy test.txt success.txt", ExpectedOutput = "Completed", ExpirationSeconds = 62, Iterations = 2, IntervalSeconds = 120, DateCreated = DateTime.Now.AddMinutes(-175) }); context.SaveChanges(); Console.WriteLine("Seed data completed"); }