Loading WindowsDevicePortalWrapper/TestApp/DevicePortalConnection.cs +10 −12 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ namespace TestApp { if (string.IsNullOrWhiteSpace(address)) { address = "localhost:10080"; address = "localhost:50443"; } this.Connection = new Uri(string.Format("{0}://{1}", this.GetUriScheme(address), address)); Loading Loading @@ -127,13 +127,12 @@ namespace TestApp } /// <summary> /// Creates and sets the device certificate from the raw data. /// Validates and sets the device certificate. /// </summary> /// <param name="certificateData">Raw device certificate data.</param> public void SetDeviceCertificate(byte[] certificateData) /// <param name="certificate">The device's root certificate.</param> public void SetDeviceCertificate(X509Certificate2 certificate) { X509Certificate2 cert = new X509Certificate2(certificateData); if (!cert.IssuerName.Name.Contains(DevicePortalCertificateIssuer)) if (!certificate.IssuerName.Name.Contains(DevicePortalCertificateIssuer)) { throw new DevicePortalException( (HttpStatusCode)0, Loading @@ -142,7 +141,7 @@ namespace TestApp "Failed to download device certificate"); } this.deviceCertificate = cert; this.deviceCertificate = certificate; } /// <summary> Loading @@ -157,7 +156,7 @@ namespace TestApp this.Connection = new Uri( string.Format( "{0}://{1}", "{0}://{1}:50443", uriScheme, this.Connection.Authority)); } Loading @@ -180,7 +179,7 @@ namespace TestApp // We take the first, non-169.x.x.x address we find that is not 0.0.0.0. if ((addressInfo.Address != "0.0.0.0") && !addressInfo.Address.StartsWith("169.")) { newConnection = new Uri(string.Format("{0}://{1}", this.GetUriScheme(addressInfo.Address, requiresHttps), addressInfo.Address)); newConnection = new Uri(string.Format("{0}://{1}:50443", this.GetUriScheme(addressInfo.Address, requiresHttps), addressInfo.Address)); //// TODO qualified name break; } Loading @@ -204,9 +203,8 @@ namespace TestApp string address, bool requiresHttps = true) { return (address.Contains("127.0.0.1") || address.Contains("localhost") || !requiresHttps) ? "http" : "https"; return "https"; // Desktop always uses https. //TODO: Replace with DNS-SD call. } } } WindowsDevicePortalWrapper/TestApp/Program.cs +44 −1 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ //---------------------------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Tools.WindowsDevicePortal; Loading Loading @@ -44,8 +45,10 @@ namespace TestApp } catch (Exception e) { // TODO: Make a usage display Console.WriteLine(e.Message); Console.WriteLine("Usage: TestApp.exe [-ip:IP_ADDRESS:PORT] -user:USERNAME -pwd:PASSWORD"); Console.WriteLine("\t TestApp.exe connects by default to localhost:50443"); Console.WriteLine("\t -ip:IP_ADDRESS:PORT, connect to Device Portal running at the specified address."); return; } Loading @@ -62,12 +65,52 @@ namespace TestApp getNameTask.Wait(); Console.WriteLine("Device name: " + getNameTask.Result); TestTagListing(portal); TestDeviceList(portal); while (true) { System.Threading.Thread.Sleep(0); } } /// <summary> /// Tests the DNS-SD APIs /// </summary> /// <param name="portal">DevicePortal object used for testing</param> private static void TestTagListing(DevicePortal portal) { Task<List<string>> getTagsTask = portal.GetServiceTags(); getTagsTask.Wait(); Console.Write("Service Tags: "); if (getTagsTask.Result.Count == 0) { Console.Write("<none>"); } foreach (string s in getTagsTask.Result) { Console.Write(s + ", "); } Console.WriteLine(string.Empty); } /// <summary> /// Tests the DeviceManager APIs /// </summary> /// <param name="portal">DevicePortal object used for testing</param> private static void TestDeviceList(DevicePortal portal) { Task<List<DevicePortal.Device>> getdeviceListTask = portal.GetDeviceList(); getdeviceListTask.Wait(); List<DevicePortal.Device> deviceList = getdeviceListTask.Result; DevicePortal.Device device = deviceList.Find(x => x.FriendlyName != null); //not all Devices come with a friendly name Console.WriteLine("First Device: {0}", device.Description); } /// <summary> /// Parses the application's command line. /// </summary> Loading WindowsDevicePortalWrapper/TestAppHL/DevicePortalConnection.cs +5 −6 Original line number Diff line number Diff line Loading @@ -127,13 +127,12 @@ namespace TestApp } /// <summary> /// Creates and sets the device certificate from the raw data. /// Validates and sets the device certificate. /// </summary> /// <param name="certificateData">Raw device certificate data.</param> public void SetDeviceCertificate(byte[] certificateData) /// <param name="certificate">The device's root certificate.</param> public void SetDeviceCertificate(X509Certificate2 certificate) { X509Certificate2 cert = new X509Certificate2(certificateData); if (!cert.IssuerName.Name.Contains(DevicePortalCertificateIssuer)) if (!certificate.IssuerName.Name.Contains(DevicePortalCertificateIssuer)) { throw new DevicePortalException( (HttpStatusCode)0, Loading @@ -142,7 +141,7 @@ namespace TestApp "Failed to download device certificate"); } this.deviceCertificate = cert; this.deviceCertificate = certificate; } /// <summary> Loading WindowsDevicePortalWrapper/TestAppHL/Program.cs +19 −3 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ //---------------------------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.Tools.WindowsDevicePortal; Loading @@ -17,6 +18,11 @@ namespace TestApp /// </summary> internal class Program : IDisposable { /// <summary> /// Usage string /// </summary> private const string GeneralUsageMessage = "Usage: /ip:<system-ip or hostname> /user:<WDP username> /pwd:<WDP password> [/ssid:<network ssid> /key:<network key>]"; /// <summary> /// The IP address of the device. /// </summary> Loading Loading @@ -66,18 +72,25 @@ namespace TestApp } catch (Exception e) { // TODO: Make a usage display Console.WriteLine(e.Message); Console.WriteLine(); Console.WriteLine(GeneralUsageMessage); return; } DevicePortal portal = new DevicePortal(new DevicePortalConnection(app.ipAddress, app.userName, app.password)); DevicePortal portal = new DevicePortal( new DevicePortalConnection( app.ipAddress, app.userName, app.password)); portal.ConnectionStatus += app.ConnectionStatusHandler; portal.AppInstallStatus += app.AppInstallStatusHandler; app.mreConnected.Reset(); Console.WriteLine("Connecting..."); Task t = portal.Connect(app.ssid, app.key); Task t = portal.Connect( app.ssid, app.key); app.mreConnected.WaitOne(); Console.WriteLine("Connected to: " + portal.Address); Loading @@ -92,6 +105,9 @@ namespace TestApp getIpdTask.Wait(); Console.WriteLine("IPD: " + getIpdTask.Result.ToString()); Task setIpdTask = portal.SetInterPupilaryDistance(67.5f); setIpdTask.Wait(); Task<BatteryState> batteryTask = portal.GetBatteryState(); batteryTask.Wait(); Console.WriteLine("Battery level: " + batteryTask.Result.Level); Loading WindowsDevicePortalWrapper/TestAppIoT/DevicePortalConnection.cs +3 −3 Original line number Diff line number Diff line Loading @@ -121,10 +121,10 @@ namespace TestAppIoT } /// <summary> /// Creates and sets the device certificate from the raw data. /// Validates and sets the device certificate. /// </summary> /// <param name="certificateData">Raw device certificate data.</param> public void SetDeviceCertificate(byte[] certificateData) /// <param name="certificate">The device's root certificate.</param> public void SetDeviceCertificate(System.Security.Cryptography.X509Certificates.X509Certificate2 certificate) { throw new NotSupportedException("The current version of TestAppIoT does not support device certificates"); } Loading Loading
WindowsDevicePortalWrapper/TestApp/DevicePortalConnection.cs +10 −12 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ namespace TestApp { if (string.IsNullOrWhiteSpace(address)) { address = "localhost:10080"; address = "localhost:50443"; } this.Connection = new Uri(string.Format("{0}://{1}", this.GetUriScheme(address), address)); Loading Loading @@ -127,13 +127,12 @@ namespace TestApp } /// <summary> /// Creates and sets the device certificate from the raw data. /// Validates and sets the device certificate. /// </summary> /// <param name="certificateData">Raw device certificate data.</param> public void SetDeviceCertificate(byte[] certificateData) /// <param name="certificate">The device's root certificate.</param> public void SetDeviceCertificate(X509Certificate2 certificate) { X509Certificate2 cert = new X509Certificate2(certificateData); if (!cert.IssuerName.Name.Contains(DevicePortalCertificateIssuer)) if (!certificate.IssuerName.Name.Contains(DevicePortalCertificateIssuer)) { throw new DevicePortalException( (HttpStatusCode)0, Loading @@ -142,7 +141,7 @@ namespace TestApp "Failed to download device certificate"); } this.deviceCertificate = cert; this.deviceCertificate = certificate; } /// <summary> Loading @@ -157,7 +156,7 @@ namespace TestApp this.Connection = new Uri( string.Format( "{0}://{1}", "{0}://{1}:50443", uriScheme, this.Connection.Authority)); } Loading @@ -180,7 +179,7 @@ namespace TestApp // We take the first, non-169.x.x.x address we find that is not 0.0.0.0. if ((addressInfo.Address != "0.0.0.0") && !addressInfo.Address.StartsWith("169.")) { newConnection = new Uri(string.Format("{0}://{1}", this.GetUriScheme(addressInfo.Address, requiresHttps), addressInfo.Address)); newConnection = new Uri(string.Format("{0}://{1}:50443", this.GetUriScheme(addressInfo.Address, requiresHttps), addressInfo.Address)); //// TODO qualified name break; } Loading @@ -204,9 +203,8 @@ namespace TestApp string address, bool requiresHttps = true) { return (address.Contains("127.0.0.1") || address.Contains("localhost") || !requiresHttps) ? "http" : "https"; return "https"; // Desktop always uses https. //TODO: Replace with DNS-SD call. } } }
WindowsDevicePortalWrapper/TestApp/Program.cs +44 −1 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ //---------------------------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Tools.WindowsDevicePortal; Loading Loading @@ -44,8 +45,10 @@ namespace TestApp } catch (Exception e) { // TODO: Make a usage display Console.WriteLine(e.Message); Console.WriteLine("Usage: TestApp.exe [-ip:IP_ADDRESS:PORT] -user:USERNAME -pwd:PASSWORD"); Console.WriteLine("\t TestApp.exe connects by default to localhost:50443"); Console.WriteLine("\t -ip:IP_ADDRESS:PORT, connect to Device Portal running at the specified address."); return; } Loading @@ -62,12 +65,52 @@ namespace TestApp getNameTask.Wait(); Console.WriteLine("Device name: " + getNameTask.Result); TestTagListing(portal); TestDeviceList(portal); while (true) { System.Threading.Thread.Sleep(0); } } /// <summary> /// Tests the DNS-SD APIs /// </summary> /// <param name="portal">DevicePortal object used for testing</param> private static void TestTagListing(DevicePortal portal) { Task<List<string>> getTagsTask = portal.GetServiceTags(); getTagsTask.Wait(); Console.Write("Service Tags: "); if (getTagsTask.Result.Count == 0) { Console.Write("<none>"); } foreach (string s in getTagsTask.Result) { Console.Write(s + ", "); } Console.WriteLine(string.Empty); } /// <summary> /// Tests the DeviceManager APIs /// </summary> /// <param name="portal">DevicePortal object used for testing</param> private static void TestDeviceList(DevicePortal portal) { Task<List<DevicePortal.Device>> getdeviceListTask = portal.GetDeviceList(); getdeviceListTask.Wait(); List<DevicePortal.Device> deviceList = getdeviceListTask.Result; DevicePortal.Device device = deviceList.Find(x => x.FriendlyName != null); //not all Devices come with a friendly name Console.WriteLine("First Device: {0}", device.Description); } /// <summary> /// Parses the application's command line. /// </summary> Loading
WindowsDevicePortalWrapper/TestAppHL/DevicePortalConnection.cs +5 −6 Original line number Diff line number Diff line Loading @@ -127,13 +127,12 @@ namespace TestApp } /// <summary> /// Creates and sets the device certificate from the raw data. /// Validates and sets the device certificate. /// </summary> /// <param name="certificateData">Raw device certificate data.</param> public void SetDeviceCertificate(byte[] certificateData) /// <param name="certificate">The device's root certificate.</param> public void SetDeviceCertificate(X509Certificate2 certificate) { X509Certificate2 cert = new X509Certificate2(certificateData); if (!cert.IssuerName.Name.Contains(DevicePortalCertificateIssuer)) if (!certificate.IssuerName.Name.Contains(DevicePortalCertificateIssuer)) { throw new DevicePortalException( (HttpStatusCode)0, Loading @@ -142,7 +141,7 @@ namespace TestApp "Failed to download device certificate"); } this.deviceCertificate = cert; this.deviceCertificate = certificate; } /// <summary> Loading
WindowsDevicePortalWrapper/TestAppHL/Program.cs +19 −3 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ //---------------------------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.Tools.WindowsDevicePortal; Loading @@ -17,6 +18,11 @@ namespace TestApp /// </summary> internal class Program : IDisposable { /// <summary> /// Usage string /// </summary> private const string GeneralUsageMessage = "Usage: /ip:<system-ip or hostname> /user:<WDP username> /pwd:<WDP password> [/ssid:<network ssid> /key:<network key>]"; /// <summary> /// The IP address of the device. /// </summary> Loading Loading @@ -66,18 +72,25 @@ namespace TestApp } catch (Exception e) { // TODO: Make a usage display Console.WriteLine(e.Message); Console.WriteLine(); Console.WriteLine(GeneralUsageMessage); return; } DevicePortal portal = new DevicePortal(new DevicePortalConnection(app.ipAddress, app.userName, app.password)); DevicePortal portal = new DevicePortal( new DevicePortalConnection( app.ipAddress, app.userName, app.password)); portal.ConnectionStatus += app.ConnectionStatusHandler; portal.AppInstallStatus += app.AppInstallStatusHandler; app.mreConnected.Reset(); Console.WriteLine("Connecting..."); Task t = portal.Connect(app.ssid, app.key); Task t = portal.Connect( app.ssid, app.key); app.mreConnected.WaitOne(); Console.WriteLine("Connected to: " + portal.Address); Loading @@ -92,6 +105,9 @@ namespace TestApp getIpdTask.Wait(); Console.WriteLine("IPD: " + getIpdTask.Result.ToString()); Task setIpdTask = portal.SetInterPupilaryDistance(67.5f); setIpdTask.Wait(); Task<BatteryState> batteryTask = portal.GetBatteryState(); batteryTask.Wait(); Console.WriteLine("Battery level: " + batteryTask.Result.Level); Loading
WindowsDevicePortalWrapper/TestAppIoT/DevicePortalConnection.cs +3 −3 Original line number Diff line number Diff line Loading @@ -121,10 +121,10 @@ namespace TestAppIoT } /// <summary> /// Creates and sets the device certificate from the raw data. /// Validates and sets the device certificate. /// </summary> /// <param name="certificateData">Raw device certificate data.</param> public void SetDeviceCertificate(byte[] certificateData) /// <param name="certificate">The device's root certificate.</param> public void SetDeviceCertificate(System.Security.Cryptography.X509Certificates.X509Certificate2 certificate) { throw new NotSupportedException("The current version of TestAppIoT does not support device certificates"); } Loading