public TransferTaskStatusChangedEventArgs(ITransferTaskToken token, TransferTaskStatusEnum oldStatus, TransferTaskStatusEnum newStatus) { if (!oldStatus.CanConvertedTo(newStatus)) { throw new InvalidOperationException($"{oldStatus} can not converted to {newStatus}"); } Token = token; OldStatus = oldStatus; NewStatus = newStatus; }
public static bool IsEndStatus(this TransferTaskStatusEnum self) => self == TransferTaskStatusEnum.Completed || self == TransferTaskStatusEnum.Canceled;
public static bool CanConvertedTo(this TransferTaskStatusEnum self, TransferTaskStatusEnum other) => !self.IsEndStatus() && // The end status cannot be converted. (other == TransferTaskStatusEnum.Canceled || // Any status can be Canceled except the end status. StatusChangeMapping[self].Contains(other));