Пример #1
0
        public Task Send(OperationTaskCommand message)
        {
            var commandJson = JsonConvert.SerializeObject(message);

            return(_bus.SendLocal(
                       new CreateNewOperationTaskCommand(
                           message.GetType().AssemblyQualifiedName,
                           commandJson, message.OperationId,
                           message.TaskId)));
        }
Пример #2
0
        public async Task <Operation> StartNew(OperationTaskCommand taskCommand, Guid vmId)
        {
            if (taskCommand == null)
            {
                throw new ArgumentNullException(nameof(taskCommand));
            }

            var operation = new Operation
            {
                Id          = Guid.NewGuid(),
                Status      = OperationStatus.Queued,
                MachineGuid = vmId
            };

            _db.Add(operation);

            await _db.SaveChangesAsync().ConfigureAwait(false);

            if (vmId != Guid.Empty && (taskCommand is IMachineCommand machineCommand) &&
                machineCommand.MachineId != vmId)
            {
                machineCommand.MachineId = vmId;
            }


            taskCommand.OperationId = operation.Id;
            taskCommand.TaskId      = Guid.NewGuid();
            var commandJson = JsonConvert.SerializeObject(taskCommand);

            await _bus.Send(
                new CreateOperationCommand {
                TaskMessage = new CreateNewOperationTaskCommand(
                    taskCommand.GetType().AssemblyQualifiedName,
                    commandJson, operation.Id,
                    taskCommand.TaskId)
            })
            .ConfigureAwait(false);

            return(operation);
        }
Пример #3
0
 public Task <Operation> StartNew(OperationTaskCommand operationCommand)
 {
     return(StartNew(operationCommand, Guid.Empty));
 }