You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2013/03/15 23:16:41 UTC

[1/2] git commit: add WP8 tooling to deploy apps from the command line

add WP8 tooling to deploy apps from the command line


Project: http://git-wip-us.apache.org/repos/asf/cordova-wp8/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp8/commit/5f9fe306
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp8/tree/5f9fe306
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp8/diff/5f9fe306

Branch: refs/heads/master
Commit: 5f9fe306a7ec9b3fbb8c6d882a5383964fcb1131
Parents: 970cf90
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Fri Mar 15 15:13:31 2013 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Fri Mar 15 15:13:31 2013 -0700

----------------------------------------------------------------------
 .../CordovaDeploy/CordovaDeploy.csproj             |   27 ++-
 tooling/CordovaDeploy/CordovaDeploy/Program.cs     |  279 ++++++++++++---
 tooling/CordovaDeploy/CordovaDeploy/app.config     |    3 +
 3 files changed, 255 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/5f9fe306/tooling/CordovaDeploy/CordovaDeploy/CordovaDeploy.csproj
----------------------------------------------------------------------
diff --git a/tooling/CordovaDeploy/CordovaDeploy/CordovaDeploy.csproj b/tooling/CordovaDeploy/CordovaDeploy/CordovaDeploy.csproj
index 33da0da..a52b532 100644
--- a/tooling/CordovaDeploy/CordovaDeploy/CordovaDeploy.csproj
+++ b/tooling/CordovaDeploy/CordovaDeploy/CordovaDeploy.csproj
@@ -28,8 +28,9 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>CordovaDeploy</RootNamespace>
     <AssemblyName>CordovaDeploy</AssemblyName>
-    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
-    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <TargetFrameworkProfile>
+    </TargetFrameworkProfile>
     <FileAlignment>512</FileAlignment>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
@@ -41,6 +42,7 @@
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
     <PlatformTarget>x86</PlatformTarget>
@@ -50,11 +52,23 @@
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
+  </PropertyGroup>
+  <PropertyGroup>
+    <StartupObject>CordovaDeploy.DeployTool</StartupObject>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="Microsoft.Smartdevice.Connectivity, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+    <Reference Include="Microsoft.Smartdevice.Connectivity, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\..\..\..\..\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SmartDevice.Connectivity\v4.0_11.0.0.0__b03f5f7f11d50a3a\Microsoft.Smartdevice.Connectivity.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.Smartdevice.Connectivity.Interface, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\..\..\..\..\Program Files (x86)\Common Files\microsoft shared\Phone Tools\CoreCon\10.0\Bin\Microsoft.Smartdevice.Connectivity.dll</HintPath>
+      <HintPath>..\..\..\..\..\..\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SmartDevice.Connectivity.Interface\v4.0_11.0.0.0__b03f5f7f11d50a3a\Microsoft.Smartdevice.Connectivity.Interface.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.Smartdevice.MultiTargeting.Connectivity, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\..\..\..\..\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SmartDevice.MultiTargeting.Connectivity\v4.0_11.0.0.0__b03f5f7f11d50a3a\Microsoft.Smartdevice.MultiTargeting.Connectivity.dll</HintPath>
     </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
@@ -68,6 +82,9 @@
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
+  <ItemGroup>
+    <None Include="app.config" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
@@ -76,4 +93,4 @@
   <Target Name="AfterBuild">
   </Target>
   -->
-</Project>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/5f9fe306/tooling/CordovaDeploy/CordovaDeploy/Program.cs
----------------------------------------------------------------------
diff --git a/tooling/CordovaDeploy/CordovaDeploy/Program.cs b/tooling/CordovaDeploy/CordovaDeploy/Program.cs
index 3414101..ad35ee6 100644
--- a/tooling/CordovaDeploy/CordovaDeploy/Program.cs
+++ b/tooling/CordovaDeploy/CordovaDeploy/Program.cs
@@ -21,13 +21,17 @@ using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using Microsoft.SmartDevice.Connectivity;
 using System.Collections.ObjectModel;
 using System.Diagnostics;
 using System.IO;
 using System.Xml.XPath;
 using System.Xml;
 using System.Xml.Linq;
+using System.Globalization;
+// Windows Phone Emulator Libraries
+using Microsoft.SmartDevice.Connectivity;
+using Microsoft.SmartDevice.Connectivity.Interface;
+using Microsoft.SmartDevice.MultiTargeting.Connectivity;
 
 
 namespace CordovaDeploy
@@ -46,13 +50,17 @@ namespace CordovaDeploy
             Log("  CordovaDeploy -devices");
             Log("  CordovaDeploy Bin/Debug");
             Log("  CordovaDeploy Bin/Release -d:1");
-
         }
 
         static void ReadWait()
         {
-            //Console.WriteLine("\nPress ENTER to continue...");
-            //Console.Read();
+            // This is used when running in Visual Studio, the Command Window is created at launch, and disappears at the 
+            // end of the program run, this let's us see the output before the window is closed.
+
+            /*
+            Console.WriteLine("\nPress ENTER to continue...");
+            Console.Read();
+            */
         }
 
         static void Log(string msg)
@@ -64,7 +72,7 @@ namespace CordovaDeploy
         static Guid ReadAppId(string root)
         {
             Guid appID = Guid.Empty;
-            string manifestFilePath = root + @"\WMAppManifest.xml";
+            string manifestFilePath = root + @"\Properties\WMAppManifest.xml";
 
             if (File.Exists(manifestFilePath))
             {
@@ -84,27 +92,29 @@ namespace CordovaDeploy
             {
                 Log(string.Format("Error: the file {0} does not exist", manifestFilePath));
             }
-
-
             return appID;
         }
 
-
-
         static void ListDevices()
         {
-            // Get CoreCon WP7 SDK
-            DatastoreManager dsmgrObj = new DatastoreManager(1033);
-            Platform WP7SDK = dsmgrObj.GetPlatforms().Single(p => p.Name == "Windows Phone 7");
-            Collection<Device> devices = WP7SDK.GetDevices();
-            for (int index = 0; index < devices.Count; index++)
+            MultiTargetingConnectivity mtConn = new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID);
+            Collection<ConnectableDevice> deviceList = mtConn.GetConnectableDevices();
+
+            for (int index = 0; index < deviceList.Count; index++)
             {
-                Device d = devices[index];
+                ConnectableDevice d = deviceList[index];
                 string info = string.Format("{0} : {1} : {2}", index.ToString(), d.Id, d.Name);
                 Log(info);
             }
         }
 
+        static ConnectableDevice GetDeviceAtIndex(int index)
+        {
+            MultiTargetingConnectivity mtConn = new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID);
+            Collection<ConnectableDevice> deviceList = mtConn.GetConnectableDevices();
+            return deviceList[index];
+        }
+
         static void Main(string[] args)
         {
             int deviceIndex = 0;
@@ -124,9 +134,10 @@ namespace CordovaDeploy
             else if (args[0] == "-devices")
             {
                 ListDevices();
+                ReadWait();
                 return;
             }
-            else if (args[1].StartsWith("-d:"))
+            else if (args.Length > 1 && args[1].StartsWith("-d:"))
             {
                 deviceIndex = int.Parse(args[1].Substring(3));
             }
@@ -141,8 +152,7 @@ namespace CordovaDeploy
             appID = ReadAppId(root);
             if (appID == Guid.Empty)
             {
-                // Logging of errors is done in ReadAppId
-                return;
+                return;    // Logging of errors is done in ReadAppId
             }
 
             if (File.Exists(root + @"\ApplicationIcon.png"))
@@ -156,8 +166,7 @@ namespace CordovaDeploy
                 return;
             }
 
-
-            xapFilePath = Directory.GetFiles(root, "*.xap").FirstOrDefault();
+            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));
@@ -165,55 +174,227 @@ namespace CordovaDeploy
                 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);
 
-            // Get CoreCon WP7 SDK
-            DatastoreManager dsmgrObj = new DatastoreManager(1033);
-            Collection<Platform> WP7SDKs = dsmgrObj.GetPlatforms();
-            Platform WP7SDK = dsmgrObj.GetPlatforms().Single(p => p.Name == "Windows Phone 7");
+                Log("Launching app on " + deviceConn.Name);
+                app.Launch();
 
-            Collection<Device> devices = null;
+                // To Stop :
+                //app.TerminateRunningInstances();
 
-            devices = WP7SDK.GetDevices();
+                device.Disconnect();
 
-            //// Get Emulator / Device
-            Device WP7Device = devices[deviceIndex];
+                ReadWait();
 
-            if (WP7Device != null)
+            }
+            catch (Exception ex)
             {
-                RemoteApplication app;
-                bool isConnected = WP7Device.IsConnected();
+                Log("Error :: " + ex.Message);
+            }
+        }
+
+        // To read and write ISO storage files!! :
+        /*
+        try
+        {
+            IRemoteIsolatedStorageFile isoStore = app.GetIsolatedStore();
+            remoteIsolatedStorageFile.ReceiveFile("sourcePath", "destPath", true);
+        }
+        catch (Exception ex) { }
+        */
+
+    }
+    class Program
+    {
+        static void Usage()
+        {
+            Log("Usage: CordovaDeploy [ -devices  BuildOutputPath -d:DeviceIndex ]");
+            Log("    -devices : lists the devices and exits");
+            Log("    BuildOutputPath : path to the built application, typically Bin/Debug/ or Bin/Release/");
+            Log("    -d : index of the device to deploy, default is 0 ");
+            Log("examples:");
+            Log("  CordovaDeploy -devices");
+            Log("  CordovaDeploy Bin/Debug");
+            Log("  CordovaDeploy Bin/Release -d:1");
+        }
+
+        static void ReadWait()
+        {
+            // This is used when running in Visual Studio, the Command Window is created at launch, and disappears at the 
+            // end of the program run, this let's us see the output before the window is closed.
 
-                Debug.WriteLine(WP7Device.ToString());
+            /*
+            Console.WriteLine("\nPress ENTER to continue...");
+            Console.Read();
+            */
+        }
 
-                if (!isConnected)
+        static void Log(string msg)
+        {
+            Debug.WriteLine(msg);
+            Console.Error.WriteLine(msg);
+        }
+
+        static Guid ReadAppId(string root)
+        {
+            Guid appID = Guid.Empty;
+            string manifestFilePath = root + @"\Properties\WMAppManifest.xml";
+
+            if (File.Exists(manifestFilePath))
+            {
+                XDocument xdoc = XDocument.Load(manifestFilePath);
+                var appNode = xdoc.Root.Descendants("App").FirstOrDefault();
+                if (appNode != null)
+                {
+                    string guidStr = appNode.Attribute("ProductID").Value;
+                    appID = new Guid(guidStr);
+                }
+                else
                 {
-                    try
-                    {
-                        WP7Device.Connect();
-                    }
-                    catch (Exception ex)
-                    {
-                        Console.WriteLine("Error: " + ex.Message);
-                        ReadWait();
-                        return;
-                    }
+                    Log(string.Format("Unable to find appID, expected to find an App.ProductID property defined in the file {0}", manifestFilePath));
                 }
+            }
+            else
+            {
+                Log(string.Format("Error: the file {0} does not exist", manifestFilePath));
+            }
+            return appID;
+        }
 
-                if (WP7Device.IsApplicationInstalled(appID))
+        static void ListDevices()
+        {
+            MultiTargetingConnectivity mtConn = new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID);
+            Collection<ConnectableDevice> deviceList = mtConn.GetConnectableDevices();
+
+            for (int index = 0; index < deviceList.Count; index++)
+            {
+                ConnectableDevice d = deviceList[index];
+                string info = string.Format("{0} : {1} : {2}", index.ToString(), d.Id, d.Name);
+                Log(info);
+            }
+        }
+
+        static ConnectableDevice GetDeviceAtIndex(int index)
+        {
+            MultiTargetingConnectivity mtConn = new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID);
+            Collection<ConnectableDevice> deviceList = mtConn.GetConnectableDevices();
+            return deviceList[index];
+        }
+
+        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"));
+                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));
+                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 " + WP7Device.Name);
-                    app = WP7Device.GetApplication(appID);
+                    Log("Uninstalling XAP from " + deviceConn.Name);
+                    app = device.GetApplication(appID);
                     app.Uninstall();
                 }
 
-                Log("Installing app on " + WP7Device.Name);
-                app = WP7Device.InstallApplication(appID, appID, "NormalApp", iconFilePath, xapFilePath);
+                Log("Installing app on " + deviceConn.Name);
+                app = device.InstallApplication(appID, appID, "NormalApp", iconFilePath, xapFilePath);
 
-                Log("Launching app on " + WP7Device.Name);
+                Log("Launching app on " + deviceConn.Name);
                 app.Launch();
 
+                // To Stop :
+                //app.TerminateRunningInstances();
+
+                device.Disconnect();
+
                 ReadWait();
+
             }
+            catch (Exception ex)
+            {
+                Log("Error :: " + ex.Message);
+            }
+        }
+
+        // To read and write ISO storage files!! :
+        /*
+        try
+        {
+            IRemoteIsolatedStorageFile isoStore = app.GetIsolatedStore();
+            remoteIsolatedStorageFile.ReceiveFile("sourcePath", "destPath", true);
         }
+        catch (Exception ex) { }
+        */ 
     }
 }

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/5f9fe306/tooling/CordovaDeploy/CordovaDeploy/app.config
----------------------------------------------------------------------
diff --git a/tooling/CordovaDeploy/CordovaDeploy/app.config b/tooling/CordovaDeploy/CordovaDeploy/app.config
new file mode 100644
index 0000000..c5e1dae
--- /dev/null
+++ b/tooling/CordovaDeploy/CordovaDeploy/app.config
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>