/// <summary> /// Returns an <see cref="UploadState"/> for a given post-back ID. /// or null if none exists. /// </summary> /// <param name="postBackID"> /// A post-back ID identifying the <see cref="UploadState"/>. /// </param> /// <returns> /// The <see cref="IUploadState"/> corresponding to /// <paramref name="postBackID"/>, or null if none-exists. /// </returns> public static UploadState OpenReadWrite(string postBackID) { UploadState uploadState = Provider.Load(postBackID); if (uploadState != null) { if (uploadState.DeleteAfterDelayWhenNotOpenReadWrite) { CancelDeleteAfterDelay(uploadState.PostBackID); } UploadState uploadStateCopy = new UploadState(); uploadStateCopy.CopyFrom(uploadState); uploadStateCopy.IsWritable = true; uploadStateCopy.DeleteAfterDelayWhenNotOpenReadWrite = uploadState.DeleteAfterDelayWhenNotOpenReadWrite; uploadStateCopy.OnMerged(); uploadStateCopy.Changed += new EventHandler(UploadState_Changed); uploadState = uploadStateCopy; } return(uploadState); }
public static void Merge(UploadState uploadState, UploadState storedUploadState) { if (uploadState == storedUploadState) return; if (storedUploadState != null) { UploadState uploadStateAtLastMerge = uploadState.UploadStateAtLastMerge; if (uploadStateAtLastMerge == null) uploadStateAtLastMerge = new UploadState(uploadState.PostBackID); uploadState.IsMerging = true; uploadState.BytesRead = storedUploadState.BytesRead + (uploadState.BytesRead - uploadStateAtLastMerge.BytesRead); uploadState.BytesTotal = storedUploadState.BytesTotal + (uploadState.BytesTotal - uploadStateAtLastMerge.BytesTotal); uploadState.FileBytesRead = storedUploadState.FileBytesRead + (uploadState.FileBytesRead - uploadStateAtLastMerge.FileBytesRead); if (uploadState.Failure == null) uploadState.Failure = storedUploadState.Failure; if (uploadState.Rejection == null) uploadState.Rejection = storedUploadState.Rejection; if (uploadState.Files.Count < storedUploadState.Files.Count) { uploadState._Files = storedUploadState._Files; } if (uploadState.MultiRequestObject == null) uploadState.MultiRequestObject = storedUploadState.MultiRequestObject; if (uploadState.ProcessingStateDict == null || uploadState.ProcessingStateDict.Count == 0) uploadState._ProcessingStateDict = storedUploadState._ProcessingStateDict; if (uploadState.Status < storedUploadState.Status) uploadState.Status = storedUploadState.Status; } uploadState.OnMerged(); uploadState.IsMerging = false; }
/// <summary> /// Merges two <see cref="UploadState"/> objects. /// </summary> /// <param name="uploadState"> /// The "local" <see cref="UploadState"/> object to merge, and the object that should contain the result /// of the merge. /// </param> /// <param name="storedUploadState"> /// The stored <see cref="UploadState"/> object to merge, which will be left unchanged. /// </param> public static void Merge(UploadState uploadState, UploadState storedUploadState) { if (uploadState == storedUploadState) { uploadState.IsMerging = true; uploadState.OnMerged(); uploadState.IsMerging = false; return; } if (storedUploadState != null) { UploadState uploadStateAtLastMerge = uploadState.UploadStateAtLastMerge; if (uploadStateAtLastMerge == null) { uploadStateAtLastMerge = new UploadState(uploadState.PostBackID); } uploadState.IsMerging = true; if (uploadState.Status < storedUploadState.Status) { uploadState.Status = storedUploadState.Status; } if (uploadState.BytesRead - uploadStateAtLastMerge.BytesRead + storedUploadState.BytesRead > uploadState.BytesTotal) { if (log.IsDebugEnabled) { log.Debug("Too many bytes read"); } } uploadState.BytesRead = storedUploadState.BytesRead + (uploadState.BytesRead - uploadStateAtLastMerge.BytesRead); uploadState.BytesTotal = storedUploadState.BytesTotal + (uploadState.BytesTotal - uploadStateAtLastMerge.BytesTotal); uploadState.FileBytesRead = storedUploadState.FileBytesRead + (uploadState.FileBytesRead - uploadStateAtLastMerge.FileBytesRead); if (uploadState.Failure == null) { uploadState.Failure = storedUploadState.Failure; } if (uploadState.Rejection == null) { uploadState.Rejection = storedUploadState.Rejection; } if (uploadState.Files.Count < storedUploadState.Files.Count) { uploadState._Files = storedUploadState._Files; } if (uploadState.MultiRequestObject == null) { uploadState.MultiRequestObject = storedUploadState.MultiRequestObject; } if (!uploadState.IsMultiRequest && storedUploadState.IsMultiRequest) { uploadState.IsMultiRequest = storedUploadState.IsMultiRequest; } if (uploadState.ProcessingStateDict == null || uploadState.ProcessingStateDict.Count == 0) { uploadState._ProcessingStateDict = storedUploadState._ProcessingStateDict; } } uploadState.OnMerged(); uploadState.IsMerging = false; }