Esempio n. 1
0
        private static async Task CheckServerAvailabilityAsync(HttpContext context, HttpCookie[] cookies)
        {
            if (ServerAvailabilityChecked || cookies == null)
            {
                return;
            }

            using (await _serverAvailabilityCheckLock.LockAsync())
            {
                if (ServerAvailabilityChecked)
                {
                    return;
                }

                if (!SystemFullyOnline)
                {
                    return;
                }

                try
                {
                    string testUrl = UrlUtils.Combine(new UrlBuilder(context.Request.Url.ToString()).ServerUrl, UrlUtils.PublicRootPath);

                    SetupRecycleTimer();

                    string outputFileName = Path.Combine(TempDirectoryFacade.TempDirectoryPath, "phantomtest.png");

                    var result = await PhantomServer.RenderUrlAsync(cookies, testUrl, outputFileName, "test");

                    if (result.Status == RenderingResultStatus.PhantomServerTimeout ||
                        result.Status == RenderingResultStatus.PhantomServerIncorrectResponse ||
                        result.Status == RenderingResultStatus.PhantomServerNoOutput)
                    {
                        Enabled = false;
                        Log.LogWarning(LogTitle, "The function preview feature will be turned off as PhantomJs server failed to complete a test HTTP request");
                    }
                }
                catch (Exception ex)
                {
                    Log.LogWarning(LogTitle, "PhantomJs server unable to complete HTTP requests, preventing C1 Function preview images from being generated. " + Environment.NewLine + ex);
                    Enabled = false;

                    PhantomServer.ShutDown(false);
                }
                finally
                {
                    ServerAvailabilityChecked = true;
                }
            }
        }
Esempio n. 2
0
        private static async Task CheckServerAvailabilityAsync(HttpContext context, HttpCookie authenticationCookie)
        {
            if (ServerAvailabilityChecked || authenticationCookie == null)
            {
                return;
            }

            using (await _serverAvailabilityCheckLock.LockAsync())
            {
                if (ServerAvailabilityChecked)
                {
                    return;
                }

                if (!SystemFullyOnline)
                {
                    return;
                }

                try
                {
                    string testUrl = UrlUtils.Combine(new UrlBuilder(context.Request.Url.ToString()).ServerUrl, UrlUtils.PublicRootPath);

                    SetupRecycleTimer();

                    string outputFileName = Path.Combine(TempDirectoryFacade.TempDirectoryPath, "phantomtest.png");

                    await PhantomServer.RenderUrlAsync(authenticationCookie, testUrl, outputFileName, "test");
                }
                catch (Exception ex)
                {
                    Log.LogWarning(LogTitle, "PhantomJs server unable to complete HTTP requests, preventing C1 Function preview images from being generated. " + Environment.NewLine + ex);
                    Enabled = false;

                    PhantomServer.ShutDown(false);
                }
                finally
                {
                    ServerAvailabilityChecked = true;
                }
            }
        }