Example #1
0
        private void Control_PreRender(object sender, EventArgs args)
        {
            if (IsDesignTime)
            {
                return;
            }

            // Find the current upload context
            string postBackID = Page.Request.Params["postBackID"];
            string barID      = Page.Request.Params["barID"];

            // Set the status to Cancelled if requested.
            if (Page.Request.Params["cancelled"] == "true")
            {
                UploadModule.CancelPostBack(postBackID);
            }

            IUploadProgressState progressState = new UploadProgressState();

            UploadModule.BindProgressState(postBackID, barID, progressState);

            if (progressState.Status == UploadStatus.Unknown)
            {
                // Status is unknown, so try to find the last post back based on the lastPostBackID param.
                // If successful, use the status of the last post back.
                string lastPostBackID = Page.Request.Params["lastPostBackID"];
                if (lastPostBackID != null && lastPostBackID.Length > 0 && Page.Request.Params["refresher"] == null)
                {
                    UploadModule.BindProgressState(lastPostBackID, barID, progressState);
                    if (progressState.FileBytesRead == 0 &&
                        progressState.ProcessingState == null)
                    {
                        progressState.Status = UploadStatus.Unknown;
                    }
                }
            }

            Status = progressState.Status;
            ProgressInfo progress = null;

            progress = (ProgressInfo)progressState.ProcessingState;
            if (progress != null && Status == UploadStatus.Completed)
            {
                Status = UploadStatus.ProcessingCompleted;
            }

            Attributes["status"] = Status.ToString();

            if (WhenStatus != null)
            {
                string[] matchingStatuses = WhenStatus.Split(' ');
                if (Array.IndexOf(matchingStatuses, Status.ToString()) == -1)
                {
                    this.Visible = false;
                }
            }
        }
Example #2
0
        private void DoProcessing()
        {
            ProgressInfo progress = inlineProgressBar.ProcessingProgress = new ProgressInfo(5000, "Units");

            for (int i = 1; i <= 5000; i++)
            {
                System.Threading.Thread.Sleep(1);
                progress.Value = i;
            }
            progress.Text = "Processing Complete";
        }
Example #3
0
        private void SetupBindableProps()
        {
            ProcessingHtml = GetResourceString("ProcessingMessage");
            if (ProcessingState != null)
            {
                ProgressInfo progress = (ProgressInfo)ProcessingState;
                FractionComplete = 1.0 * progress.Value / progress.Maximum;
                ProcessingHtml   = progress.ToHtml();
            }

            CanScript           = (Request.Params["canScript"] != null && Boolean.Parse(Request.Params["canScript"]));
            CanCancel           = (Request.Params["canCancel"] != null && Boolean.Parse(Request.Params["canCancel"]));
            IsRefreshing        = (Request.Params["refresh"] != "false" && Request.Params["refresher"] != null);
            StartRefreshVisible = (!CanScript && !IsRefreshing &&
                                   (CurrentStatus == UploadStatus.Unknown ||
                                    CurrentStatus == UploadStatus.NormalInProgress ||
                                    CurrentStatus == UploadStatus.ChunkedInProgress));
            StopRefreshVisible = (!CanScript && IsRefreshing &&
                                  (CurrentStatus == UploadStatus.Unknown ||
                                   CurrentStatus == UploadStatus.NormalInProgress ||
                                   CurrentStatus == UploadStatus.ChunkedInProgress));
            CancelVisible = (CanCancel &&
                             (CurrentStatus == UploadStatus.NormalInProgress || CurrentStatus == UploadStatus.ChunkedInProgress));

            // The base refresh url contains just the barID and postBackID

            RefreshUrl  = Request.Url.AbsolutePath;
            RefreshUrl += "?barID=" + ProgressBarID + "&postBackID=" + PostBackID;

            // Workaround Mono XSP bug where ApplyAppPathModifier() removes the session id
            RefreshUrl = ProgressBar.ApplyAppPathModifier(RefreshUrl);

            RefreshUrl     += "&canScript=" + CanScript + "&canCancel=" + CanCancel;
            StartRefreshUrl = RefreshUrl + "&refresher=server";
            StopRefreshUrl  = RefreshUrl + "&refresh=false";
            CancelUrl       = "javascript:NeatUpload_CancelClicked()";

            DataBind();
        }
Example #4
0
        public void ProcessRequest(HttpContext context)
        {
            string postBackID = context.Request.Params["postBackID"];
            string controlID  = context.Request.Params["controlID"];
            string cancel     = context.Request.Params["cancel"];

            if (cancel != null && Boolean.Parse(cancel))
            {
                UploadModule.CancelPostBack(postBackID);
            }

            UploadModule.BindProgressState(postBackID, controlID, this);
            string message = "";

            if (Status == UploadStatus.Rejected)
            {
                message = Rejection.Message;
            }
            else if (Status == UploadStatus.Failed)
            {
                message = Failure.Message;
            }
            context.Response.ContentType = "application/json";

            double       percentComplete     = Math.Floor(100 * FractionComplete);
            string       processingStateJson = "null";
            ProgressInfo progressInfo        = ProcessingState as ProgressInfo;

            if (progressInfo != null)
            {
                percentComplete     = Math.Floor(100.0 * progressInfo.Value / progressInfo.Maximum);
                processingStateJson = String.Format(@"{{ ""Value"" : {0}, ""Maximum"" : {1}, ""Units"" : ""{2}"", ""Text"" : ""{3}"" }}",
                                                    progressInfo.Value, progressInfo.Maximum, Quote(progressInfo.Units), progressInfo.Text != null ? Quote(progressInfo.Text) : "");
            }

            System.Text.StringBuilder filesJson = new System.Text.StringBuilder();
            bool isFirstFile = true;

            for (int i = 0; Files != null && i < Files.Count; i++)
            {
                UploadedFile file = Files[i];
                if (Status == UploadStatus.NormalInProgress || Status == UploadStatus.ChunkedInProgress || Status == UploadStatus.ProcessingInProgress)
                {
                    AppendFileJson(filesJson, file, ref isFirstFile);
                }
                else
                {
                    // If the upload isn't in progress, the file might have been disposed which
                    // can cause exceptions, so we only make a best effort.
                    try
                    {
                        AppendFileJson(filesJson, file, ref isFirstFile);
                    }
                    catch (Exception ex)
                    {
                        // File was probably disposed so ignore the error.
                    }
                }
            }

            string jsonFormat = @"{{ 
      ""Status"" : ""{0}"",
      ""BytesRead"" : {1},
      ""BytesTotal"" : {2},
      ""PercentComplete"" : {3},
      ""BytesPerSec"" : {4},
      ""Message"" : ""{5}"",
      ""SecsRemaining"" : {6},
      ""SecsElapsed"" : {7},
      ""CurrentFileName"" : ""{8}"",
      ""ProcessingState"" : {9},
      ""Files"" : [{10}]  
    }}
    ";
            string json       = String.Format(jsonFormat,
                                              Status, BytesRead, BytesTotal, percentComplete, BytesPerSec, Quote(message),
                                              Math.Floor(TimeRemaining.TotalSeconds), Math.Floor(TimeElapsed.TotalSeconds), Quote(CurrentFileName), processingStateJson, filesJson.ToString());

            context.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
            context.Response.Write(json);
        }