Exemple #1
0
    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);
        }
    }