PageRenderTime 73ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/platform/uwp/RhoAppRunner/Program.cs

http://github.com/rhomobile/rhodes
C# | 137 lines | 96 code | 16 blank | 25 comment | 15 complexity | 524b32b7e9899bb2a88b77b88a35f946 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, MIT, Apache-2.0, LGPL-2.1, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. /*------------------------------------------------------------------------
  2. * (The MIT License)
  3. *
  4. * Copyright (c) 2008-2011 Rhomobile, Inc.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. *
  24. * http://rhomobile.com
  25. *------------------------------------------------------------------------*/
  26. using System;
  27. using System.Globalization;
  28. using System.IO;
  29. using System.Linq;
  30. using Microsoft.SmartDevice.Connectivity.Interface;
  31. using Microsoft.SmartDevice.MultiTargeting.Connectivity;
  32. namespace RhoAppRunner
  33. {
  34. class Program
  35. {
  36. static int Main(string[] args)
  37. {
  38. MultiTargetingConnectivity UWPSDK = new MultiTargetingConnectivity(CultureInfo.CurrentCulture.LCID, false);
  39. bool useEmulator = true;
  40. ConnectableDevice cDevice = null;
  41. IDevice UWPDevice = null;
  42. if (args.Length < 5)
  43. {
  44. Console.WriteLine("Invalid parameters");
  45. return 1;
  46. }
  47. args[2] = args[2].Replace('/', '\\');
  48. args[3] = args[3].Replace('/', '\\');
  49. if (args.Length > 5)
  50. args[5] = args[5].Replace('/', '\\');
  51. if (args[4] == "dev")
  52. useEmulator = false;
  53. try
  54. {
  55. if (useEmulator)
  56. cDevice = UWPSDK.GetConnectableDevices(false).Last(d => (d.Name.StartsWith("Mobile ") && d.Name.Contains("2GB") && d.IsEmulator()));
  57. else
  58. cDevice = UWPSDK.GetConnectableDevices(false).First(d => d.Name.StartsWith("Device") || d.Name.StartsWith("Windows Phone 10 Device") ||
  59. d.Name.StartsWith("Windows Phone Device") || d.Name.StartsWith("Windows phone"));
  60. }
  61. catch
  62. {
  63. Console.WriteLine("Cannot find Windows Phone Emulator/Device.");
  64. return 3;
  65. }
  66. Console.WriteLine("Connecting to " + cDevice.Name);
  67. try
  68. {
  69. UWPDevice = cDevice.Connect(true);
  70. }
  71. catch
  72. {
  73. Console.WriteLine("Failed to connect to Windows Phone Emulator/Device.");
  74. return 4;
  75. }
  76. Console.WriteLine("Windows Phone Emulator/Device Connected...");
  77. Guid appID = Guid.Parse(args[0]);
  78. IRemoteApplication app;
  79. if (UWPDevice.IsApplicationInstalled(appID))
  80. {
  81. if (args[4] == "emulibs")
  82. {
  83. Console.WriteLine("Library is already installed");
  84. return 0;
  85. }
  86. Console.WriteLine("Updating sample APPX to Windows Phone Emulator/Device...");
  87. app = UWPDevice.GetApplication(appID);
  88. if (args.Length == 6)
  89. {
  90. var remoteIso = app.GetIsolatedStore();
  91. string targetDesktopFilePath = @args[5];
  92. try
  93. {
  94. remoteIso.ReceiveFile(Path.DirectorySeparatorChar + "rho" + Path.DirectorySeparatorChar + "rholog.txt", targetDesktopFilePath, true);
  95. }
  96. catch (Exception e)
  97. {
  98. Console.WriteLine("Can't receive rholog.txt from the " + (useEmulator ? "emulator" : "device") + ": " + e.Message);
  99. return 2;
  100. }
  101. return 0;
  102. }
  103. app.Uninstall();
  104. }
  105. Console.WriteLine("Installing sample APPX to Windows Phone Emulator/Device...");
  106. try
  107. {
  108. app = UWPDevice.InstallApplication(appID, appID, args[1], args[2], args[3]);
  109. Console.WriteLine("Sample APPX installed to Windows Phone Emulator...");
  110. Console.WriteLine("Launching sample app on Windows Phone Emulator...");
  111. app.Launch();
  112. Console.WriteLine("Launched sample app on Windows Phone Emulator...");
  113. }
  114. catch(Exception e)
  115. {
  116. Console.WriteLine("Launching error: " + e.Message);
  117. }
  118. return 0;
  119. }
  120. }
  121. }