private void OnPackageArrived(TcpTypedConnection <byte[]> connection, TcpPackage package) { var corrId = package.CorrelationId; WorkerItem workItem; if (!_items.TryGetValue(corrId, out workItem)) { _coordinator.SignalWorkerFailed(null, string.Format( "Worker {0} received unexpected CorrId: {1}, no item with such CorrId is in progress.", _name, corrId)); return; } var result = workItem.Task.CheckStepExpectations(package); switch (result.Status) { case Status.MeetsExpectations: if (TryRemoveWorkItem(workItem)) { NotifyItemProcessed(workItem); } break; case Status.Retry: Retry(workItem); break; case Status.CheckStreamDeleted: if (_coordinator.IsDeleted(result.Description) && TryRemoveWorkItem(workItem)) { NotifyItemProcessed(workItem); } else { Retry(workItem); _coordinator.SignalPossibleFailure( string.Format( "Got stream deleted ({0}), but it's not confirmed. Retrying ({1})", result.Description, workItem.Attempt)); } break; case Status.Ignore: break; case Status.FailFast: _coordinator.SignalWorkerFailed(null, result.Description); TryRemoveWorkItem(workItem); break; default: throw new ArgumentOutOfRangeException(); } }