public async Task <HttpStatusCode> ConfirmAliveAsync(int processId, DateTime now, ControllableProcessStatus status) { using (_SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(ConfirmAliveAsync)))) { var methodNamesFromStack = _MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames(); _SimpleLogger.LogInformationWithCallStack($"Confirm that process with id={processId} is alive", methodNamesFromStack); var context = new DefaultContainer(new Uri(BaseUrl)); var processExists = await ProcessExists(context, processId); if (processExists.Inconclusive) { _SimpleLogger.LogInformationWithCallStack($"Could not determine if process with id={processId} exists", methodNamesFromStack); return(HttpStatusCode.InternalServerError); } if (!processExists.YesNo) { _SimpleLogger.LogInformationWithCallStack($"No process exists with id={processId}", methodNamesFromStack); return(HttpStatusCode.NotFound); } _SimpleLogger.LogInformationWithCallStack($"Update process with id={processId}", methodNamesFromStack); var controllableProcess = await context.ControllableProcesses.ByKey(processId).GetValueAsync(); controllableProcess.ConfirmedAt = now; controllableProcess.Status = status; context.UpdateObject(controllableProcess); var response = await context.SaveChangesAsync(SaveChangesOptions.None); var statusCode = response.Select(r => (HttpStatusCode)r.StatusCode).FirstOrDefault(); return(statusCode); } }
private async Task EnableOrDisableCommandAsync(Type commandType, bool enable) { using (SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(EnableOrDisableCommandAsync)))) { var wasEnabled = await EnabledAsync(commandType); lock (this) { if (enable) { EnableRequests[commandType]++; } else { DisableRequests[commandType]++; } if (DisableRequests[commandType] == EnableRequests[commandType]) { DisableRequests[commandType] = 0; EnableRequests[commandType] = 0; } } if (wasEnabled == await EnabledAsync(commandType)) { return; } await HandleApplicationFeedbackAsync(new FeedbackToApplication { Type = FeedbackType.CommandsEnabledOrDisabled }); } }
public async Task ExecuteAsync(Type commandType) { using (SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(ExecuteAsync)))) { var command = Commands.FirstOrDefault(x => x.GetType() == commandType); if (command == null) { await HandleApplicationFeedbackAsync(new FeedbackToApplication { Type = FeedbackType.UnknownCommand, CommandType = commandType }); return; } if (!await EnabledAsync(commandType)) { await HandleApplicationFeedbackAsync(new FeedbackToApplication { Type = FeedbackType.CommandIsDisabled, CommandType = commandType }); return; } if (command.MakeLogEntries) { await HandleApplicationFeedbackAsync(new FeedbackToApplication { Type = FeedbackType.LogInformation, Message = string.Format(Properties.Resources.ExecutingCommand, command.Name) }); } await DisableCommandRunTaskAndEnableCommandAsync(command); if (command.MakeLogEntries) { await HandleApplicationFeedbackAsync(new FeedbackToApplication { Type = FeedbackType.LogInformation, Message = string.Format(Properties.Resources.ExecutedCommand, command.Name) }); } await HandleApplicationFeedbackAsync(new FeedbackToApplication { Type = FeedbackType.CommandExecutionCompleted, CommandType = command.GetType() }); } }
public async Task <bool> EnabledAsync(Type commandType) { using (SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(EnabledAsync)))) { bool enabled; IApplicationCommand command; lock (this) { if (!DefaultEnabled.Keys.Contains(commandType)) { enabled = false; } else if (DefaultEnabled[commandType]) { enabled = DisableRequests[commandType] == 0; } else { enabled = EnableRequests[commandType] != 0; } if (!enabled) { return(false); } command = Commands.FirstOrDefault(x => x.GetType() == commandType); } enabled = command != null && await command.CanExecuteAsync(); return(enabled); } }
public void RunProcess(string executableFileName, string arguments, IFolder workingFolder, IErrorsAndInfos errorsAndInfos) { var id = Guid.NewGuid().ToString(); using (vSimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(ProcessRunner), id))) { vSimpleLogger.LogInformation($"Running {executableFileName} with arguments {arguments} in {workingFolder.FullName}"); using (var process = CreateProcess(executableFileName, arguments, workingFolder)) { try { var outputWaitHandle = new AutoResetEvent(false); var errorWaitHandle = new AutoResetEvent(false); process.OutputDataReceived += (_, e) => { OnDataReceived(e, outputWaitHandle, errorsAndInfos.Infos, LogLevel.Information); }; process.ErrorDataReceived += (_, e) => { OnDataReceived(e, errorWaitHandle, errorsAndInfos.Errors, LogLevel.Error); }; process.Exited += (_, _) => { vSimpleLogger.LogInformation("Process exited"); }; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(int.MaxValue); outputWaitHandle.WaitOne(); errorWaitHandle.WaitOne(); } catch (Exception e) { errorsAndInfos.Errors.Add($"Process failed: {e.Message}"); return; } } vSimpleLogger.LogInformation("Process completed"); } }
public async Task <DvinApp> GetTashAppAsync(IErrorsAndInfos errorsAndInfos) { using (_SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(GetTashAppAsync)))) { var methodNamesFromStack = _MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames(); _SimpleLogger.LogInformationWithCallStack("Returning tash app", methodNamesFromStack); return(await DvinRepository.LoadAsync(TashAppId, errorsAndInfos)); } }
public async Task <HttpStatusCode> ConfirmDeadAsync(int processId) { using (_SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(ConfirmDeadAsync)))) { var methodNamesFromStack = _MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames(); _SimpleLogger.LogInformationWithCallStack($"Confirm that process with id={processId} is dead", methodNamesFromStack); return(await ConfirmAliveAsync(processId, DateTime.Now, ControllableProcessStatus.Dead)); } }
public async Task <YesNoInconclusive> UpdateNugetPackagesInRepositoryAsync(IFolder repositoryFolder, IErrorsAndInfos errorsAndInfos) { using (SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(UpdateNugetPackagesInRepositoryAsync), Guid.NewGuid().ToString()))) { SimpleLogger.LogInformation("Determining files with uncommitted changes"); var yesNoInconclusive = new YesNoInconclusive(); var files = GitUtilities.FilesWithUncommittedChanges(repositoryFolder); yesNoInconclusive.Inconclusive = files.Any(f => EndingsThatAllowReset.All(e => !f.EndsWith("." + e, StringComparison.InvariantCultureIgnoreCase))); yesNoInconclusive.YesNo = false; if (yesNoInconclusive.Inconclusive) { errorsAndInfos.Infos.Add("Not all files allow a reset"); SimpleLogger.LogInformation($"Returning {yesNoInconclusive}"); return(yesNoInconclusive); } SimpleLogger.LogInformation("Resetting repository"); GitUtilities.Reset(repositoryFolder, GitUtilities.HeadTipIdSha(repositoryFolder), errorsAndInfos); if (errorsAndInfos.AnyErrors()) { errorsAndInfos.Infos.Add("Could not reset"); SimpleLogger.LogInformation($"Returning {yesNoInconclusive}"); return(yesNoInconclusive); } SimpleLogger.LogInformation("Searching for project files"); var projectFileFullNames = Directory.GetFiles(repositoryFolder.SubFolder("src").FullName, "*.csproj", SearchOption.AllDirectories).ToList(); if (!projectFileFullNames.Any()) { errorsAndInfos.Infos.Add("No project files found"); SimpleLogger.LogInformation($"Returning {yesNoInconclusive}"); return(yesNoInconclusive); } foreach (var projectFileFullName in projectFileFullNames) { SimpleLogger.LogInformation($"Analyzing project file {projectFileFullName}"); var projectErrorsAndInfos = new ErrorsAndInfos(); if (!await UpdateNugetPackagesForProjectAsync(projectFileFullName, yesNoInconclusive.YesNo, projectErrorsAndInfos)) { continue; } yesNoInconclusive.YesNo = true; } if (yesNoInconclusive.YesNo) { errorsAndInfos.Infos.Add("No project was updated"); SimpleLogger.LogInformation($"Returning {yesNoInconclusive}"); return(yesNoInconclusive); } SimpleLogger.LogInformation("Resetting repository"); GitUtilities.Reset(repositoryFolder, GitUtilities.HeadTipIdSha(repositoryFolder), errorsAndInfos); SimpleLogger.LogInformation($"Returning {yesNoInconclusive}"); return(yesNoInconclusive); } }
public async Task HandleFeedbackToApplicationAsync(IFeedbackToApplication feedback) { using (SimpleLogger.BeginScope(SimpleLoggingScopeId.Create("Scope"))) { var methodNamesFromStack = MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames(); switch (feedback.Type) { case FeedbackType.CommandExecutionCompleted: case FeedbackType.CommandExecutionCompletedWithMessage: { await CommandExecutionCompletedHandlerAsync(feedback); } break; case FeedbackType.CommandsEnabledOrDisabled: { await CommandsEnabledOrDisabledHandlerAsync(); } break; case FeedbackType.LogInformation: { SimpleLogger.LogInformationWithCallStack(feedback.Message, methodNamesFromStack); } break; case FeedbackType.LogWarning: { SimpleLogger.LogWarningWithCallStack(feedback.Message, methodNamesFromStack); } break; case FeedbackType.LogError: { SimpleLogger.LogErrorWithCallStack(feedback.Message, methodNamesFromStack); } break; case FeedbackType.CommandIsDisabled: { SimpleLogger.LogErrorWithCallStack("Attempt to run disabled command " + feedback.CommandType, methodNamesFromStack); } break; case FeedbackType.ImportantMessage: { var fileName = feedback.Message; if (File.Exists(fileName)) { var folder = new Folder(Folder.Text); fileName = fileName.Substring(folder.FullName.Length + 1); Results.Items.Add(fileName); } } break; default: { throw new NotImplementedException(); } } } await Task.CompletedTask; }
public async Task <ControllableProcessTask> PickRequestedTask(int processId) { using (_SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(PickRequestedTask)))) { var methodNamesFromStack = _MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames(); _SimpleLogger.LogInformationWithCallStack($"Get requested task for process with id={processId}", methodNamesFromStack); var tasks = await GetControllableProcessTasksAsync(); return(tasks.FirstOrDefault(t => t.ProcessId == processId && t.Status == ControllableProcessTaskStatus.Requested)); } }
public async Task <IErrorsAndInfos> EnsureTashAppIsRunningAsync() { using (_SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(EnsureTashAppIsRunningAsync)))) { var methodNamesFromStack = _MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames(); _SimpleLogger.LogInformationWithCallStack("Ensuring tash app is running", methodNamesFromStack); var errorsAndInfos = new ErrorsAndInfos(); try { var processes = await GetControllableProcessesAsync(); if (processes != null) { _SimpleLogger.LogInformationWithCallStack("Tash app is running", methodNamesFromStack); return(errorsAndInfos); } } catch { _SimpleLogger.LogInformationWithCallStack("Exception was thrown, tash app probably is not running", methodNamesFromStack); } var tashApp = await GetTashAppAsync(errorsAndInfos); if (errorsAndInfos.AnyErrors()) { _SimpleLogger.LogInformationWithCallStack("Could not get tash app", methodNamesFromStack); return(errorsAndInfos); } var fileSystemService = new FileSystemService(); tashApp.Start(fileSystemService, errorsAndInfos); if (errorsAndInfos.AnyErrors()) { _SimpleLogger.LogInformationWithCallStack("Could not start tash app", methodNamesFromStack); errorsAndInfos.Errors.ToList().ForEach(e => _SimpleLogger.LogErrorWithCallStack(e, methodNamesFromStack)); return(errorsAndInfos); } await Task.Delay(TimeSpan.FromSeconds(10)); try { var processes = await GetControllableProcessesAsync(); if (processes != null) { _SimpleLogger.LogInformationWithCallStack("Tash app is running", methodNamesFromStack); return(errorsAndInfos); } } catch { const string errorMessage = "Tash started but not answering"; errorsAndInfos.Errors.Add(errorMessage); // Should this occur regularly, maybe the Tash process can be killed _SimpleLogger.LogErrorWithCallStack(errorMessage, methodNamesFromStack); } return(errorsAndInfos); } }
public async Task <IList <ControllableProcessTask> > GetControllableProcessTasksAsync() { using (_SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(GetControllableProcessTasksAsync)))) { var methodNamesFromStack = _MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames(); _SimpleLogger.LogInformationWithCallStack("Get controllable process tasks", methodNamesFromStack); var context = new DefaultContainer(new Uri(BaseUrl)); var processTasks = await context.ControllableProcessTasks.ExecuteAsync(); var processList = processTasks.ToList(); return(processList); } }
public void Log_CalledManyTimesWithRandomId_IsWorking() { _Sut = new SimpleLogger(CreateLogConfiguration(nameof(Log_CalledManyTimesWithRandomId_IsWorking)), _Flusher, _MethodNamesFromStackFramesExtractor); using (_Sut.BeginScope(SimpleLoggingScopeId.Create("Scope"))) { using (_Sut.BeginScope(SimpleLoggingScopeId.Create("Scope"))) { for (var i = 0; i < NumberOfLogEntries; i++) { _Sut.LogInformationWithCallStack(NotAMessage, _MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames()); } } } }
public async Task <ControllableProcess> GetControllableProcessAsync(int processId) { using (_SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(GetControllableProcessAsync)))) { var methodNamesFromStack = _MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames(); _SimpleLogger.LogInformationWithCallStack($"Get controllable process with id={processId}", methodNamesFromStack); var context = new DefaultContainer(new Uri(BaseUrl)); if (!(await ProcessExists(context, processId)).YesNo) { _SimpleLogger.LogInformationWithCallStack($"No process found with id={processId}", methodNamesFromStack); return(null); } var process = await context.ControllableProcesses.ByKey(processId).GetValueAsync(); _SimpleLogger.LogInformationWithCallStack($"Returning process with id={processId}", methodNamesFromStack); return(process); } }
public async Task <HttpStatusCode> ConfirmStatusAsync(Guid taskId, ControllableProcessTaskStatus status, string text, string errorMessage) { using (_SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(ConfirmStatusAsync)))) { var methodNamesFromStack = _MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames(); _SimpleLogger.LogInformationWithCallStack($"Confirm status {Enum.GetName(typeof(ControllableProcessStatus), status)} for task id={taskId}", methodNamesFromStack); DefaultContainer context; ControllableProcessTask controllableProcessTask = null; bool wasExceptionThrown; do { wasExceptionThrown = false; context = new DefaultContainer(new Uri(BaseUrl)); try { if (!await ProcessTaskExists(context, taskId)) { return(HttpStatusCode.NotFound); } _SimpleLogger.LogInformationWithCallStack($"Select task with id={taskId} for update", methodNamesFromStack); controllableProcessTask = await context.ControllableProcessTasks.ByKey(taskId).GetValueAsync(); } catch { _SimpleLogger.LogErrorWithCallStack($"Could not select task with id={taskId} for update, trying again", methodNamesFromStack); wasExceptionThrown = true; } } while (wasExceptionThrown); if (controllableProcessTask == null) { _SimpleLogger.LogInformationWithCallStack($"No task found with id={taskId}", methodNamesFromStack); return(HttpStatusCode.NotFound); } _SimpleLogger.LogInformationWithCallStack($"Update task with id={taskId}", methodNamesFromStack); controllableProcessTask.Status = status; controllableProcessTask.Text = text; controllableProcessTask.ErrorMessage = errorMessage; context.UpdateObject(controllableProcessTask); var response = await context.SaveChangesAsync(SaveChangesOptions.None); var statusCode = response.Select(r => (HttpStatusCode)r.StatusCode).FirstOrDefault(); return(statusCode); } }
private async Task <bool> UpdateNugetPackagesForProjectAsync(string projectFileFullName, bool yesNo, IErrorsAndInfos errorsAndInfos) { using (SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(UpdateNugetPackagesForProjectAsync), Guid.NewGuid().ToString()))) { SimpleLogger.LogInformation("Retrieving dependency ids and versions"); var dependencyErrorsAndInfos = new ErrorsAndInfos(); var dependencyIdsAndVersions = await PackageConfigsScanner.DependencyIdsAndVersionsAsync(projectFileFullName.Substring(0, projectFileFullName.LastIndexOf('\\')), true, true, dependencyErrorsAndInfos); SimpleLogger.LogInformation("Retrieving manually updated packages"); var secret = new SecretManuallyUpdatedPackages(); var manuallyUpdatedPackages = await SecretRepository.GetAsync(secret, errorsAndInfos); if (errorsAndInfos.AnyErrors()) { SimpleLogger.LogInformation("Returning false"); return(false); } foreach (var id in dependencyIdsAndVersions.Select(dependencyIdsAndVersion => dependencyIdsAndVersion.Key).Where(id => manuallyUpdatedPackages.All(p => p.Id != id))) { SimpleLogger.LogInformation($"Updating dependency {id}"); var projectFileFolder = new Folder(projectFileFullName.Substring(0, projectFileFullName.LastIndexOf('\\'))); ProcessRunner.RunProcess("dotnet", "remove " + projectFileFullName + " package " + id, projectFileFolder, errorsAndInfos); ProcessRunner.RunProcess("dotnet", "add " + projectFileFullName + " package " + id, projectFileFolder, errorsAndInfos); } SimpleLogger.LogInformation("Retrieving dependency ids and versions once more"); var dependencyIdsAndVersionsAfterUpdate = await PackageConfigsScanner.DependencyIdsAndVersionsAsync(projectFileFullName.Substring(0, projectFileFullName.LastIndexOf('\\')), true, true, dependencyErrorsAndInfos); SimpleLogger.LogInformation("Determining differences"); foreach (var dependencyIdsAndVersion in dependencyIdsAndVersionsAfterUpdate) { var id = dependencyIdsAndVersion.Key; var version = dependencyIdsAndVersion.Value; yesNo = yesNo || !dependencyIdsAndVersions.ContainsKey(id) || version != dependencyIdsAndVersions[id]; } SimpleLogger.LogInformation($"Returning {yesNo}"); return(yesNo); } }
public async Task <ControllableProcessTask> AwaitCompletionAsync(Guid taskId, int milliSecondsToAttemptWhileRequestedOrProcessing) { const int internalInMilliSeconds = 100; ControllableProcessTask task; using (_SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(AwaitCompletionAsync)))) { var methodNamesFromStack = _MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames(); _SimpleLogger.LogInformationWithCallStack($"Awaiting completion of task with id={taskId}", methodNamesFromStack); do { await Wait.UntilAsync(async() => { task = await GetControllableProcessTaskAsync(taskId); return(task?.Status == ControllableProcessTaskStatus.Completed); }, TimeSpan.FromMilliseconds(internalInMilliSeconds)); task = await GetControllableProcessTaskAsync(taskId); if (task != null) { if (task.Status == ControllableProcessTaskStatus.Completed) { _SimpleLogger.LogInformationWithCallStack($"Task with id={taskId} is complete", methodNamesFromStack); return(task); } var process = await GetControllableProcessAsync(task.ProcessId); if (process?.Status == ControllableProcessStatus.Dead) { _SimpleLogger.LogInformationWithCallStack($"Process with id={task.ProcessId} is dead for task with id={taskId}", methodNamesFromStack); return(task); } } milliSecondsToAttemptWhileRequestedOrProcessing -= internalInMilliSeconds; } while (0 < milliSecondsToAttemptWhileRequestedOrProcessing && (task == null || task.Status == ControllableProcessTaskStatus.Processing || task.Status == ControllableProcessTaskStatus.Requested)); _SimpleLogger.LogInformationWithCallStack($"Returning incomplete task with id={taskId}", methodNamesFromStack); return(task); } }
public async Task <HttpStatusCode> PutControllableProcessTaskAsync(ControllableProcessTask processTask) { using (_SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(PutControllableProcessTaskAsync)))) { var methodNamesFromStack = _MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames(); _SimpleLogger.LogInformationWithCallStack($"Put controllable process task with id={processTask.Id}", methodNamesFromStack); var context = new DefaultContainer(new Uri(BaseUrl)); ControllableProcessTask controllableProcessTask; if (await ProcessTaskExists(context, processTask.Id)) { _SimpleLogger.LogInformationWithCallStack($"Update controllable process task with id={processTask.Id}", methodNamesFromStack); controllableProcessTask = await context.ControllableProcessTasks.ByKey(processTask.Id).GetValueAsync(); controllableProcessTask.ProcessId = processTask.ProcessId; controllableProcessTask.Type = processTask.Type; controllableProcessTask.ControlName = processTask.ControlName; controllableProcessTask.Text = processTask.Text; controllableProcessTask.Status = processTask.Status; context.UpdateObject(controllableProcessTask); } else { _SimpleLogger.LogInformationWithCallStack($"Insert controllable process task with id={processTask.Id}", methodNamesFromStack); controllableProcessTask = new ControllableProcessTask { Id = processTask.Id, ProcessId = processTask.ProcessId, Type = processTask.Type, ControlName = processTask.ControlName, Text = processTask.Text, Status = processTask.Status }; context.AddToControllableProcessTasks(controllableProcessTask); } var response = await context.SaveChangesAsync(SaveChangesOptions.ReplaceOnUpdate); var statusCode = response.Select(r => (HttpStatusCode)r.StatusCode).FirstOrDefault(); return(statusCode); } }
public async Task <YesNoInconclusive> UpdateNugetPackagesInSolutionAsync(IFolder solutionFolder, IErrorsAndInfos errorsAndInfos) { using (SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(UpdateNugetPackagesInSolutionAsync), Guid.NewGuid().ToString()))) { SimpleLogger.LogInformation("Searching for project files"); var yesNoInconclusive = new YesNoInconclusive(); var projectFileFullNames = Directory.GetFiles(solutionFolder.FullName, "*.csproj", SearchOption.AllDirectories).ToList(); if (!projectFileFullNames.Any()) { SimpleLogger.LogInformation($"Returning {yesNoInconclusive}"); return(yesNoInconclusive); } foreach (var projectFileFullName in projectFileFullNames) { SimpleLogger.LogInformation($"Analyzing project file {projectFileFullName}"); yesNoInconclusive.YesNo = await UpdateNugetPackagesForProjectAsync(projectFileFullName, yesNoInconclusive.YesNo, errorsAndInfos); } SimpleLogger.LogInformation($"Returning {yesNoInconclusive}"); return(yesNoInconclusive); } }
protected override async Task ProcessSingleTaskAsync(ITashTaskHandlingStatus <ICacheckApplicationModel> status) { using (SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(TashAccessor), LogId))) { var s = string.IsNullOrEmpty(status.TaskBeingProcessed.ControlName) ? $"Processing a task of type {status.TaskBeingProcessed.Type} in {nameof(TashHandler)}" : $"Processing a task of type {status.TaskBeingProcessed.Type} on {status.TaskBeingProcessed.ControlName} in {nameof(TashHandler)}"; SimpleLogger.LogInformation(s); switch (status.TaskBeingProcessed.Type) { case ControllableProcessTaskType.Reset: await TashCommunicator.CommunicateAndShowCompletedOrFailedAsync(status, false, ""); break; default: await base.ProcessSingleTaskAsync(status); break; } } }
public async Task <HttpStatusCode> PutControllableProcessAsync(Process process) { using (_SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(PutControllableProcessAsync)))) { var methodNamesFromStack = _MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames(); _SimpleLogger.LogInformationWithCallStack($"Put controllable process with id={process.Id}", methodNamesFromStack); var context = new DefaultContainer(new Uri(BaseUrl)); ControllableProcess controllableProcess; if ((await ProcessExists(context, process.Id)).YesNo) { _SimpleLogger.LogInformationWithCallStack($"Update controllable process with id={process.Id}", methodNamesFromStack); controllableProcess = await context.ControllableProcesses.ByKey(process.Id).GetValueAsync(); controllableProcess.Title = process.ProcessName; controllableProcess.Status = ControllableProcessStatus.Idle; controllableProcess.ConfirmedAt = DateTimeOffset.Now; controllableProcess.LaunchCommand = process.MainModule?.FileName; context.UpdateObject(controllableProcess); } else { _SimpleLogger.LogInformationWithCallStack($"Insert controllable process with id={process.Id}", methodNamesFromStack); controllableProcess = new ControllableProcess { ProcessId = process.Id, Title = process.ProcessName, Status = ControllableProcessStatus.Idle, ConfirmedAt = DateTimeOffset.Now, LaunchCommand = process.MainModule?.FileName }; context.AddToControllableProcesses(controllableProcess); } var response = await context.SaveChangesAsync(SaveChangesOptions.ReplaceOnUpdate); var statusCode = response.Select(r => (HttpStatusCode)r.StatusCode).FirstOrDefault(); return(statusCode); } }
public async Task <ControllableProcessTask> GetControllableProcessTaskAsync(Guid taskId) { using (_SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(GetControllableProcessTaskAsync)))) { var methodNamesFromStack = _MethodNamesFromStackFramesExtractor.ExtractMethodNamesFromStackFrames(); if (_DetailedLogging) { _SimpleLogger.LogInformationWithCallStack($"Get controllable process task with id={taskId}", methodNamesFromStack); } var context = new DefaultContainer(new Uri(BaseUrl)); if (!await ProcessTaskExists(context, taskId)) { _SimpleLogger.LogInformationWithCallStack($"No controllable process task found with id={taskId}", methodNamesFromStack); return(null); } if (_DetailedLogging) { _SimpleLogger.LogInformationWithCallStack($"Returning controllable process task with id={taskId}", methodNamesFromStack); } var processTask = await context.ControllableProcessTasks.ByKey(taskId).GetValueAsync(); return(processTask); } }
public async Task ImLoggingWorkTooAsync() { using (SimpleLogger.BeginScope(SimpleLoggingScopeId.Create(nameof(ImLogging)))) { await WorkAsync(); } }