Ejemplo n.º 1
0
 public bool Get()
 {
     if (putFuture_ == null)
     {
         PutFuture newFuture = eyesConnector_.RenderPutResource(runningRender_, resource_);
         putFuture_ = newFuture.putFuture_;
     }
     if (!isSentAlready_)
     {
         while (retryCount_ != 0)
         {
             try
             {
                 WebResponse response = putFuture_.GetAwaiter().GetResult();
                 response?.Close();
                 break;
             }
             catch (Exception e)
             {
                 logger_.Verbose("{0} on hash: {1}", e.Message, resource_.Sha256);
                 retryCount_--;
                 logger_.Verbose("Entering retry");
                 Thread.Sleep(300);
                 PutFuture newFuture = eyesConnector_.RenderPutResource(runningRender_, resource_);
                 logger_.Log("fired retry");
                 putFuture_ = newFuture.putFuture_;
             }
         }
     }
     isSentAlready_ = true;
     return(true);
 }
Ejemplo n.º 2
0
        internal void CreatePutFutures_(List <PutFuture> allPuts, RunningRender runningRender, IDictionary <string, RGridResource> resources)
        {
            List <Uri> needMoreResources = runningRender.NeedMoreResources;

            foreach (Uri url in needMoreResources)
            {
                string urlStr = SanitizeUrl_(url.OriginalString);
                if (putResourceCache_.TryGetValue(urlStr, out PutFuture putFuture))
                {
                    if (!allPuts.Contains(putFuture))
                    {
                        allPuts.Add(putFuture);
                    }
                    continue;
                }

                RGridResource resource;
                //logger_.Verbose("trying to get url from map - {0}", url);
                if (!fetchedCacheMap_.TryGetValue(urlStr, out ResourceFuture resourceFuture) || resourceFuture == null)
                {
                    logger_.Verbose("fetchedCacheMap.get(url) == null - " + url);
                    logger_.Log("Resource put requested but never downloaded (maybe a Frame)");
                    resources.TryGetValue(urlStr, out resource);
                }
                else
                {
                    try
                    {
                        Task <RGridResource> resourceTask = resourceFuture.Get(TimeSpan.FromSeconds(60));
                        resource = resourceTask.Result;
                    }
                    catch (Exception e)
                    {
                        logger_.Log("Error (6): " + e);
                        continue;
                    }
                }

                logger_.Verbose("resource({0}) hash : {1}", resource.Url, resource.Sha256);
                PutFuture future = connector_.RenderPutResource(runningRender, resource);
                if (resource.ContentType != RGridDom.ContentType)
                {
                    putResourceCache_.TryAdd(urlStr, future);
                }
                allPuts.Add(future);
            }
        }
Ejemplo n.º 3
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");
        }