Ejemplo n.º 1
0
 internal static void Copy(IUploadProgressState src, IUploadProgressState dest)
 {
     dest.Status           = src.Status;
     dest.BytesRead        = src.BytesRead;
     dest.BytesTotal       = src.BytesTotal;
     dest.BytesPerSec      = src.BytesPerSec;
     dest.FileBytesRead    = src.FileBytesRead;
     dest.FractionComplete = src.FractionComplete;
     dest.CurrentFileName  = src.CurrentFileName;
     dest.Files            = src.Files;
     dest.Failure          = src.Failure;
     dest.Rejection        = src.Rejection;
     dest.ProcessingState  = src.ProcessingState;
     dest.TimeElapsed      = src.TimeElapsed;
     dest.TimeRemaining    = src.TimeRemaining;
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Fills in an <see cref="IUploadProgressState"/> object with the progress state for
        /// a given post-back ID and control UniqueID.
        /// </summary>
        /// <param name="postBackID">
        /// The post-back ID for which the progress state should be retrieved.
        /// </param>
        /// <param name="controlUniqueID">
        /// The UniqueID of the control for which the progress state should be retrieved.
        /// </param>
        /// <param name="progressState">
        /// A <see cref="IUploadProgressState"/> to be filled in with the progress state
        /// for the given post-back ID and control UniqueID.
        /// </param>
        /// <remarks>The progress state is cached for the length of the current request to
        /// ensure consistency across multiple calls during a single request and to reduce 
        /// the number of calls made
        /// to the underlying <see cref="IUploadModule"/> implementation since some 
        /// implementations might need to access the network to determine the 
        /// progress state.</remarks>
        public static void BindProgressState(string postBackID, string controlUniqueID, IUploadProgressState progressState)
        {
            HttpContext ctx = HttpContext.Current;
            if (ctx != null)
            {
                InstalledModule.BindProgressState(postBackID, controlUniqueID, progressState);
                return;
            }

            string cacheKey = String.Format("NeatUpload_cachedProgressState_{0}-{1}", postBackID, controlUniqueID);
            UploadProgressState cachedProgressState = ctx.Items[cacheKey] as Internal.UI.UploadProgressState;
            if (cachedProgressState == null)
            {
                cachedProgressState = new UploadProgressState();
                InstalledModule.BindProgressState(postBackID, controlUniqueID, cachedProgressState);
                ctx.Items[cacheKey] = cachedProgressState;
            }
            UploadProgressState.Copy(cachedProgressState, progressState);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Fills in an <see cref="IUploadProgressState"/> object with the progress state for
        /// a given post-back ID and control UniqueID.
        /// </summary>
        /// <param name="postBackID">
        /// The post-back ID for which the progress state should be retrieved.
        /// </param>
        /// <param name="controlUniqueID">
        /// The UniqueID of the control for which the processing state should be retrieved,
        /// or null to retrieve progress state without processing state.
        /// </param>
        /// <param name="progressState">
        /// A <see cref="IUploadProgressState"/> to be filled in with the progress state
        /// for the given post-back ID and control UniqueID.
        /// </param>
        /// <remarks>The progress state is cached for the length of the current request to
        /// ensure consistency across multiple calls during a single request and to reduce
        /// the number of calls made
        /// to the underlying <see cref="IUploadModule"/> implementation since some
        /// implementations might need to access the network to determine the
        /// progress state.</remarks>
        public static void BindProgressState(string postBackID, string controlUniqueID, IUploadProgressState progressState)
        {
            HttpContext ctx = HttpContext.Current;

            if (ctx == null)
            {
                InstalledModule.BindProgressState(postBackID, controlUniqueID, progressState);
                return;
            }

            string cacheKey = String.Format("NeatUpload_cachedProgressState_{0}-{1}", postBackID, controlUniqueID);
            UploadProgressState cachedProgressState = ctx.Items[cacheKey] as Internal.UI.UploadProgressState;

            if (cachedProgressState == null)
            {
                cachedProgressState = new UploadProgressState();
                InstalledModule.BindProgressState(postBackID, controlUniqueID, cachedProgressState);
                ctx.Items[cacheKey] = cachedProgressState;
            }
            UploadProgressState.Copy(cachedProgressState, progressState);
        }
Ejemplo n.º 5
0
        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);
            if (uploadState.Files != null && uploadState.Files.Count > 0)
                progressState.CurrentFileName = uploadState.Files[uploadState.Files.Count-1].FileName;
            progressState.Files = uploadState.Files.GetReadOnlyCopy();
            progressState.Failure = uploadState.Failure;
            progressState.Rejection = uploadState.Rejection;
            progressState.ProcessingState = uploadState.ProcessingStateDict[controlUniqueID];
            progressState.TimeElapsed = uploadState.TimeElapsed;
            if (uploadState.BytesRead == 0 || uploadState.BytesTotal < 0)
            {
                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);
        }