Beispiel #1
0
    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);
        }
    }
Beispiel #2
0
 public async Task <HttpStatusCode> ConfirmStatusAsync(Guid taskId, ControllableProcessTaskStatus status)
 {
     return(await ConfirmStatusAsync(taskId, status, null, null));
 }