/// <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(CultureInfo.InvariantCulture, "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); ApplicationArchiveInfo appInfo = ApplicationArchiveInfo.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> /// 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(CultureInfo.InvariantCulture, "Found no matching devices for name '{0}'", this.deviceName)); } else { this.SendStatusUpdate("Connecting to device {0}.", device.Name); List <string> fileNames = new List <string>(); if (!this.appPath.Equals(string.Empty)) { this.assemblyDirectory = Path.GetDirectoryName(this.appPath); fileNames.Add(Path.GetFileName(this.appPath)); } else { this.assemblyDirectory = Path.GetDirectoryName(this.GetType().Assembly.Location); fileNames.Add("WindowsPhoneDriverBrowser.xap"); } string path = GetPackagePath(this.assemblyDirectory, fileNames); this.SendStatusUpdate("path: " + path); ApplicationArchiveInfo appInfo = ApplicationArchiveInfo.ReadApplicationInfo(path); 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 (path.EndsWith("xap")) { if (device.IsApplicationInstalled(applicationId)) { this.SendStatusUpdate("Application already installed. Uninstalling.."); device.GetApplication(applicationId).Uninstall(); } this.SendStatusUpdate("Installing application {0}.", path); this.browserApplication = device.InstallApplication(applicationId, applicationId, "WindowsPhoneDriverBrowser", iconPath, path); } else { if (device.IsApplicationInstalled(applicationId)) { this.SendStatusUpdate("Application already installed. Uninstalling.."); device.GetApplication(applicationId).Uninstall(); } this.SendStatusUpdate("Installing application {0}.", path); IAppManifestInfo manifestInfo = Utils.ReadAppManifestInfoFromPackage(this.appPath); DeploymentOptions deploymentOptions = DeploymentOptions.None; var devices = Utils.GetDevices(); var utilDevice = devices.FirstOrDefault(d => d.ToString() == "Device"); Utils.InstallApplication(utilDevice, manifestInfo, deploymentOptions, this.appPath); } } File.Delete(iconPath); } }