private void InstallXapSynchronous(object pathToXap) { Guid? guid; Version version; bool flag; _device.Activate(); var tempFile = Path.GetTempFileName(); File.Copy((string)pathToXap, tempFile, true); Utils.ReadWMAppManifestXaml(tempFile, out guid, out version, out flag); var iconFile = Utils.ExtractIconFile(tempFile); if (_device.GetInstalledApplications().Any(x => x.ProductID == guid.Value)) { _lastApp = _device.GetApplication(guid.Value); } else { _lastApp = _device.InstallApplication(guid.Value, guid.Value, "NormalApp", iconFile, tempFile); } _lastApp.Launch(); XapInstalled(this, null); }
static int Main(string[] args) { if (args.Length == 0) { return(showHelp()); } string command = null; string wpsdk = null; string udid = null; Guid appid = Guid.Empty; int i; for (i = 0; i < args.Length; i++) { if (args[i] == "--wpsdk") { if (i + 1 < args.Length) { wpsdk = args[++i]; } } else if (command == null) { command = args[i]; if (command == "connect" && i + 1 < args.Length) { udid = args[++i]; } else if (command == "launch" && i + 1 < args.Length) { udid = args[++i]; string rawAppId = args[++i]; try { appid = Guid.Parse(rawAppId); } catch (FormatException fe) { return(showHelp("Invalid app GUID format: " + rawAppId)); } } } } if (wpsdk == null) { wpsdk = "10.0"; } else { // trim whatever version number they pass in to 2 digits string[] parts = wpsdk.Split(new Char [] { '.' }); wpsdk = ""; i = 0; while (i < 2) { if (wpsdk.Length > 0) { wpsdk += '.'; } if (i < parts.Length) { wpsdk += parts[i]; } else { wpsdk += '0'; } i++; } } if (!wpsdk.Equals("10.0") && !wpsdk.Equals("8.1")) { return(showHelp("Unsupported wpsdk value. Please use '10.0' or '8.1'.")); } int localeId = CultureInfo.CurrentUICulture.LCID; MultiTargetingConnectivity multiTargetingConnectivity = new MultiTargetingConnectivity(localeId); Collection <ConnectableDevice> devices = multiTargetingConnectivity.GetConnectableDevices(); List <ConnectableDevice> deviceList = new List <ConnectableDevice>(); i = 0; foreach (ConnectableDevice dev in devices) { // Filter to device and emulators that match the given SDK. We use 6.3 Version as the marker for 8.1 emus, assume rest are 10.0 string versionString = dev.Version.ToString(); if (!dev.IsEmulator() || (wpsdk == "8.1" && versionString.Equals("6.3")) || (wpsdk == "10.0" && !versionString.Equals("6.3"))) { deviceList.Add(dev); i++; } } if (command == "enumerate") { int id = 0; int j = 0; Console.WriteLine("{"); Console.WriteLine("\t\"devices\": ["); foreach (ConnectableDevice dev in deviceList) { string versionString = dev.Version.ToString(); if (!dev.IsEmulator()) { if (j > 0) { Console.WriteLine(","); } string sdk = "null"; if (versionString == "6.3") { sdk = "\"8.1\""; } else if (versionString == "10.0") { sdk = "\"10.0\""; } Console.WriteLine("\t\t{\n"); Console.WriteLine("\t\t\t\"name\": \"" + dev.Name.Replace("\"", "\\\"") + "\","); Console.WriteLine("\t\t\t\"udid\": " + id + ","); Console.WriteLine("\t\t\t\"index\": " + id + ","); Console.WriteLine("\t\t\t\"version\": \"" + versionString + "\","); // windows 8.1: "6.3", windows 10: "10.0" Console.WriteLine("\t\t\t\"wpsdk\": " + sdk); Console.Write("\t\t}"); j++; } id++; } Console.WriteLine("\n\t],"); id = 0; j = 0; Console.WriteLine("\t\"emulators\": ["); foreach (ConnectableDevice dev in deviceList) { if (dev.IsEmulator()) { if (j > 0) { Console.WriteLine(","); } Console.WriteLine("\t\t{\n"); Console.WriteLine("\t\t\t\"name\": \"" + dev.Name.Replace("\"", "\\\"") + "\","); Console.WriteLine("\t\t\t\"udid\": \"" + wpsdk.Replace('.', '-') + "-" + id + "\","); Console.WriteLine("\t\t\t\"index\": " + id + ","); Console.WriteLine("\t\t\t\"guid\": \"" + dev.Id + "\","); Console.WriteLine("\t\t\t\"version\": \"" + dev.Version + "\","); // 6.3 for 8.1 emulators, 6.4 for 10 emulators, 2147483647.2147483647.2147483647.2147483647 for device Console.WriteLine("\t\t\t\"uapVersion\": \"" + dev.UapVersion + "\","); // blank/empty for 8.1 emulators and device, 10.0.10586.0 for win 10 emulators Console.WriteLine("\t\t\t\"wpsdk\": \"" + wpsdk + "\""); Console.Write("\t\t}"); j++; } id++; } Console.WriteLine("\n\t]"); Console.WriteLine("}"); return(0); } // This won't just connect, it will launch the emulator! if (command == "connect" || command == "launch") { if (udid == null) { return(showHelp("Missing device/emulator UDID")); } // TODO Validate that the udid is either our generated udid (i.e. 10-0-1), or it's GUID, or it's an integer index value! int id = 0; // Search devices for udid! ConnectableDevice connectableDevice = null; foreach (ConnectableDevice dev in deviceList) { // Is it a matching GUID, matching UDID or matching Index value? if (dev.Id.Equals(udid) || (wpsdk.Replace('.', '-') + "-" + id).Equals(udid) || udid.Equals(id.ToString())) { connectableDevice = dev; break; } id++; } if (connectableDevice == null) { return(showHelp(String.Format("Invalid device UDID '{0:D}'", udid))); } // ConnectableDevice throws an error when connecting to a physical Windows 10 device // physical Windows 10 devices can be connected to using 127.0.0.1 if (command == "connect" && connectableDevice.Version.Major == 10 && !connectableDevice.IsEmulator()) { Console.WriteLine("{"); Console.WriteLine("\t\"success\": true,"); Console.WriteLine("\t\"ip\": \"127.0.0.1\","); Console.WriteLine("\t\"osVersion\": \"" + connectableDevice.Version.ToString() + "\""); Console.WriteLine("}"); return(0); } try { IDevice device = connectableDevice.Connect(); if (command == "launch") { IRemoteApplication app = device.GetApplication(appid); app.Launch(); Console.WriteLine("{"); Console.WriteLine("\t\"success\": true"); Console.WriteLine("}"); } else { string destinationIp; string sourceIp; int destinationPort; device.GetEndPoints(0, out sourceIp, out destinationIp, out destinationPort); var address = IPAddress.Parse(destinationIp); ISystemInfo systemInfo = device.GetSystemInfo(); Version version = new Version(systemInfo.OSMajor, systemInfo.OSMinor, systemInfo.OSBuildNo); Console.WriteLine("{"); Console.WriteLine("\t\"success\": true,"); Console.WriteLine("\t\"ip\": \"" + address.ToString() + "\","); Console.WriteLine("\t\"port\": " + destinationPort.ToString() + ","); Console.WriteLine("\t\"osVersion\": \"" + version.ToString() + "\","); Console.WriteLine("\t\"availablePhysical\": " + systemInfo.AvailPhys.ToString() + ","); Console.WriteLine("\t\"totalPhysical\": " + systemInfo.TotalPhys.ToString() + ","); Console.WriteLine("\t\"availableVirtual\": " + systemInfo.AvailVirtual.ToString() + ","); Console.WriteLine("\t\"totalVirtual\": " + systemInfo.TotalVirtual.ToString() + ","); Console.WriteLine("\t\"architecture\": \"" + systemInfo.ProcessorArchitecture.ToString() + "\","); Console.WriteLine("\t\"instructionSet\": \"" + systemInfo.InstructionSet.ToString() + "\","); Console.WriteLine("\t\"processorCount\": " + systemInfo.NumberOfProcessors.ToString() + ""); Console.WriteLine("}"); } return(0); } catch (Exception ex) { Console.WriteLine("{"); Console.WriteLine("\t\"success\": false,"); Console.WriteLine("\t\"message\": \"" + ex.Message.Trim().Replace("\"", "\\\"") + "\""); Console.WriteLine("}"); return(1); } } if (command != null) { return(showHelp(String.Format("Invalid command '{0}'", command))); } return(showHelp()); }
static void Main(string[] args) { int deviceIndex = 0; string iconFilePath = ""; string xapFilePath = ""; Guid appID = Guid.Empty; bool uninstallFirst = args.Contains("-uninstall"); bool awaitAppClose = args.Contains("-wait"); string root = Directory.GetCurrentDirectory(); if (args.Length < 1) { Usage(); ReadWait(); return; } else if (args.Contains("-devices")) { ListDevices(); ReadWait(); return; } else if (args.Length > 1 && args[1].StartsWith("-d:")) { deviceIndex = int.Parse(args[1].Substring(3)); } if (Directory.Exists(args[0])) { var info = new DirectoryInfo(args[0]); root = info.FullName; try { xapFilePath = Directory.GetFiles(root + @"\Bin\Debug", "*.xap").FirstOrDefault(); } catch (DirectoryNotFoundException) { try { xapFilePath = Directory.GetFiles(root + @"\Bin\Release", "*.xap").FirstOrDefault(); } catch (DirectoryNotFoundException) { Log(string.Format("Error: could not find project build directoy in {0}", root), true); Log("make sure your app has been successfully built before deploying.", true); } } } if (File.Exists(args[0])) { var info = new FileInfo(args[0]); if (info.Extension == ".xap") { root = info.DirectoryName; xapFilePath = info.FullName; } } appID = ReadAppId(root); if (appID == Guid.Empty) { return; // Logging of errors is done in ReadAppId } if (File.Exists(root + @"\ApplicationIcon.png")) { iconFilePath = root + @"\ApplicationIcon.png"; } else { Log(string.Format("Error: could not find application icon at {0}", root + @"\ApplicationIcon.png"), true); ReadWait(); return; } if (string.IsNullOrEmpty(xapFilePath)) { Log(string.Format("Error: could not find application .xap in folder {0}", root), true); ReadWait(); return; } ConnectableDevice deviceConn = GetDeviceAtIndex(deviceIndex); Log("Connecting to device :: " + deviceConn.Id + " : " + deviceConn.Name); try { IDevice device = deviceConn.Connect(); IRemoteApplication app = null; if (device.IsApplicationInstalled(appID)) { app = device.GetApplication(appID); if (uninstallFirst) { Log("Uninstalling app on " + deviceConn.Name); app.Uninstall(); Log("Installing app on " + deviceConn.Name); app = device.InstallApplication(appID, appID, "NormalApp", iconFilePath, xapFilePath); } else { Log("Updating app on " + deviceConn.Name); app.UpdateApplication("NormalApp", iconFilePath, xapFilePath); } } else { Log("Installing app on " + deviceConn.Name); app = device.InstallApplication(appID, appID, "NormalApp", iconFilePath, xapFilePath); } Log("Launching app on " + deviceConn.Name); app.Launch(); if (awaitAppClose) { // wait for the app to launch Thread.Sleep(4000); bool isExiting = false; string tempFileName = Path.GetTempFileName(); try { IRemoteIsolatedStorageFile isoFile = app.GetIsolatedStore(); int index = 0; while (!isExiting) //app.IsRunning()) // not implemented ... wtf? { char[] buffer = new char[1000]; isoFile.ReceiveFile((object)Path.DirectorySeparatorChar + "debugOutput.txt", tempFileName, true); using (StreamReader reader = System.IO.File.OpenText(tempFileName)) { try { int newLinesRead = 0; for (int lineNum = 0; ; lineNum++) { if (reader.Peek() > -1) { string str = reader.ReadLine(); if (lineNum >= index) { newLinesRead++; if (str == "EXIT") { isExiting = true; } Log(str); } } else { break; } } index += newLinesRead; } catch (Exception) { // at end of stream most likely, no worries, ... move along. } } Thread.Sleep(1000); } System.IO.File.Delete(tempFileName); } catch (Exception ex) { Log(ex.Message); } } // To Stop : //app.TerminateRunningInstances(); device.Disconnect(); ReadWait(); } catch (Exception ex) { Log("Error :: " + ex.Message, true); } }
static void Main(string[] args) { int deviceIndex = 0; string iconFilePath = ""; string xapFilePath = ""; Guid appID = Guid.Empty; string root = Directory.GetCurrentDirectory(); if (args.Length < 1) { Usage(); ReadWait(); return; } else if (args[0] == "-devices") { ListDevices(); ReadWait(); return; } else if (args.Length > 1 && args[1].StartsWith("-d:")) { deviceIndex = int.Parse(args[1].Substring(3)); } if (Directory.Exists(args[0])) { DirectoryInfo info = new DirectoryInfo(args[0]); root = info.FullName; } appID = ReadAppId(root); if (appID == Guid.Empty) { return; // Logging of errors is done in ReadAppId } if (File.Exists(root + @"\ApplicationIcon.png")) { iconFilePath = root + @"\ApplicationIcon.png"; } else { Log(string.Format("Error: could not find application icon at {0}", root + @"\ApplicationIcon.png"), true); ReadWait(); return; } xapFilePath = Directory.GetFiles(root + @"\Bin\Debug", "*.xap").FirstOrDefault(); if (string.IsNullOrEmpty(xapFilePath)) { Log(string.Format("Error: could not find application .xap in folder {0}", root), true); ReadWait(); return; } ConnectableDevice deviceConn = GetDeviceAtIndex(deviceIndex); Log("Connecting to device :: " + deviceConn.Id + " : " + deviceConn.Name); try { IDevice device = deviceConn.Connect(); IRemoteApplication app = null; if (device.IsApplicationInstalled(appID)) { Log("Uninstalling XAP from " + deviceConn.Name); app = device.GetApplication(appID); app.Uninstall(); } Log("Installing app on " + deviceConn.Name); app = device.InstallApplication(appID, appID, "NormalApp", iconFilePath, xapFilePath); Log("Launching app on " + deviceConn.Name); app.Launch(); // To Stop : //app.TerminateRunningInstances(); device.Disconnect(); ReadWait(); } catch (Exception ex) { Log("Error :: " + ex.Message, true); } }