예제 #1
0
        private void SendMissingResources_(List <RunningRender> runningRenders, RGridDom dom, IDictionary <string, RGridResource> resources, bool isNeedMoreDom)
        {
            logger_.Verbose("enter - sending {0} missing resources. need more dom: {1}", resources.Count, isNeedMoreDom);
            List <PutFuture> allPuts = new List <PutFuture>();

            if (isNeedMoreDom)
            {
                RunningRender runningRender = runningRenders[0];
                PutFuture     future        = null;
                try
                {
                    future = connector_.RenderPutResource(runningRender, dom.AsResource());
                }
                catch (JsonException e)
                {
                    logger_.Log("Error (4): " + e);
                }
                logger_.Verbose("locking putResourceCache");
                lock (putResourceCache_)
                {
                    allPuts.Add(future);
                }
                logger_.Verbose("releasing putResourceCache");
            }

            logger_.Verbose("creating PutFutures for {0} runningRenders", runningRenders.Count);

            foreach (RunningRender runningRender in runningRenders)
            {
                CreatePutFutures_(allPuts, runningRender, resources);
            }

            logger_.Verbose("calling future.get on {0} PutFutures", allPuts.Count);
            foreach (PutFuture future in allPuts)
            {
                logger_.Verbose("calling future.get on {0}", future);
                try
                {
                    future.Get(TimeSpan.FromSeconds(120));
                }
                catch (Exception e)
                {
                    logger_.Log("Error (5): " + e);
                }
            }
            logger_.Verbose("exit");
        }
예제 #2
0
        private IDictionary <string, RGridResource> BuildAllRGDoms_(IDictionary <string, RGridResource> resourceMapping, FrameData currentFrame)
        {
            Uri baseUrl = currentFrame.Url;

            logger_.Verbose("enter - baseUrl: " + baseUrl);

            ConcurrentDictionary <string, RGridResource> mapping = new ConcurrentDictionary <string, RGridResource>();
            ConcurrentDictionary <string, RGridResource> frames  = new ConcurrentDictionary <string, RGridResource>();

            logger_.Verbose("iterating {0} sub-frames", currentFrame.Frames.Count);
            foreach (FrameData frame in currentFrame.Frames)
            {
                logger_.Verbose("iterating {0} sub-frame blobs", frame.Blobs.Count);
                foreach (BlobData blob in frame.Blobs)
                {
                    string urlStr = blob.Url.OriginalString;
                    if (resourceMapping.TryGetValue(urlStr, out RGridResource rGridResource))
                    {
                        mapping.TryAdd(urlStr, rGridResource);
                    }
                }

                logger_.Verbose("iterating {0} sub-frame resource urls", frame.ResourceUrls.Count);
                foreach (Uri resourceUrl in frame.ResourceUrls)
                {
                    string urlStr = resourceUrl.OriginalString;
                    if (resourceMapping.TryGetValue(urlStr, out RGridResource rGridResource))
                    {
                        mapping.TryAdd(urlStr, rGridResource);
                    }
                }

                Uri frameUrl = frame.Url;

                /*if ("about:blank".Equals(frameUrl.ToString(), StringComparison.OrdinalIgnoreCase))
                 * {
                 *  continue;
                 * }
                 * else */
                if (!frameUrl.IsAbsoluteUri)
                {
                    frameUrl = new Uri(baseUrl, frameUrl);
                }


                try
                {
                    logger_.Verbose("entering recursion. url: {0}", frameUrl);
                    IDictionary <string, RGridResource> innerFrameResourceMap = BuildAllRGDoms_(resourceMapping, frame);
                    logger_.Verbose("exiting recursion. url: {0}", frameUrl);

                    foreach (KeyValuePair <string, RGridResource> kvp in innerFrameResourceMap)
                    {
                        mapping.TryAdd(kvp.Key, kvp.Value);
                    }
                    logger_.Verbose("mapped resources: {0}", mapping.Count);

                    // Sort mapped resources by their URL for constant, testable results.
                    SortedDictionary <string, RGridResource> sortedMapping = new SortedDictionary <string, RGridResource>(mapping);

                    RGridDom rGridDom = new RGridDom(frame.Cdt, sortedMapping, frameUrl, logger_, "buildAllRGDoms");
                    logger_.Verbose("adding resources to dictionary. url: {0}", frameUrl);
                    RGridResource frameResource = rGridDom.AsResource();
                    resourceMapping[frameUrl.OriginalString] = frameResource;
                    frames[frameUrl.OriginalString]          = frameResource;
                }
                catch (Exception e)
                {
                    logger_.Log("Error (10): " + e);
                }
            }

            logger_.Verbose("exit");
            return(frames);
        }