private static void CacheItem_Remove(string postBackID, object val, CacheItemRemovedReason reason) { UploadStateStoreProvider.CleanUpIfStaleCallback cleanUpIfStaleCallback = (UploadStateStoreProvider.CleanUpIfStaleCallback)val; if (reason == CacheItemRemovedReason.Removed) { return; } cleanUpIfStaleCallback(postBackID); }
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.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); }