Example #1
0
        protected override void OnPreRender(EventArgs e)
        {
            if (!IsDesignTime && UploadModule.IsEnabled)
            {
                if (!Page.IsClientScriptBlockRegistered("NeatUploadMultiFile"))
                {
                    Page.RegisterClientScriptBlock("NeatUploadMultiFile", @"
	<script type='text/javascript' language='javascript' src='"
                                                   + UploadModule.BustCache(ResolveUrl("~/NeatUpload/SWFUpload.js"))
                                                   + @"'></script>");
                }
                if (!Page.IsClientScriptBlockRegistered("NeatUploadJs"))
                {
                    Page.RegisterClientScriptBlock("NeatUploadJs", @"
	<script type='text/javascript' language='javascript' src='"
                                                   + UploadModule.BustCache(ResolveUrl("~/NeatUpload/NeatUpload.js"))
                                                   + @"'></script>");
                }
            }
            if (!IsDesignTime)
            {
                Page.RegisterRequiresPostBack(this);
            }
            base.OnPreRender(e);
        }
Example #2
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 #3
0
 internal void UpdateProcessingState()
 {
     if (TimeOfLastSync.AddSeconds(1) > DateTime.Now || ControlID == null)
     {
         return;
     }
     UploadModule.SetProcessingState(ControlID, this);
     TimeOfLastSync = DateTime.Now;
 }
Example #4
0
        private void InitializeFiles()
        {
            if (IsDesignTime || IsFilesInitialized)
            {
                return;
            }
            // Initialize the Files property
            ArrayList fileArrayList = new ArrayList();

            if (UploadModule.IsEnabled)
            {
                UploadedFileCollection allFiles = UploadModule.Files;
                // Get only the files that were uploaded from this control
                for (int i = 0; allFiles != null && i < allFiles.Count; i++)
                {
                    if (allFiles.GetKey(i) == this.UniqueID)
                    {
                        UploadedFile uploadedFile = allFiles[i];
                        if (uploadedFile.IsUploaded)
                        {
                            fileArrayList.Add(allFiles[i]);
                        }
                    }
                }
            }
            else
            {
                HttpFileCollection allFiles = HttpContext.Current.Request.Files;
                // Get only the files that were uploaded from this control
                for (int i = 0; allFiles != null && i < allFiles.Count; i++)
                {
                    if (allFiles.GetKey(i) == this.UniqueID)
                    {
                        UploadedFile uploadedFile
                            = UploadModule.ConvertToUploadedFile(this.UniqueID, (HttpPostedFile)allFiles[i]);
                        if (uploadedFile == null)
                        {
                            continue;
                        }
                        if (uploadedFile.IsUploaded)
                        {
                            fileArrayList.Add(uploadedFile);
                        }
                        else
                        {
                            uploadedFile.Dispose();
                        }
                    }
                }
            }
            _files = new UploadedFile[fileArrayList.Count];
            Array.Copy(fileArrayList.ToArray(), _files, _files.Length);
            IsFilesInitialized = true;
        }
Example #5
0
        protected override void OnPreRender(EventArgs e)
        {
            if (!Page.IsClientScriptBlockRegistered("NeatUploadJs"))
            {
                Page.RegisterClientScriptBlock("NeatUploadJs", @"
<script type='text/javascript' language='javascript' src='"
                                               + UploadModule.BustCache(ResolveUrl("~/NeatUpload/NeatUpload.js"))
                                               + @"'></script>");
            }
            this.Page.RegisterStartupScript("NeatUploadUnloadConfirmer-" + this.UniqueID, GetStartupScript());
            base.OnPreRender(e);
        }
Example #6
0
        protected override void OnPreRender(EventArgs e)
        {
            if (!Width.IsEmpty && Width.Type != UnitType.Pixel)
            {
                throw new System.ArgumentOutOfRangeException("Width must use pixel(px) units when using a GreyBoxProgressBar.");
            }
            if (!Height.IsEmpty && Height.Type != UnitType.Pixel)
            {
                throw new System.ArgumentOutOfRangeException("Height must use pixel(px) units when using a GreyBoxProgressBar.");
            }
            base.OnPreRender(e);
            if (!UploadModule.IsEnabled)
            {
                return;
            }
            string expandedGreyBoxRoot = GreyBoxRoot;

            if (expandedGreyBoxRoot == null)
            {
                expandedGreyBoxRoot = "~/greybox";
            }
            expandedGreyBoxRoot = ResolveUrl(expandedGreyBoxRoot);

            if (!Page.IsClientScriptBlockRegistered("GreyBoxJs"))
            {
                Page.RegisterClientScriptBlock("GreyBoxJs", String.Format(@"
<script type='text/javascript' language='javascript'>
    var GB_ROOT_DIR = '{0}/';
</script>
<script type='text/javascript' language='javascript' src='{1}'></script>
<script type='text/javascript' language='javascript' src='{2}'></script>
<script type='text/javascript' language='javascript' src='{3}'></script>
<script type='text/javascript'>
    // Opera can't do fade-in effect during postback
	if (window.opera) AJS.fx = null;
</script>
<link href='{0}/gb_styles.css' rel='stylesheet' type='text/css' />
", expandedGreyBoxRoot,
                                                                          UploadModule.BustCache(expandedGreyBoxRoot + "/AJS.js"),
                                                                          UploadModule.BustCache(expandedGreyBoxRoot + "/AJS_fx.js"),
                                                                          UploadModule.BustCache(expandedGreyBoxRoot + "/gb_scripts.js")));
            }
        }
Example #7
0
        private void SetupContext()
        {
            // Find the current upload context
            PostBackID    = Request.Params["postBackID"];
            ProgressBarID = Request.Params["barID"];
            UploadModule.BindProgressState(PostBackID, ProgressBarID, this);
            if (log.IsDebugEnabled)
            {
                log.Debug("Status " + Status + " when SessionID = "
                          + (HttpContext.Current.Session != null ? HttpContext.Current.Session.SessionID : null));
            }

            if (Status == UploadStatus.Unknown)
            {
                CurrentStatus = 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, ProgressBarID, this);
                    if (FileBytesRead == 0 && ProcessingState != null)
                    {
                        Status = UploadStatus.Unknown;
                    }
                }
            }
            else
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("In ProgressPage, PostBackID = " + PostBackID);
                }
                if (log.IsDebugEnabled)
                {
                    log.Debug("In ProgressPage, Status = " + Status);
                }
                CurrentStatus = Status;
            }
        }
Example #8
0
        protected override void OnPreRender(EventArgs e)
        {
            if (UploadModule.IsEnabled)
            {
                // If we don't have a session yet and the session mode is not "Off", we need to create a
                // session so that it can be used to pass information between the progress display and the
                // upload request.  Apparently the only way to force the session to be created is to put
                // something in it.
                if (HttpContext.Current.Session != null &&
                    Page.Session.Mode != System.Web.SessionState.SessionStateMode.Off &&
                    Page.Session.Count == 0 &&
                    !Page.Session.IsReadOnly)
                {
                    Page.Session["NeatUpload_value"] = "ignored";
                }

                InitializeVars();
                if (!Page.IsClientScriptBlockRegistered("NeatUploadJs"))
                {
                    Page.RegisterClientScriptBlock("NeatUploadJs", @"
	<script type='text/javascript' language='javascript' src='"
                                                   + UploadModule.BustCache(ResolveUrl("~/NeatUpload/NeatUpload.js"))
                                                   + @"'></script>");
                }
                if (!Page.IsClientScriptBlockRegistered("NeatUploadProgressBar"))
                {
                    Page.RegisterClientScriptBlock("NeatUploadProgressBar", @"
	<script type='text/javascript' language='javascript'>
	NeatUploadPB.prototype.ClearFileNamesAlert = '"     + ResourceManagerSingleton.GetResourceString("ClearFileNamesAlert") + @"';
	// -->
	</script>
	"    );
                }
                this.Page.RegisterStartupScript("NeatUploadProgressBarBase-" + this.UniqueID, GetStartupScript());
            }
            base.OnPreRender(e);
        }
Example #9
0
        protected override void OnLoad(EventArgs e)
        {
            RegisterClientScriptBlock("NeatUpload-ProgressPage", "<script type='text/javascript' language='javascript' src='"
                                      + UploadModule.BustCache(ResolveUrl("Progress.js")) + @"'></script>");
            SetupContext();
            SetupBindableProps();

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

            if (Request.Params["useXml"] == "true")
            {
                Response.ContentType = "text/xml";
                Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
                Response.Write(@"<?xml version=""1.0"" encoding=""utf-8"" ?>");
            }

            string prevStatus = Request.Params["prevStatus"];

            if (prevStatus == null)
            {
                prevStatus = UploadStatus.Unknown.ToString();
            }
            string curStatus = Status.ToString();

            // If the status is unchanged from the last refresh and it is not Unknown nor *InProgress,
            // then the page is not refreshed.  Instead, if an UploadException occurred we try to cancel
            // the upload.  Otherwise, no exception occurred we close the progress display window (if it's a pop-up)
            if (curStatus == prevStatus &&
                (Status != UploadStatus.Unknown &&
                 Status != UploadStatus.NormalInProgress &&
                 Status != UploadStatus.ChunkedInProgress &&
                 Status != UploadStatus.ProcessingInProgress
                ))
            {
                if (Status == UploadStatus.Rejected ||
                    (Status == UploadStatus.Failed && Failure is HttpException &&
                     ((HttpException)Failure).GetHttpCode() == 400))
                {
                    if (CanCancel)
                    {
                        RegisterStartupScript("scrNeatUploadError", @"
<script type=""text/javascript"" language=""javascript"">
<!--
window.onload = function() {
		NeatUploadStop('"         + Status + @"');
}
// -->
</script>");
                    }
                }
                else if (Status != UploadStatus.Failed)
                {
                    RegisterStartupScript("scrNeatUploadClose", @"<script type='text/javascript' language='javascript'>
<!--
NeatUploadClose('" + ProgressBarID + @"');
// -->
</script>");
                }
            }
            // Otherwise, if we are refreshing, we refresh the page in one second
            else if (IsRefreshing)
            {
                // And add a prevStatus param to the url to track the previous status.
                string refreshUrl = RefreshUrl + "&prevStatus=" + curStatus;
                Refresh(refreshUrl);
            }
            base.OnLoad(e);
        }
Example #10
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);
        }
Example #11
0
 public static void AppendToLog(string param)
 {
     UploadModule.AppendToLog(param);
 }