Example #1
0
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            //Make thread barrier here
            if (!ProcessingEvent.WaitOne(TimeSpan.FromSeconds(90)))
            {
                //If we didn't wait finishing then redirect here again
                context.Response.Redirect(context.Request.GetUrlRewriter().ToString(), true);
            }

            var asyncState = new AsyncBundlingRequestState(context, cb, extraData);

            if (!string.IsNullOrEmpty(context.Request.Headers["If-Modified-Since"]))
            {
                //Respond 304
                //Return always 304 because
                context.Response.StatusCode = (int)HttpStatusCode.NotModified;
                asyncState.IsFromCache      = true;
                asyncState.OnCompleted(true);
            }
            else
            {
                //Try cached
                var cached = HttpRuntime.Cache.Get(GetKey(new HttpRequestWrapper(context.Request))) as StringBuilder;
                if (cached != null)
                {
                    asyncState.IsFromCache  = true;
                    asyncState.ResourceData = cached;
                    asyncState.OnCompleted(true);
                }
                else
                {
                    //Beign Read
                    _maxEmbeddableSize = ClientCapabilities.GetMaxEmbeddableImageSize(new HttpRequestWrapper(context.Request));
                    ProcessingEvent.Reset();

                    if (_bundleResources.Count(r => r.Content.Contains("jquery")) <= 0)
                    {
                        var content =
                            @"/*
    Copyright (c) Ascensio System SIA " + DateTime.UtcNow.Year + @". All rights reserved.
    http://www.teamlab.com
*/";
                        asyncState.ResourceData.Append(content).Append(Environment.NewLine);

                        asyncState.Context.Response.Write(content);
                        asyncState.Context.Response.Write(Environment.NewLine);
                    }


                    ProcessItem(_bundleResources.Dequeue(), asyncState);
                }
            }
            return(asyncState);
        }
Example #2
0
 private BundleResource GetNextResource(AsyncBundlingRequestState asyncState)
 {
     if (_bundleResources.Count == 0)
     {
         asyncState.OnCompleted();
         return(BundleResource.Empty);
     }
     return(_bundleResources.Dequeue());
 }
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            //Make thread barrier here
            if (!ProcessingEvent.WaitOne(TimeSpan.FromSeconds(90)))
            {
                //If we didn't wait finishing then redirect here again
                context.Response.Redirect(context.Request.GetUrlRewriter().ToString(), true);
            }

            var asyncState = new AsyncBundlingRequestState(context, cb, extraData);
            if (!string.IsNullOrEmpty(context.Request.Headers["If-Modified-Since"]))
            {
                //Respond 304
                //Return always 304 because
                context.Response.StatusCode = (int)HttpStatusCode.NotModified;
                asyncState.IsFromCache = true;
                asyncState.OnCompleted(true);
            }
            else
            {

                //Try cached
                var cached = HttpRuntime.Cache.Get(GetKey(new HttpRequestWrapper(context.Request))) as StringBuilder;
                if (cached != null)
                {
                    asyncState.IsFromCache = true;
                    asyncState.ResourceData = cached;
                    asyncState.OnCompleted(true);
                }
                else
                {
                    //Beign Read
                    _maxEmbeddableSize = ClientCapabilities.GetMaxEmbeddableImageSize(new HttpRequestWrapper(context.Request));
                    ProcessingEvent.Reset();

                    if (_bundleResources.Count(r=> r.Content.Contains("jquery"))<= 0)
                    {
                        var content =
@"/*
    Copyright (c) Ascensio System SIA " + DateTime.UtcNow.Year + @". All rights reserved.
    http://www.teamlab.com
*/";
                        asyncState.ResourceData.Append(content).Append(Environment.NewLine);

                        asyncState.Context.Response.Write(content);
                        asyncState.Context.Response.Write(Environment.NewLine);
                    }
                   

                    ProcessItem(_bundleResources.Dequeue(), asyncState);
                }
            }
            return asyncState;
        }
 private BundleResource GetNextResource(AsyncBundlingRequestState asyncState)
 {
     if (_bundleResources.Count == 0)
     {
         asyncState.OnCompleted();
         return BundleResource.Empty;
     }
     return _bundleResources.Dequeue();
 }