public override void MergeAndSave(UploadState uploadState) { HttpContext ctx = HttpContext.Current; string key = KeyPrefix + uploadState.PostBackID; UploadState storedUploadState = Load(uploadState.PostBackID); Merge(uploadState, storedUploadState); ctx.Session[key] = 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> /// Returns an <see cref="IUploadState"/> for a given post-back ID. /// or creates one if none exists. /// </summary> /// <param name="postBackID"> /// A post-back ID identifying the <see cref="IUploadState"/>. /// </param> /// <returns> /// The <see cref="IUploadState"/> corresponding to /// <paramref name="postBackID"/> /// </returns> public static UploadState OpenReadWriteOrCreate(string postBackID) { UploadState uploadState = OpenReadWrite(postBackID); if (uploadState != null && !uploadState.IsMultiRequest && HttpContext.Current != null && HttpContext.Current.Items["NeatUpload_CalledOpenReadWriteOrCreate"] == null) { // This is not a multi-request upload and this is the first time // we've been called during this request, so the uploadState we // found must be from a previous postback with the same postback ID. // That can happen if the user has scripting disabled and the current // postback is from a cached page. So, we need to delete the old // upload state and pretend we didn't get it. // Make it stale and save it so it can be cleaned up uploadState.TimeOfLastMerge = DateTime.MinValue; MergeAndSave(uploadState); // Clean it up UploadStateStoreProvider.CleanUpIfStaleCallback cleanUpIfStaleCallback = Provider.GetCleanUpIfStaleCallback(); cleanUpIfStaleCallback(postBackID); // Pretend we didn't get it uploadState = null; // Don't do the above again during this request. HttpContext.Current.Items["NeatUpload_CalledOpenReadWriteOrCreate"] = true; } if (uploadState == null) { uploadState = new UploadState(postBackID); uploadState.Changed += new EventHandler(UploadState_Changed); uploadState.DeleteAfterDelayWhenNotOpenReadWrite = true; } uploadState.IsWritable = true; return(uploadState); }
protected virtual void ProcessMultiRequestUploadRequest(HttpContext context, UploadState uploadState) { string controlID = context.Request.QueryString[MultiRequestUploadModule.ControlIDQueryParam]; if (log.IsDebugEnabled) log.DebugFormat("controlID={0}", controlID); string postBackID = context.Request.QueryString[UploadModule.PostBackIDQueryParam]; if (log.IsDebugEnabled) log.DebugFormat("postBackID={0}", postBackID); string secureStorageConfigString = context.Request.Form[UploadModule.ConfigFieldNamePrefix + controlID]; if (log.IsDebugEnabled) log.DebugFormat("secureStorageConfigString={0}", secureStorageConfigString); string fileSizesString = context.Request.Form[MultiRequestUploadModule.FileSizesFieldName]; if (log.IsDebugEnabled) log.DebugFormat("fileSizesString={0}", fileSizesString); if (postBackID != null && fileSizesString != null && fileSizesString.Length > 0) { string[] fileSizeStrings = fileSizesString.Split(' '); long totalSize = 0; for (int i = 0; i < fileSizeStrings.Length; i++) { totalSize += Int64.Parse(fileSizeStrings[i]); } uploadState.MultiRequestObject = secureStorageConfigString; uploadState.BytesTotal = totalSize; } }
/// <summary> /// Copies the upload state stored in the <paramref name="source"/> /// <see cref="UploadState"/> object into this object. /// </summary> /// <param name="source">the <see cref="UploadState"/> object to copy /// the state from.</param> public void CopyFrom(object source) { UploadState src = (UploadState)source; this._BytesPerSec = src._BytesPerSec; this._BytesRead = src._BytesRead; this._BytesTotal = src._BytesTotal; this._Failure = src._Failure; this._FileBytesRead = src._FileBytesRead; this._Files = src._Files; if (this._Files != null) { this._Files.UploadState = this; } this._MultiRequestObject = src._MultiRequestObject; this._IsMultiRequest = src._IsMultiRequest; this._PostBackID = src._PostBackID; this._CurrentFileName = src._CurrentFileName; this._ProcessingStateDict = src._ProcessingStateDict; this._Rejection = src._Rejection; this._Status = src._Status; this.BytesReadAtLastMark = src.BytesReadAtLastMark; this.IsMerging = src.IsMerging; this.TimeOfFirstByte = src.TimeOfFirstByte; this.TimeOfFinalByte = src.TimeOfFinalByte; this.TimeOfLastMark = src.TimeOfLastMark; this.TimeOfLastMerge = src.TimeOfLastMerge; if (src.UploadStateAtLastMerge == null) { this.UploadStateAtLastMerge = null; } else { this.UploadStateAtLastMerge = (UploadState)src.UploadStateAtLastMerge.MemberwiseClone(); } }
protected virtual void ProcessMultiRequestUploadRequest(HttpContext context, UploadState uploadState) { string controlID = context.Request.QueryString[MultiRequestUploadModule.ControlIDQueryParam]; if (log.IsDebugEnabled) log.DebugFormat("controlID={0}", controlID); string postBackID = context.Request.QueryString[UploadModule.PostBackIDQueryParam]; if (log.IsDebugEnabled) log.DebugFormat("postBackID={0}", postBackID); string secureStorageConfigString = context.Request.Form[UploadModule.ConfigFieldNamePrefix + controlID]; if (log.IsDebugEnabled) log.DebugFormat("secureStorageConfigString={0}", secureStorageConfigString); string fileSizesString = context.Request.Form[MultiRequestUploadModule.FileSizesFieldName]; if (log.IsDebugEnabled) log.DebugFormat("fileSizesString={0}", fileSizesString); context.Response.Clear(); if (postBackID != null && fileSizesString != null && fileSizesString.Length > 0) { string[] fileSizeStrings = fileSizesString.Split(' '); long totalSize = 0; for (int i = 0; i < fileSizeStrings.Length; i++) { long size = Int64.Parse(fileSizeStrings[i]); // fileSizesString contains a -1 for each non-Flash upload // associated with the request. Ignore those so that the // totalSize is not off by one. if (size > 0) totalSize += size; } uploadState.IsMultiRequest = true; uploadState.MultiRequestObject = secureStorageConfigString; uploadState.BytesTotal = totalSize; context.Response.Write(String.Format(@"{{ ""ArmoredCookies"" : ""{0}"" }}", MultiRequestUploadModule.GetArmoredCookies())); } // MacOSX Flash player won't fire FileReference.onComplete unless something is returned. context.Response.Write(" "); context.Response.End(); }
/// <summary> /// Merges a particular <see cref="UploadState"/> with the stored <see cref="UploadState"/> and store /// the merged <see cref="UploadState"/>. /// </summary> /// <param name="uploadState"> /// The <see cref="UploadState"/> to be merged. /// </param> /// <remarks>When this method returns, <paramref name="uploadState"/> and the stored <see cref="UploadState"/> /// will be equivalent (though not necessarily identical) and either may have changed as a result /// of the merge.</remarks> public override void MergeAndSave(UploadState uploadState) { Provider.MergeAndSave(uploadState); }
public override void MergeAndSave(UploadState uploadState) { Provider.MergeAndSave(uploadState); }
public override void MergeAndSave(UploadState uploadState) { if (IsSessionWritable) { base.MergeAndSave(uploadState); return; } MakeRemoteCall("MergeAndSave", uploadState); }
/// <summary> /// Returns true if the specified <see cref="UploadState"/> is considered stale. /// </summary> /// <param name="uploadState"> /// The <see cref="UploadState"/> to check for staleness /// </param> /// <returns> /// true if <paramref name="uploadState"/> is stale. /// </returns> /// <remarks>The <see cref="UploadState"/> is considered stale if it has not been updated in the /// number of seconds indicated by the stateStaleAfterSeconds attribute of the <neatUpload> /// element or it has been forced stale.</remarks> protected bool IsStale(UploadState uploadState) { return(uploadState.TimeOfLastMerge.AddSeconds(Config.Current.StateStaleAfterSeconds) < DateTime.Now); }
/// <summary> /// Called to indicate that no additional calls will be made to members /// of the uploadState object during this request. If the implementation /// is supposed to share the information in the object across servers, it /// might need to take some action to ensure that final changes are /// propagated to other servers. /// </summary> public static void Close(UploadState uploadState) { if (uploadState.IsWritable) MergeAndSave(uploadState); if (uploadState.DeleteAfterDelayWhenNotOpenReadWrite) DeleteAfterDelay(uploadState); }
public override void MergeAndSave(UploadState uploadState) { string key = KeyPrefix + uploadState.PostBackID; Application.Lock(); try { UploadState storedUploadState = Load(uploadState.PostBackID); Merge(uploadState, storedUploadState); Application[key] = uploadState; } finally { Application.UnLock(); } }
private static void MergeAndSave(UploadState uploadState) { Provider.MergeAndSave(uploadState); }
private static void DeleteAfterDelay(UploadState uploadState) { HttpContext ctx = HttpContext.Current; UploadStateStoreProvider.CleanUpIfStaleCallback cleanUpIfStaleCallback = Provider.GetCleanUpIfStaleCallback(); ctx.Cache.Insert(uploadState.PostBackID, cleanUpIfStaleCallback, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(Config.Current.StateStaleAfterSeconds), CacheItemPriority.High, new CacheItemRemovedCallback(CacheItem_Remove)); }
/// <summary> /// Returns an <see cref="IUploadState"/> for a given post-back ID. /// or creates one if none exists. /// </summary> /// <param name="postBackID"> /// A post-back ID identifying the <see cref="IUploadState"/>. /// </param> /// <returns> /// The <see cref="IUploadState"/> corresponding to /// <paramref name="postBackID"/> /// </returns> public static UploadState OpenReadWriteOrCreate(string postBackID) { UploadState uploadState = OpenReadWrite(postBackID); if (uploadState == null) { uploadState = new UploadState(postBackID); uploadState.Changed += new EventHandler(UploadState_Changed); uploadState.DeleteAfterDelayWhenNotOpenReadWrite = true; } uploadState.IsWritable = true; return uploadState; }
/// <summary> /// Returns an <see cref="IUploadState"/> for a given post-back ID /// </summary> /// <param name="postBackID"> /// A post-back ID identifying the <see cref="IUploadState"/>. /// </param> /// <returns> /// The <see cref="IUploadState"/> corresponding to /// <paramref name="postBackID"/> /// </returns> public static UploadState OpenReadOnly(string postBackID) { UploadState uploadState = Provider.Load(postBackID); if (uploadState == null) return null; UploadState uploadStateCopy = new UploadState(); uploadStateCopy.CopyFrom(uploadState); uploadStateCopy.IsWritable = false; return uploadStateCopy; }
public void CopyFrom(object source) { UploadState src = (UploadState)source; this._BytesPerSec = src._BytesPerSec; this._BytesRead = src._BytesRead; this._BytesTotal = src._BytesTotal; this._Failure = src._Failure; this._FileBytesRead = src._FileBytesRead; this._Files = src._Files; this._MultiRequestObject = src._MultiRequestObject; this._PostBackID = src._PostBackID; this._ProcessingStateDict = src._ProcessingStateDict; this._Rejection = src._Rejection; this._Status = src._Status; this.BytesReadAtLastMark = src.BytesReadAtLastMark; this.IsMerging = src.IsMerging; this.TimeOfFirstByte = src.TimeOfFirstByte; this.TimeOfLastMark = src.TimeOfLastMark; this.TimeOfLastMerge = src.TimeOfLastMerge; this.UploadStateAtLastMerge = src.UploadStateAtLastMerge; }
public abstract void MergeAndSave(UploadState uploadState);
/// <summary> /// Merges a particular <see cref="UploadState"/> with the stored <see cref="UploadState"/> and store /// the merged <see cref="UploadState"/>. /// </summary> /// <param name="uploadState"> /// The <see cref="UploadState"/> to be merged. /// </param> /// <remarks>When this method returns, <paramref name="uploadState"/> and the stored <see cref="UploadState"/> /// will be equivalent (though not necessarily identical) and either may have changed as a result /// of the merge.</remarks> public abstract void MergeAndSave(UploadState uploadState);
protected bool IsStale(UploadState uploadState) { return (uploadState.TimeOfLastMerge.AddSeconds(Config.Current.StateStaleAfterSeconds) > DateTime.Now); }
internal void OnMerged() { UploadStateAtLastMerge = (UploadState)MemberwiseClone(); UploadStateAtLastMerge.UploadStateAtLastMerge = null; }
/// <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; }