Provides a mutex-like lock on a socket.
Inheritance: ILock
        /// <summary>
        /// Starts the connection to the extension.
        /// </summary>
        public void Start()
        {
            using (ILock lockObject = new SocketLock(this.profile.Port - 1))
            {
                lockObject.LockObject(this.process.TimeoutInMilliseconds);
                try
                {
                    int portToUse = DetermineNextFreePort(this.host, this.profile.Port);
                    this.profile.Port = portToUse;
                    this.profile.WriteToDisk();
                    this.process.Clean(this.profile);
                    this.process.StartProfile(this.profile, new string[] { "-foreground" });

                    this.SetAddress(portToUse);

                    // TODO (JimEvans): Get a better url algorithm.
                    this.executor = new HttpCommandExecutor(new Uri(string.Format(CultureInfo.InvariantCulture, "http://{0}:{1}/hub/", this.host, portToUse)), this.timeout);
                }
                finally
                {
                    lockObject.UnlockObject();
                }
            }

            this.ConnectToBrowser(this.process.TimeoutInMilliseconds);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts the connection to the extension.
        /// </summary>
        public void Start()
        {
            using (ILock lockObject = new SocketLock(this.profile.Port - 1))
            {
                lockObject.LockObject(this.process.Timeout);
                try
                {
                    int portToUse = DetermineNextFreePort(this.host, this.profile.Port);
                    this.profile.Port = portToUse;
                    this.profile.WriteToDisk();
                    this.process.Clean(this.profile);
                    this.process.StartProfile(this.profile, new string[] { "-foreground" });

                    this.SetAddress(portToUse);

                    // TODO (JimEvans): Get a better url algorithm.
                    this.executor = new HttpCommandExecutor(new Uri(string.Format(CultureInfo.InvariantCulture, "http://{0}:{1}/hub/", this.host, portToUse)), this.timeout);
                    this.ConnectToBrowser(this.process.Timeout);
                }
                finally
                {
                    lockObject.UnlockObject();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Connect to an instance of the WebDriver Firefox extension.
        /// </summary>
        /// <param name="binary">The <see cref="FirefoxBinary"/> in which the extension is hosted.</param>
        /// <param name="profile">The <see cref="FirefoxProfile"/> in which the extension is installed.</param>
        /// <param name="host">The host name of the computer running the extension (usually "localhost").</param>
        /// <returns>An <see cref="ExtensionConnection"/> connected to the WebDriver Firefox extension.</returns>
        /// <exception cref="WebDriverException">If there are any problems connecting to the extension.</exception>
        public static ExtensionConnection ConnectTo(FirefoxBinary binary, FirefoxProfile profile, string host)
        {
            int profilePort = profile.Port;
            ExtensionConnection connection = null;

            using (ILock lockObject = new SocketLock(profilePort - 1))
            {
                connection = new ExtensionConnection(lockObject, binary, profile, host);
            }

            return(connection);
        }