コード例 #1
0
        static BrowserRender()
        {
            GlobalEventSystemFacade.SubscribeToShutDownEvent(a => ShutdownPhantomJsExeSilent());
            PackageInstaller.OnPackageInstallation += ShutdownPhantomJsExeSilent;

            FileChangeNotificator.Subscribe(PhantomServer.ScriptFilePath, (a, b) => PhantomServer.ShutDown(false));
        }
コード例 #2
0
        private static void RecycleIfNotUsed()
        {
            if (DateTime.Now - _lastUsageDate < RecycleOnIdleInterval)
            {
                return;
            }

            PhantomServer.ShutDown(false);
        }
コード例 #3
0
 private static void ShutdownPhantomJsExeSilent()
 {
     Enabled = false;
     try
     {
         PhantomServer.ShutDown(false, true);
     }
     catch
     {
     }
 }
コード例 #4
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;
                }
            }
        }
コード例 #5
0
        private static async Task <RenderingResult> MakePreviewRequestAsync(HttpContext context, string url, string outputFileName, string mode)
        {
            var cookies = GetAuthenticationCookies(context);

            await CheckServerAvailabilityAsync(context, cookies);

            if (!Enabled)
            {
                return(null);
            }

            _lastUsageDate = DateTime.Now;

            return(await PhantomServer.RenderUrlAsync(cookies, url, outputFileName, mode));
        }
コード例 #6
0
            public static void ShutDown(bool alreadyLocked, bool silent = false)
            {
                PhantomServer ps;

                using (alreadyLocked ? null : _instanceAsyncLock.Lock())
                {
                    if (_instance == null)
                    {
                        return;
                    }

                    ps        = _instance;
                    _instance = null;
                }

                ps.DisposeInternal(silent);
                GC.SuppressFinalize(ps);
            }
コード例 #7
0
            public static void ShutDown(bool alreadyLocked, bool silent = false)
            {
                PhantomServer ps;

                using (alreadyLocked ? null : _instanceAsyncLock.Lock())
                {
                    if (_instance == null)
                    {
                        return;
                    }

                    ps = _instance;
                    _instance = null;
                }

                ps.DisposeInternal(silent);
                GC.SuppressFinalize(ps);
            }
コード例 #8
0
ファイル: BrowserRender.cs プロジェクト: gitter-badger/C1-CMS
        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;
                }
            }
        }