public IEnumerable <ICommand> HandleCommand(Lazy <ImmutableList <ICommand> > previousCommands, ICommand cmd) { var lockRes = UploadJobWorker.LockCommandHandler(previousCommands, cmd).ToList(); if (lockRes.Any()) { foreach (LockStateChangedCommand lockCmd in lockRes.OfType <LockStateChangedCommand>()) { _locked = lockCmd.Locked; // _output.WriteLine($"Locked {lockCmd.Locked}"); } return(lockRes); } // _output.WriteLine($"Got cmd: {cmd.GetType().FullName}"); var res = new List <ICommand>(); if (cmd is DataTransferDownloadRequestCommand startCmd) { Assert.Equal(_bank != 0xffff, _locked); Assert.False(_isComplete); Assert.Equal(_index, startCmd.TransferIndex); Assert.Equal(_bank, startCmd.TransferStoreId); _transferId = startCmd.TransferId; _pendingAck = 0; res.AddRange(SendData()); } else if (cmd is DataTransferAckCommand ackCmd) { // Assert.False(_isComplete); if (_offset >= _bytes.Length) { res.Add(new DataTransferCompleteCommand { TransferId = _transferId }); _isComplete = true; } else { res.AddRange(SendData()); } } return(res); }
public IEnumerable <ICommand> HandleCommand(Lazy <ImmutableList <ICommand> > previousCommands, ICommand cmd) { var lockRes = UploadJobWorker.LockCommandHandler(previousCommands, cmd).ToList(); if (lockRes.Any()) { return(lockRes); } // _output.WriteLine($"Got cmd: {cmd.GetType().FullName}"); var res = new List <ICommand>(); if (cmd is DataTransferUploadRequestCommand startCmd) { Assert.False(_isAborted); _transferId = startCmd.TransferId; res.Add(new DataTransferUploadContinueCommand { TransferId = startCmd.TransferId, ChunkCount = _chunkCount, ChunkSize = _chunkSize }); } else if (cmd is DataTransferFileDescriptionCommand descCmd) { res.Add(null); } else if (cmd is DataTransferDataCommand dataCmd) { res.Add(null); } else if (cmd is DataTransferAbortCommand abortCmd) { Assert.Equal(_transferId, abortCmd.TransferId); _isAborted = true; res.Add(null); } return(res); }