Ejemplo n.º 1
0
        private void context_Error(object sender, EventArgs e)
        {
            HttpApplication application = sender as HttpApplication;
            bool            flag        = this.IsUploadRequest(application.Request);

            if (flag)
            {
                UploadStatus uploadStatus = HttpUploadModule.GetUploadStatus(application.Context);
                this.ClearUploadStatus(uploadStatus);
                uploadStatus.SetState(UploadState.Terminated, UploadTerminationReason.Error, application.Context.AllErrors, application.Context.AllErrors[0].Message);
            }
        }
Ejemplo n.º 2
0
        public static ReadOnlyCollection <UploadedFile> GetUploadedFiles()
        {
            UploadStatus uploadStatus = HttpUploadModule.GetUploadStatus();
            bool         flag         = uploadStatus != null;
            ReadOnlyCollection <UploadedFile> result;

            if (flag)
            {
                result = uploadStatus.GetUploadedFiles();
            }
            else
            {
                result = null;
            }
            return(result);
        }
Ejemplo n.º 3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/xml";
            context.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            context.Response.Cache.SetNoStore();
            context.Response.Cache.SetNoServerCaching();
            context.Response.Cache.SetExpires(DateTime.Now);
            string uploadId = context.Request.QueryString["UploadId"];

            using (XmlTextWriter writer = new XmlTextWriter(context.Response.OutputStream, context.Response.ContentEncoding))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("uploadStatus");
                UploadStatus uploadStatus = HttpUploadModule.GetUploadStatus(uploadId);
                bool         flag         = uploadStatus != null;
                if (flag)
                {
                    float num = (float)uploadStatus.Position / (float)uploadStatus.ContentLength;
                    writer.WriteAttributeString("state", uploadStatus.State.ToString());
                    writer.WriteAttributeString("reason", uploadStatus.Reason.ToString());
                    bool flag2 = !string.IsNullOrEmpty(uploadStatus.ErrorMessage);
                    if (flag2)
                    {
                        writer.WriteAttributeString("errorMessage", uploadStatus.ErrorMessage);
                    }
                    writer.WriteAttributeString("percentComplete", (num * 100f).ToString("##0.00", CultureInfo.InvariantCulture));
                    writer.WriteAttributeString("contentLengthText", this.SwitchContentlength(uploadStatus.ContentLength));
                    writer.WriteAttributeString("transferredLengthText", this.SwitchContentlength(uploadStatus.ContentLength - (uploadStatus.ContentLength - uploadStatus.Position)));
                    writer.WriteAttributeString("remainingLengthText", this.SwitchContentlength(uploadStatus.ContentLength - uploadStatus.Position));
                    writer.WriteAttributeString("currentFile", uploadStatus.CurrentFileName);
                    writer.WriteAttributeString("currentFileIndex", uploadStatus.UploadedFiles.Count.ToString());
                    TimeSpan span = DateTime.Now.Subtract(uploadStatus.Start);
                    writer.WriteAttributeString("timeElapsedText", this.SwitchTimeSpan(span));
                    bool flag3 = uploadStatus.Position > 0L;
                    if (flag3)
                    {
                        double   num2  = (double)span.Ticks / (double)uploadStatus.Position;
                        double   num3  = (double)(uploadStatus.ContentLength - uploadStatus.Position) * num2;
                        TimeSpan span2 = new TimeSpan((long)num3);
                        writer.WriteAttributeString("timeRemainingText", this.SwitchTimeSpan(span2));
                    }
                    else
                    {
                        writer.WriteAttributeString("timeRemainingText", "[calculating]");
                    }
                    double num4  = (double)uploadStatus.Position / span.TotalSeconds;
                    bool   flag4 = num >= 1f;
                    if (flag4)
                    {
                        writer.WriteAttributeString("speedText", "正在处理,请稍等...");
                    }
                    else
                    {
                        writer.WriteAttributeString("speedText", this.SwitchContentlength((long)num4) + "/sec");
                    }
                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
        }
Ejemplo n.º 4
0
 public static UploadStatus GetUploadStatus()
 {
     return(HttpUploadModule.GetUploadStatus(HttpContext.Current));
 }