void IUploadModule.BindProgressState(string postBackID, string controlUniqueID, IUploadProgressState progressState) { UploadState uploadState = UploadStateStore.OpenReadOnly(postBackID); if (uploadState == null) { progressState.Status = UploadStatus.Unknown; return; } progressState.Status = uploadState.Status; if (uploadState.Status == UploadStatus.Unknown) { return; } progressState.BytesRead = uploadState.BytesRead; progressState.BytesTotal = uploadState.BytesTotal; progressState.BytesPerSec = uploadState.BytesPerSec; progressState.FileBytesRead = uploadState.FileBytesRead; progressState.FractionComplete = (uploadState.BytesTotal <= 0 || uploadState.FileBytesRead <= 0) ? 0 : ((double)uploadState.BytesRead / uploadState.BytesTotal); progressState.CurrentFileName = uploadState.CurrentFileName; progressState.Files = uploadState.Files.GetReadOnlyCopy(); progressState.Failure = uploadState.Failure; progressState.Rejection = uploadState.Rejection; if (controlUniqueID != null) { progressState.ProcessingState = uploadState.ProcessingStateDict[controlUniqueID]; } progressState.TimeElapsed = uploadState.TimeElapsed; if (uploadState.BytesRead == 0 || uploadState.BytesTotal < 0) { // If the upload is in progress but we haven't received any bytes yet, // pretend that the upload hasn't started yet because there is no way // to estimate TimeRemaining. This situation occurs during a Flash-upload // or other upload where the postBackID is passed in the query string. // Note that we don't want to lie about the upload status if the status is // something other than NormalInProgress. For example, if the status is // Rejected then pretending the upload hasn't started would hide the rejection // message. if (uploadState.Status == UploadStatus.NormalInProgress) { progressState.Status = UploadStatus.Unknown; } progressState.TimeRemaining = TimeSpan.MaxValue; } else { double bytesRemaining = ((double)(uploadState.BytesTotal - uploadState.BytesRead)); double ticksRemaining = bytesRemaining * uploadState.TimeElapsed.Ticks; progressState.TimeRemaining = new TimeSpan((long)(ticksRemaining / uploadState.BytesRead)); } UploadStateStore.Close(uploadState); }
void IUploadModule.CancelPostBack(string postBackID) { UploadState uploadState = UploadStateStore.OpenReadWrite(postBackID); if (uploadState.Status == UploadStatus.Unknown) { return; } uploadState.Status = UploadStatus.Cancelled; UploadStateStore.Close(uploadState); }
private void Application_EndRequest(object sender, EventArgs e) { if (!IsInited) { return; } if (log.IsDebugEnabled) { log.Debug("In Application_EndRequest"); } if (!Config.Current.UseHttpModule) { return; } HttpApplication app = sender as HttpApplication; if (RememberErrorHandler != null) { app.Error -= RememberErrorHandler; } HttpContext ctx = HttpContext.Current; // Get the list of files to dispose to the current context if one hasn't been added yet ArrayList filesToDispose = ctx.Items["NeatUpload_FilesToDispose"] as ArrayList; if (filesToDispose != null) { foreach (UploadedFile file in filesToDispose) { file.Dispose(); } } // Get CurrentUploadState only if it has already been set to // avoid deadlocks. UploadState uploadState = null; if (HttpContext.Current != null) { uploadState = (UploadState)HttpContext.Current.Items["NeatUpload_UploadState"]; } if (uploadState != null) { if (CurrentMultiRequestControlID == null && uploadState.Status != UploadStatus.Failed && uploadState.Status != UploadStatus.Rejected) { uploadState.Status = UploadStatus.Completed; } UploadStateStore.Close(CurrentUploadState); CurrentUploadState = null; } }