public Task Handle(AcceptedOperation <ConvergeVirtualMachineCommand> message) { var command = message.Command; var config = command.Config; _operationId = command.OperationId; var chain = from normalizedVMConfig in Converge.NormalizeMachineConfig(config, _engine, ProgressMessage) from vmList in GetVmInfo(normalizedVMConfig.Id, _engine) from optionalVmInfo in EnsureUnique(vmList, normalizedVMConfig.Id) from storageSettings in DetectStorageSettings(optionalVmInfo) from vmConfig in ApplyStorageSettings(normalizedVMConfig, storageSettings, GetHostSettings()) from vmInfoCreated in EnsureCreated(optionalVmInfo, vmConfig, storageSettings, _engine) from vmInfo in EnsureNameConsistent(vmInfoCreated, vmConfig, _engine) from _ in AttachToOperation(vmInfo, _bus, command.OperationId) from vmInfoConverged in ConvergeVm(vmInfo, vmConfig, storageSettings, _engine) select vmInfoConverged; return(chain.ToAsync().MatchAsync( LeftAsync: HandleError, RightAsync: vmInfo2 => _bus.Send(new OperationCompletedEvent { OperationId = command.OperationId, }).ToUnit())); }
public async Task Handle(AcceptedOperation <T> message) { var command = message.Command; var result = await GetVmInfo(command.MachineId, _engine) .BindAsync(optVmInfo => { return(optVmInfo.MatchAsync( Some: s => HandleCommand(s, command, _engine), None: () => new TypedPsObject <VirtualMachineInfo>(new PSObject(new { Id = message.Command.MachineId })))); }).ConfigureAwait(false); await result.MatchAsync( LeftAsync : f => HandleError(f, command), RightAsync : async vmInfo => { await _bus.Send(new OperationCompletedEvent { OperationId = command.OperationId, }).ConfigureAwait(false); return(Unit.Default); }).ConfigureAwait(false); }