Loading Samples/DeviceLab/DeviceLab.csproj +0 −2 Original line number Diff line number Diff line Loading @@ -64,7 +64,6 @@ <Compile Include="ViewModels\DiagnosticSinks.cs" /> <Compile Include="ViewModels\GenericDevicePortalConnectionFactory.cs" /> <Compile Include="ViewModels\ObservableCommandQueue.cs" /> <Compile Include="ViewModels\XboxDevicePortalConnectionFactory.cs" /> <Compile Include="Views\DeviceCollectionView.xaml.cs"> <DependentUpon>DeviceCollectionView.xaml</DependentUpon> </Compile> Loading @@ -78,7 +77,6 @@ <DependentUpon>NumberEntryBox.xaml</DependentUpon> </Compile> <Compile Include="Controls\SelectionListBox.cs" /> <Compile Include="XboxDevicePortalConnection.cs" /> <Page Include="Controls\BindablePassword.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> Loading Samples/DeviceLab/ViewModels/DevicePortalCommandModel.cs +5 −5 Original line number Diff line number Diff line Loading @@ -11,9 +11,9 @@ namespace DeviceLab { /// <summary> /// Base class for ViewModel classes that wrap a DevicePortal object. /// Provides status for pending DevicePortal operations and an /// ObservableCommandQueue to enable composing commands using /// CommandSequences. /// Provides status for pending DevicePortal operations, diagnostic /// output support, an ObservableCommandQueue to enable composing /// commands using CommandSequences, etc. /// </summary> public class DevicePortalCommandModel : BindableBase { Loading Loading @@ -231,8 +231,8 @@ namespace DeviceLab protected virtual void ReportException(string commandName, Exception exn) { this.OutputDiagnosticString("Exception during {0} command:\n", commandName); this.OutputDiagnosticString(exn.Message); this.OutputDiagnosticString(exn.StackTrace); this.OutputDiagnosticString(exn.Message + "\n"); this.OutputDiagnosticString(exn.StackTrace + "\n"); // Clear the command queue to prevent executing any more commands this.OutputDiagnosticString("Clearing any queued commands\n"); Loading Samples/DeviceLab/ViewModels/DevicePortalViewModel.cs +59 −27 Original line number Diff line number Diff line Loading @@ -9,6 +9,9 @@ using System.Threading.Tasks; using System.Windows.Input; using Microsoft.Tools.WindowsDevicePortal; using Prism.Commands; using System.Security.Cryptography.X509Certificates; using System.Windows; using System.Net.Security; namespace DeviceLab { Loading @@ -29,7 +32,11 @@ namespace DeviceLab public DevicePortalViewModel(DevicePortal portal, IDiagnosticSink diags) : base(portal, diags) { this.ConnectionRetryAttempts = 5; // Add additional handling for untrusted certs. this.Portal.UnvalidatedCert += DoCertValidation; // Default number of retry attempts to make when reestablishing the connection this.ConnectionRetryAttempts = 3; } #endregion // Cosntructors Loading Loading @@ -383,6 +390,7 @@ namespace DeviceLab this.OutputDiagnosticString("Connection failed after {0} tries.\n", numTries); } }; this.Portal.ConnectionStatus += handler; this.Ready = false; Loading @@ -393,7 +401,12 @@ namespace DeviceLab await this.Portal.Connect(); ++numTries; } while (this.Portal.ConnectionHttpStatusCode != HttpStatusCode.OK && numTries < this.ConnectionRetryAttempts); while (this.Portal.ConnectionHttpStatusCode != HttpStatusCode.OK && numTries <= this.ConnectionRetryAttempts); if(this.Portal.ConnectionHttpStatusCode !=HttpStatusCode.OK) { throw new Exception(string.Format("Unable to connect after {0} tries.", numTries - 1)); } } catch (Exception exn) { Loading Loading @@ -450,7 +463,7 @@ namespace DeviceLab try { this.Portal.SystemPerfMessageReceived += this.OnSystemPerfReceived; await Task.Run(this.StartListeningHelper); await this.Portal.StartListeningForSystemPerf(); } catch (Exception exn) { Loading @@ -459,17 +472,6 @@ namespace DeviceLab this.Ready = true; } /// <summary> /// StartListeningForSystemPerf would deadlock when called from the main thread. /// This helper exists so that the asynchronous operation can be run on the /// thread pool and avoid the deadlock /// </summary> /// <returns>A task the captures the continuation of the start listening call</returns> private async Task StartListeningHelper() { await this.Portal.StartListeningForSystemPerf().ConfigureAwait(false); } #endregion // StartListeningForSystemPerfCommand #region StopListeningForSystemPerfCommand Loading Loading @@ -517,8 +519,7 @@ namespace DeviceLab try { this.Portal.SystemPerfMessageReceived -= this.OnSystemPerfReceived; await this.StopListeningHelper(); await this.StopListeningHelper(); await this.Portal.StopListeningForSystemPerf(); } catch (Exception exn) { Loading @@ -527,17 +528,6 @@ namespace DeviceLab this.Ready = true; } /// <summary> /// StopListeningForSystemPerf would deadlock when called from the main thread. /// This helper exists so that the asynchronous operation can be run on the /// thread pool and avoid the deadlock /// </summary> /// <returns>Task the captures the continuation of the asynchronous action</returns> private async Task StopListeningHelper() { await this.Portal.StopListeningForSystemPerf(); } #endregion // StopListeningForSystemPerfCommand #endregion // Commands Loading @@ -551,5 +541,47 @@ namespace DeviceLab this.cpuLoad = args.Message.CpuLoad; this.OnPropertyChanged("CPULoad"); } /// <summary> /// An SSL thumbprint that we'll accept. /// </summary> private string thumbprint; /// <summary> /// Validate the server certificate /// </summary> /// <param name="sender">The sender object</param> /// <param name="certificate">The server's certificate</param> /// <param name="chain">The cert chain</param> /// <param name="sslPolicyErrors">Policy Errors</param> /// <returns>whether the cert passes validation</returns> private bool DoCertValidation(DevicePortal sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { X509Certificate2 cert = new X509Certificate2(certificate); // If we have previously said to accept this cert, don't prompt again for this session. if (!string.IsNullOrEmpty(this.thumbprint) && this.thumbprint.Equals(cert.Thumbprint, StringComparison.OrdinalIgnoreCase)) { return true; } // We could alternatively ask the user if they wanted to always trust // this device and we could persist the thumbprint in some way (registry, database, filesystem, etc). MessageBoxResult result = MessageBox.Show(string.Format( "Do you want to accept the following certificate?\n\nThumbprint:\n {0}\nIssuer:\n {1}", cert.Thumbprint, cert.Issuer), "Untrusted Certificate Detected", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); if (result == MessageBoxResult.Yes) { thumbprint = cert.Thumbprint; return true; } return false; } } } Samples/DeviceLab/ViewModels/MainViewModel.cs +0 −1 Original line number Diff line number Diff line Loading @@ -35,7 +35,6 @@ namespace DeviceLab DiagnosticSinks.AggregateDiagnosticSink aggDiags = new DiagnosticSinks.AggregateDiagnosticSink(this.Diagnostics, debugDiags); this.SignIn = new DeviceSignInViewModel(aggDiags); this.SignIn.AddDevicePortalConnectionFactory(new XboxDevicePortalConnectionFactory()); this.SignIn.AddDevicePortalConnectionFactory(new GenericDevicePortalConnectionFactory()); this.SignIn.SignInAttempted += this.OnSignInAttemptCompleted; Loading Samples/DeviceLab/ViewModels/XboxDevicePortalConnectionFactory.csdeleted 100644 → 0 +0 −39 Original line number Diff line number Diff line //---------------------------------------------------------------------------------------------- // <copyright file="XboxDevicePortalConnectionFactory.cs" company="Microsoft Corporation"> // Licensed under the MIT License. See LICENSE.TXT in the project root license information. // </copyright> //---------------------------------------------------------------------------------------------- using System.Security; using Microsoft.Tools.WindowsDevicePortal; namespace DeviceLab { /// <summary> /// Factory creates an IDevicePortalConnection instance that is specific to Xbox One devices /// </summary> public class XboxDevicePortalConnectionFactory : IDevicePortalConnectionFactory { /// <summary> /// Gets a friendly name for the XboxDevicePortalConnectionFactory that can be presented to the user /// </summary> public string Name { get { return "Xbox One"; } } /// <summary> /// Create an instance of XboxDevicePortalConnectionFactory /// </summary> /// <param name="address">IP address to use for connectin</param> /// <param name="userName">User name to use for authenticating</param> /// <param name="password">Password to use for authenticating</param> /// <returns>The new IDevicePortalConnection instance</returns> public IDevicePortalConnection CreateConnection( string address, string userName, SecureString password) { return new XboxDevicePortalConnection(address, userName, password); } } } Loading
Samples/DeviceLab/DeviceLab.csproj +0 −2 Original line number Diff line number Diff line Loading @@ -64,7 +64,6 @@ <Compile Include="ViewModels\DiagnosticSinks.cs" /> <Compile Include="ViewModels\GenericDevicePortalConnectionFactory.cs" /> <Compile Include="ViewModels\ObservableCommandQueue.cs" /> <Compile Include="ViewModels\XboxDevicePortalConnectionFactory.cs" /> <Compile Include="Views\DeviceCollectionView.xaml.cs"> <DependentUpon>DeviceCollectionView.xaml</DependentUpon> </Compile> Loading @@ -78,7 +77,6 @@ <DependentUpon>NumberEntryBox.xaml</DependentUpon> </Compile> <Compile Include="Controls\SelectionListBox.cs" /> <Compile Include="XboxDevicePortalConnection.cs" /> <Page Include="Controls\BindablePassword.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> Loading
Samples/DeviceLab/ViewModels/DevicePortalCommandModel.cs +5 −5 Original line number Diff line number Diff line Loading @@ -11,9 +11,9 @@ namespace DeviceLab { /// <summary> /// Base class for ViewModel classes that wrap a DevicePortal object. /// Provides status for pending DevicePortal operations and an /// ObservableCommandQueue to enable composing commands using /// CommandSequences. /// Provides status for pending DevicePortal operations, diagnostic /// output support, an ObservableCommandQueue to enable composing /// commands using CommandSequences, etc. /// </summary> public class DevicePortalCommandModel : BindableBase { Loading Loading @@ -231,8 +231,8 @@ namespace DeviceLab protected virtual void ReportException(string commandName, Exception exn) { this.OutputDiagnosticString("Exception during {0} command:\n", commandName); this.OutputDiagnosticString(exn.Message); this.OutputDiagnosticString(exn.StackTrace); this.OutputDiagnosticString(exn.Message + "\n"); this.OutputDiagnosticString(exn.StackTrace + "\n"); // Clear the command queue to prevent executing any more commands this.OutputDiagnosticString("Clearing any queued commands\n"); Loading
Samples/DeviceLab/ViewModels/DevicePortalViewModel.cs +59 −27 Original line number Diff line number Diff line Loading @@ -9,6 +9,9 @@ using System.Threading.Tasks; using System.Windows.Input; using Microsoft.Tools.WindowsDevicePortal; using Prism.Commands; using System.Security.Cryptography.X509Certificates; using System.Windows; using System.Net.Security; namespace DeviceLab { Loading @@ -29,7 +32,11 @@ namespace DeviceLab public DevicePortalViewModel(DevicePortal portal, IDiagnosticSink diags) : base(portal, diags) { this.ConnectionRetryAttempts = 5; // Add additional handling for untrusted certs. this.Portal.UnvalidatedCert += DoCertValidation; // Default number of retry attempts to make when reestablishing the connection this.ConnectionRetryAttempts = 3; } #endregion // Cosntructors Loading Loading @@ -383,6 +390,7 @@ namespace DeviceLab this.OutputDiagnosticString("Connection failed after {0} tries.\n", numTries); } }; this.Portal.ConnectionStatus += handler; this.Ready = false; Loading @@ -393,7 +401,12 @@ namespace DeviceLab await this.Portal.Connect(); ++numTries; } while (this.Portal.ConnectionHttpStatusCode != HttpStatusCode.OK && numTries < this.ConnectionRetryAttempts); while (this.Portal.ConnectionHttpStatusCode != HttpStatusCode.OK && numTries <= this.ConnectionRetryAttempts); if(this.Portal.ConnectionHttpStatusCode !=HttpStatusCode.OK) { throw new Exception(string.Format("Unable to connect after {0} tries.", numTries - 1)); } } catch (Exception exn) { Loading Loading @@ -450,7 +463,7 @@ namespace DeviceLab try { this.Portal.SystemPerfMessageReceived += this.OnSystemPerfReceived; await Task.Run(this.StartListeningHelper); await this.Portal.StartListeningForSystemPerf(); } catch (Exception exn) { Loading @@ -459,17 +472,6 @@ namespace DeviceLab this.Ready = true; } /// <summary> /// StartListeningForSystemPerf would deadlock when called from the main thread. /// This helper exists so that the asynchronous operation can be run on the /// thread pool and avoid the deadlock /// </summary> /// <returns>A task the captures the continuation of the start listening call</returns> private async Task StartListeningHelper() { await this.Portal.StartListeningForSystemPerf().ConfigureAwait(false); } #endregion // StartListeningForSystemPerfCommand #region StopListeningForSystemPerfCommand Loading Loading @@ -517,8 +519,7 @@ namespace DeviceLab try { this.Portal.SystemPerfMessageReceived -= this.OnSystemPerfReceived; await this.StopListeningHelper(); await this.StopListeningHelper(); await this.Portal.StopListeningForSystemPerf(); } catch (Exception exn) { Loading @@ -527,17 +528,6 @@ namespace DeviceLab this.Ready = true; } /// <summary> /// StopListeningForSystemPerf would deadlock when called from the main thread. /// This helper exists so that the asynchronous operation can be run on the /// thread pool and avoid the deadlock /// </summary> /// <returns>Task the captures the continuation of the asynchronous action</returns> private async Task StopListeningHelper() { await this.Portal.StopListeningForSystemPerf(); } #endregion // StopListeningForSystemPerfCommand #endregion // Commands Loading @@ -551,5 +541,47 @@ namespace DeviceLab this.cpuLoad = args.Message.CpuLoad; this.OnPropertyChanged("CPULoad"); } /// <summary> /// An SSL thumbprint that we'll accept. /// </summary> private string thumbprint; /// <summary> /// Validate the server certificate /// </summary> /// <param name="sender">The sender object</param> /// <param name="certificate">The server's certificate</param> /// <param name="chain">The cert chain</param> /// <param name="sslPolicyErrors">Policy Errors</param> /// <returns>whether the cert passes validation</returns> private bool DoCertValidation(DevicePortal sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { X509Certificate2 cert = new X509Certificate2(certificate); // If we have previously said to accept this cert, don't prompt again for this session. if (!string.IsNullOrEmpty(this.thumbprint) && this.thumbprint.Equals(cert.Thumbprint, StringComparison.OrdinalIgnoreCase)) { return true; } // We could alternatively ask the user if they wanted to always trust // this device and we could persist the thumbprint in some way (registry, database, filesystem, etc). MessageBoxResult result = MessageBox.Show(string.Format( "Do you want to accept the following certificate?\n\nThumbprint:\n {0}\nIssuer:\n {1}", cert.Thumbprint, cert.Issuer), "Untrusted Certificate Detected", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); if (result == MessageBoxResult.Yes) { thumbprint = cert.Thumbprint; return true; } return false; } } }
Samples/DeviceLab/ViewModels/MainViewModel.cs +0 −1 Original line number Diff line number Diff line Loading @@ -35,7 +35,6 @@ namespace DeviceLab DiagnosticSinks.AggregateDiagnosticSink aggDiags = new DiagnosticSinks.AggregateDiagnosticSink(this.Diagnostics, debugDiags); this.SignIn = new DeviceSignInViewModel(aggDiags); this.SignIn.AddDevicePortalConnectionFactory(new XboxDevicePortalConnectionFactory()); this.SignIn.AddDevicePortalConnectionFactory(new GenericDevicePortalConnectionFactory()); this.SignIn.SignInAttempted += this.OnSignInAttemptCompleted; Loading
Samples/DeviceLab/ViewModels/XboxDevicePortalConnectionFactory.csdeleted 100644 → 0 +0 −39 Original line number Diff line number Diff line //---------------------------------------------------------------------------------------------- // <copyright file="XboxDevicePortalConnectionFactory.cs" company="Microsoft Corporation"> // Licensed under the MIT License. See LICENSE.TXT in the project root license information. // </copyright> //---------------------------------------------------------------------------------------------- using System.Security; using Microsoft.Tools.WindowsDevicePortal; namespace DeviceLab { /// <summary> /// Factory creates an IDevicePortalConnection instance that is specific to Xbox One devices /// </summary> public class XboxDevicePortalConnectionFactory : IDevicePortalConnectionFactory { /// <summary> /// Gets a friendly name for the XboxDevicePortalConnectionFactory that can be presented to the user /// </summary> public string Name { get { return "Xbox One"; } } /// <summary> /// Create an instance of XboxDevicePortalConnectionFactory /// </summary> /// <param name="address">IP address to use for connectin</param> /// <param name="userName">User name to use for authenticating</param> /// <param name="password">Password to use for authenticating</param> /// <returns>The new IDevicePortalConnection instance</returns> public IDevicePortalConnection CreateConnection( string address, string userName, SecureString password) { return new XboxDevicePortalConnection(address, userName, password); } } }