Exemplo n.º 1
0
        private static void LoaderPortalPages(RequestItem requestItem)
        {
            CoreContext.TenantManager.SetCurrentTenant(requestItem.TenantId);

            var authCookie = SecurityContext.AuthenticateMe(SecurityContext.CurrentAccount.ID);
            var tenant     = CoreContext.TenantManager.GetCurrentTenant().TenantDomain;

            try
            {
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(requestItem.Url);
                httpWebRequest.Headers.Add("Authorization", authCookie);
                httpWebRequest.Method          = "GET";
                httpWebRequest.CookieContainer = new CookieContainer();
                httpWebRequest.CookieContainer.Add(new Cookie("asc_auth_key", authCookie, "/", tenant));
                httpWebRequest.Timeout = 120000;

                httpWebRequest.GetResponseAsync().ContinueWith(r => Progress.Increment());
            }
            catch (Exception exception)
            {
                LogManager.GetLogger("ASC.Web")
                .Error(string.Format("Page is not avaliable by url {0}", requestItem.Url), exception);
            }
            finally
            {
            }
        }
Exemplo n.º 2
0
        private void MakeRequest()
        {
            if (WorkContext.IsMono)
            {
                ServicePointManager.ServerCertificateValidationCallback = (s, c, h, p) => true;
            }

            if (Tenant == null)
            {
                LogManager.GetLogger("ASC").Warn("Warmup: tenant is null");
                return;
            }

            CoreContext.TenantManager.SetCurrentTenant(Tenant);
            var auth       = SecurityContext.AuthenticateMe(Tenant.OwnerId);
            var tasksCount = (int)Math.Round((double)Environment.ProcessorCount / instanceCount);

            if (tasksCount == 0)
            {
                tasksCount = 1;
            }

            for (var j = 0; j < Urls.Count; j++)
            {
                if (tokenSource.IsCancellationRequested)
                {
                    return;
                }

                var tasks = new List <Task>(tasksCount);

                for (var i = 0; i < tasksCount && j < Urls.Count; i++, j++)
                {
                    tasks.Add(MakeRequest(Urls[j], auth));
                }

                j--;

                try
                {
                    Task.WaitAll(tasks.Where(r => r != null).ToArray());
                }
                catch (AggregateException ex)
                {
                    logger.Error("WarmUp error", ex);
                }


                lock (locker)
                {
                    progress.Increment(tasks.Count(r => r != null));
                }

                Publish();
            }
        }
Exemplo n.º 3
0
        private void MakeRequest(string requestUrl)
        {
            try
            {
                if (tokenSource.IsCancellationRequested)
                {
                    return;
                }

                CoreContext.TenantManager.SetCurrentTenant(TenantId);
                if (WorkContext.IsMono)
                {
                    ServicePointManager.ServerCertificateValidationCallback = (s, c, h, p) => true;
                }

                var currentUserId = SecurityContext.CurrentAccount.ID;
                if (!SecurityContext.IsAuthenticated)
                {
                    currentUserId = CoreContext.TenantManager.GetCurrentTenant().OwnerId;
                }

                using (var webClient = new WebClient())
                {
                    webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.4; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36");
                    webClient.Headers.Add("Authorization", SecurityContext.AuthenticateMe(currentUserId));
                    webClient.DownloadData(requestUrl);
                }
            }
            catch (Exception exception)
            {
                LogManager.GetLogger("ASC.Web").Error(string.Format("Page is not avaliable by url {0}", requestUrl), exception);
            }
            finally
            {
                lock (locker)
                {
                    progress.Increment();
                    Publish();
                }
            }
        }