public static UploadProgressStatistic GetStatistic(string id)
 {
     UploadProgressStatistic us;
     if (!statistics.TryGetValue(id, out us))
         us = new UploadProgressStatistic();
     return us;
 }
        public static UploadProgressStatistic GetStatistic(string id)
        {
            UploadProgressStatistic us;

            if (!statistics.TryGetValue(id, out us))
            {
                us = new UploadProgressStatistic();
            }
            return(us);
        }
        public override void OnProcessRequest(HttpContext context)
        {
            if (!string.IsNullOrEmpty(context.Request["submit"]))
            {
                FileUploadHandler.FileUploadResult result;
                try
                {
                    var uploadHandler = (FileUploadHandler)Activator.CreateInstance(Type.GetType(context.Request["submit"], true));
                    result = uploadHandler.ProcessUpload(context);
                }
                catch (Exception ex)
                {
                    result = new FileUploadHandler.FileUploadResult
                    {
                        Success = false,
                        Message = ex.Message.HtmlEncode(),
                    };
                }

                //NOTE: Don't set content type. ie cant parse it
                context.Response.StatusCode = 200;
                context.Response.Write(JavaScriptSerializer.Serialize(result));
            }
            else
            {
                context.Response.ContentType = "application/json";
                var id = context.Request.QueryString[UploadProgressStatistic.UploadIdField];
                var us = UploadProgressStatistic.GetStatistic(id);

                if (!string.IsNullOrEmpty(context.Request["limit"]))
                {
                    var limit = long.Parse(context.Request["limit"]);
                    if (us.TotalBytes > limit)
                    {
                        us.ReturnCode = 1;
                        us.IsFinished = true;
                    }
                }

                context.Response.Write(us.ToJson());
            }
        }
        internal EntityBodyInspector(HttpUploadWorkerRequest request)
        {
            statistic = new UploadProgressStatistic();
            
            statistic.TotalBytes = request.GetTotalEntityBodyLength();

            string contentType = request.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentType);

            string boundary = string.Format("--{0}\r\n", UploadProgressUtils.GetBoundary(contentType));
            _encoding = System.Text.Encoding.UTF8;

            _boundaryWaiter = new EntityBodyChunkStateWaiter(boundary, false);
            _boundaryWaiter.MeetGuard += new EventHandler<EventArgs>(boundaryWaiter_MeetGuard);
            _current = _boundaryWaiter;

            _boundaryInfoWaiter = new EntityBodyChunkStateWaiter("\r\n\r\n", true);
            _boundaryInfoWaiter.MeetGuard += new EventHandler<EventArgs>(boundaryInfoWaiter_MeetGuard);

            _formValueWaiter = new EntityBodyChunkStateWaiter("\r\n", true);
            _formValueWaiter.MeetGuard += new EventHandler<EventArgs>(formValueWaiter_MeetGuard);

            _lastCdName = string.Empty;
        }
        internal EntityBodyInspector(HttpUploadWorkerRequest request)
        {
            statistic = new UploadProgressStatistic();

            statistic.TotalBytes = request.GetTotalEntityBodyLength();

            string contentType = request.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentType);

            string boundary = string.Format("--{0}\r\n", UploadProgressUtils.GetBoundary(contentType));

            _encoding = System.Text.Encoding.UTF8;

            _boundaryWaiter            = new EntityBodyChunkStateWaiter(boundary, false);
            _boundaryWaiter.MeetGuard += new EventHandler <EventArgs>(boundaryWaiter_MeetGuard);
            _current = _boundaryWaiter;

            _boundaryInfoWaiter            = new EntityBodyChunkStateWaiter("\r\n\r\n", true);
            _boundaryInfoWaiter.MeetGuard += new EventHandler <EventArgs>(boundaryInfoWaiter_MeetGuard);

            _formValueWaiter            = new EntityBodyChunkStateWaiter("\r\n", true);
            _formValueWaiter.MeetGuard += new EventHandler <EventArgs>(formValueWaiter_MeetGuard);

            _lastCdName = string.Empty;
        }