Esempio n. 1
0
        public Task FailOrRun <T, TOpMessage>(OperationTaskStatusEvent <T> message, Func <TOpMessage, Task> completedFunc)
            where T : OperationTaskCommand
            where TOpMessage : class
        {
            if (message.OperationFailed)
            {
                return(Fail(message.GetMessage()));
            }

            return(completedFunc(message.GetMessage() as TOpMessage));
        }
Esempio n. 2
0
        public Task FailOrRun <T>(OperationTaskStatusEvent <T> message, Func <Task> completedFunc) where T : OperationTaskCommand
        {
            if (message.OperationFailed)
            {
                return(Fail(message.GetMessage()));
            }

            return(completedFunc());
        }
Esempio n. 3
0
        public async Task Handle(OperationTaskStatusEvent message)
        {
            var op = await _dbContext.Operations.FindAsync(message.OperationId).ConfigureAwait(false);

            var task = await _dbContext.OperationTasks.FindAsync(message.TaskId).ConfigureAwait(false);

            if (op == null || task == null)
            {
                return;
            }

            if (task.Status == OperationTaskStatus.Queued || task.Status == OperationTaskStatus.Running)
            {
                var taskCommandTypeName = Data.Tasks[message.TaskId];

                var genericType        = typeof(OperationTaskStatusEvent <>);
                var wrappedCommandType = genericType.MakeGenericType(Type.GetType(taskCommandTypeName));
                var commandInstance    = Activator.CreateInstance(wrappedCommandType, message);
                await _bus.SendLocal(commandInstance);
            }

            task.Status = message.OperationFailed ? OperationTaskStatus.Failed : OperationTaskStatus.Completed;

            if (message.TaskId == Data.PrimaryTaskId)
            {
                op.Status = message.OperationFailed ? OperationStatus.Failed : OperationStatus.Completed;
                string errorMessage = null;
                if (message.GetMessage() is ErrorData errorData)
                {
                    errorMessage = errorData.ErrorMessage;
                }

                op.StatusMessage = string.IsNullOrWhiteSpace(errorMessage) ? op.Status.ToString() : errorMessage;
                MarkAsComplete();
            }


            await _dbContext.SaveChangesAsync();
        }