コード例 #1
0
        /// <inheritdoc />
        public void ReleaseBrowser(BrowserAbstract browser)
        {
            // This method is not expected to leak any predictable WebDriver exceptions.
            if (browser == null)
            {
                return;
            }

            FiddlerProxy.ClearHeaders(browser.ProcessId);

            try
            {
                // cleanup the previous state
                browser.DeleteAllCookies();

                // Selenium issue: must navigate away from page after cleaning up cookies otherwise some cookies will persist.
                browser.NavigateTo(browser.DefaultPage);
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {
                // suppress any exceptions while removing cookies.
                // If there is a problem, the browser will be marked as Faulted and handled in the next block.
            }

            if (this.browserPools.ContainsKey(browser.BrowserType) &&
                !this.browserPools[browser.BrowserType].PoolContains(browser))
            {
                // put the browser back in rotation
                this.browserPools[browser.BrowserType].ReleaseBrowser(browser);
            }
        }
コード例 #2
0
ファイル: BrowserPool.cs プロジェクト: leovo2708/sesopen
 /// <summary>
 /// Removes a browser instance from the pool.
 /// </summary>
 /// <param name="browser">
 ///     The browser to remove.
 /// </param>
 public void RemoveInstance(BrowserAbstract browser)
 {
     if (browser != null)
     {
         this.instances.Remove(browser);
         this.timers.Remove(browser);
     }
 }
コード例 #3
0
ファイル: BrowserPool.cs プロジェクト: leovo2708/sesopen
        /// <summary>
        /// Returns a previously acquired browser to the pool.
        /// </summary>
        /// <param name="browser">
        ///     The browser to release.
        /// </param>
        public void ReleaseBrowser(BrowserAbstract browser)
        {
            if (this.instances.Contains(browser))
            {
                this.pool.Add(browser);

                this.timers[browser].Stop();

                this.timers[browser].Reset();
            }
        }
コード例 #4
0
ファイル: BrowserPool.cs プロジェクト: leovo2708/sesopen
        /// <summary>
        /// Adds a browser instance to the pool.
        /// </summary>
        /// <param name="browser">
        ///     The browser to add.
        /// </param>
        public void AddInstance(BrowserAbstract browser)
        {
            if (browser.BrowserType == this.BrowserType)
            {
                if (!this.timers.ContainsKey(browser))
                {
                    this.timers.Add(new KeyValuePair <BrowserAbstract, Stopwatch>(browser, new Stopwatch()));
                }

                this.instances.Add(browser);
                this.pool.Add(browser);
            }
        }
コード例 #5
0
        /// <inheritdoc />
        public BrowserAbstract AcquireBrowser(BrowserType browserType)
        {
            BrowserAbstract browser = null;

            if (this.browserPools.ContainsKey(browserType))
            {
                var pool = this.browserPools[browserType];
                browser = pool.WaitForABrowser();

                if (browser == null)
                {
                    Logger.WriteDebug(
                        "Unable to acquire browser {0}", browserType);
                }
            }

            return(browser);
        }
コード例 #6
0
        /// <inheritdoc />
        public void CreateBrowserInstances()
        {
            // wait a short while for the semaphore, if we can't get it then assume someone else is maintaining the pool
            if (this.syncLock.Wait(100))
            {
                try
                {
                    foreach (var pool in this.browserPools.Values)
                    {
                        for (int i = pool.InstanceCount; i < pool.MaxInstances; i++)
                        {
                            try
                            {
                                BrowserAbstract browser = this.factory.Create(pool.BrowserType);

                                Logger.WriteInfo(
                                    "Registering browser: {0} (PID {1} parent PID {2})",
                                    browser.GetType().Name,
                                    browser.ProcessId,
                                    browser.ParentProcessId);

                                pool.AddInstance(browser);
                            }
                            catch (Exception exception)
                            {
                                Logger.WriteWarning(
                                    exception,
                                    "Unexpected failure while creating a browser of type {0}",
                                    pool.BrowserType);
                            }
                        }
                    }
                }
                finally
                {
                    this.syncLock.Release();
                }
            }
        }
コード例 #7
0
ファイル: BrowserPool.cs プロジェクト: leovo2708/sesopen
 /// <summary>
 /// Returns a value indicating whether the specified browser is available in the pool.
 /// </summary>
 /// <param name="browser">
 ///     The browser to verify.
 /// </param>
 /// <returns>
 /// True if the browser is available in the pool, otherwise false.
 /// </returns>
 public bool PoolContains(BrowserAbstract browser)
 {
     return(this.pool.Contains(browser));
 }