/// <summary>
        /// Starts the controller.
        /// </summary>
        public void Start()
        {
            if (!string.IsNullOrEmpty(this.address) && !string.IsNullOrEmpty(this.port))
            {
                return;
            }

            Device device = this.FindDevice();

            if (device == null)
            {
                throw new WindowsPhoneDriverException(string.Format("Found no matching devices for name '{0}'", this.deviceName));
            }
            else
            {
                this.SendStatusUpdate("Connecting to device {0}.", device.Name);
                string assemblyDirectory = Path.GetDirectoryName(this.GetType().Assembly.Location);
                string xapPath = GetPackagePath(assemblyDirectory);
                XapInfo appInfo = XapInfo.ReadApplicationInfo(xapPath);
                Guid applicationId = appInfo.ApplicationId.Value;
                string iconPath = appInfo.ExtractIconFile();

                bool isConnectedToDevice = false;
                try
                {
                    device.Connect();
                    isConnectedToDevice = device.IsConnected();
                }
                catch (SmartDeviceException ex)
                {
                    this.SendStatusUpdate("WARNING! Exception encountered when connecting to device. HRESULT: {0:X}, message: {1}", ex.HResult, ex.Message);
                    System.Threading.Thread.Sleep(500);
                }

                if (!isConnectedToDevice)
                {
                    // TODO: Create connection mitigation routine.
                    this.SendStatusUpdate("WARNING! Was unable to connect to device!");
                }
                else
                {
                    if (!device.IsApplicationInstalled(applicationId))
                    {
                        this.SendStatusUpdate("Installing application {0}.", xapPath);
                        this.browserApplication = device.InstallApplication(applicationId, applicationId, "WindowsPhoneDriverBrowser", iconPath, xapPath);
                    }
                    else
                    {
                        this.SendStatusUpdate("Application already installed.");
                        this.browserApplication = device.GetApplication(applicationId);
                    }
                }

                File.Delete(iconPath);
            }
        }
        /// <summary>
        /// Reads the application info.
        /// </summary>
        /// <param name="appArchiveFilePath">Path to the file of the application bundle.</param>
        /// <returns>The <see cref="XapInfo"/> containing the information about the application.</returns>
        public static XapInfo ReadApplicationInfo(string appArchiveFilePath)
        {
            XapInfo appInfo = new XapInfo(appArchiveFilePath);

            try
            {
                // Do not use "using" for the FileStream. The ZipArchive will close/dispose the stream unless
                // we specify otherwise.
                FileStream appArchiveFileStream = new FileStream(appArchiveFilePath, FileMode.Open, FileAccess.Read);
                using (ZipArchive zipArchive = new ZipArchive(appArchiveFileStream, ZipArchiveMode.Read))
                {
                    ZipArchiveEntry appManifestEntry = zipArchive.GetEntry("WMAppManifest.xml");
                    using (Stream appManifestFileStream = appManifestEntry.Open())
                    {
                        XPathDocument  manifestDocument  = new XPathDocument(appManifestFileStream);
                        XPathNavigator manifestNavigator = manifestDocument.CreateNavigator();
                        XPathNavigator appNodeNavigator  = manifestNavigator.SelectSingleNode("//App");
                        appInfo.ApplicationId = new Guid?(new Guid(appNodeNavigator.GetAttribute("ProductID", string.Empty)));
                        string attribute = appNodeNavigator.GetAttribute("RuntimeType", string.Empty);
                        if (attribute.Equals("Modern Native", StringComparison.OrdinalIgnoreCase))
                        {
                            appInfo.IsNative = true;
                        }

                        manifestNavigator.MoveToFirstChild();
                        appInfo.ManifestVersion = new Version(manifestNavigator.GetAttribute("AppPlatformVersion", string.Empty));
                    }
                }
            }
            catch (Exception ex)
            {
                throw new WindowsPhoneDriverException("Unexpected error reading application information.", ex);
            }

            return(appInfo);
        }