5

我对 Windows Phone 开发非常陌生。我想开发一个应用程序,当我将 Windows 8 手机连接到我的笔记本电脑时将启动它。我正在学习本教程(http://justinangel.net/WindowsPhone7EmulatorAutomation)并且能够连接到我的 Windows 7 手机/模拟器,但我无法连接到我的 Windows 8 手机或模拟器。有没有其他方法可以连接到 Windows 8 手机?

请让我知道是否有任何可能的解决方案,

谢谢

4

2 回答 2

7

我还没有机会更新这篇博文。Delvis Gomez(我的一位同事)更新了最终的代码示例并可以自由分发。将来我会为 WP8 更新该博客文章,但与此同时,这里有一个关于如何自动化 WP8 模拟器的很好记录的代码片段。

此外,请确保添加对所需的新 DLL 的引用,例如 Microsoft.SmartDevice.MultiTargeting.Connectivity。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using System.Reflection;

// Libraries needed to connect to the Windows Phone X Emulator
using Microsoft.SmartDevice.Connectivity;
using Microsoft.SmartDevice.Connectivity.Interface;
using Microsoft.SmartDevice.MultiTargeting.Connectivity;
using System.Globalization;
using System.Collections.ObjectModel;


namespace AutomatedUnitTestDriver
{
    class Program
    {
        static void Main(string[] args)
        {
            MultiTargetingConnectivity connectivity = new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID);

            // Get a connectable device for a specific Device ID (from the CoreCon datastore)
            string deviceId = "5E7661DF-D928-40ff-B747-A4B1957194F9";
            ConnectableDevice connectableDevice = connectivity.GetConnectableDevice(deviceId);
            Console.WriteLine("Found Connectable Device \'" + connectableDevice.Name + "\' for Device id {" + connectableDevice.Id + "}.");

            // Connect to the Device
            Console.WriteLine("Connecting to Device...");
            IDevice iDevice = connectableDevice.Connect();
            Console.WriteLine("Done!");

            // Check if the application is already install, if it is remove it (From WMAppManifect.xml)
            Guid appID = new Guid("{b6635769-b7ac-41a5-915d-5a7b0ae34481}"); 

            if (iDevice.IsApplicationInstalled(appID))
            {
                Console.WriteLine("Uninstalling application...");
                iDevice.GetApplication(appID).Uninstall();
                Console.WriteLine("Done!");
            }

            Guid productId = appID;
            Guid instanceId = appID;
            string applicationGenre = "NormalApp";
            string iconPath = @"C:\Share\LatestAPI\TestCode\Automated\AutomatedUnitTests\Bin\Debug\ApplicationIcon.png";
            string xapPackage = @"C:\Share\LatestAPI\TestCode\Automated\AutomatedUnitTests\Bin\Debug\AutomatedUnitTests.xap";

            // Install the application 
            Console.WriteLine("Installing the application...");
            IRemoteApplication remoteApplication = iDevice.InstallApplication(appID, appID, applicationGenre, iconPath, xapPackage);
            Console.WriteLine("Done!");

            // Launch the application
            Console.WriteLine("Starting the application...");
            remoteApplication.Launch();

            int startStopWaitTime = 1000;   // msec
            int executionWaitTime = 180000; // msec

            // Note that IRemoteApplication has a 'IsRunning' method but it is not implemented.
            // So, for the moment we sleep few msec.
            Thread.Sleep(startStopWaitTime);
            Console.WriteLine("Done!");

            // Allow application to complete 
            Console.WriteLine("Application is running! Waiting few seconds...");
            Thread.Sleep(executionWaitTime);

            try
            {
                IRemoteIsolatedStorageFile remoteIsolatedStorageFile = remoteApplication.GetIsolatedStore();
                string sourceDeviceFilePath = (object)Path.DirectorySeparatorChar + "TestResults.trx";
                string targetDesktopFilePath = @"C:\Share\LatestAPI\TestCode\Automated\AutomatedUnitTests\Bin\Debug\" + "TestResults.trx";
                remoteIsolatedStorageFile.ReceiveFile(sourceDeviceFilePath, targetDesktopFilePath,true);
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception \'" + exception.Message + "\' reading file from device.");
            }

            // Terminate application
            Console.WriteLine("Terminating the application...");
            remoteApplication.TerminateRunningInstances();

            Thread.Sleep(startStopWaitTime);
            Console.WriteLine("\nDone!");

            // Disconnect from the emulator
            Console.WriteLine("Disconnecting Device...");
            iDevice.Disconnect();
            Console.WriteLine("\nDone!");
        }
    }
}
于 2012-11-17T10:32:25.767 回答
0

我在实施接受的解决方案时遇到了麻烦,因为我缺少这些命名空间的引用:

Microsoft.SmartDevice.Connectivity.Interface
Microsoft.SmartDevice.MultiTargeting.Connectivity

这是我找到它们的地方:

C:\Windows\Microsoft.NET\assembly\GAC_MSIL\
   Microsoft.SmartDevice.Connectivity.Interface\
   v4.0_11.0.0.0__b03f5f7f11d50a3a\
   Microsoft.Smartdevice.Connectivity.Interface.dll

C:\Windows\Microsoft.NET\assembly\GAC_MSIL\
   Microsoft.SmartDevice.MultiTargeting.Connectivity\
   v4.0_11.0.0.0__b03f5f7f11d50a3a\
   Microsoft.Smartdevice.MultiTargeting.Connectivity.dll

请注意,这些路径,尤其是v4.0_11.0.0.0__b03f5f7f11d50a3a部件,在您的系统上可能会有所不同。在您的项目中添加对这些 DLL 的引用,一切都应该正常工作。

于 2013-09-18T19:38:21.060 回答