// ReSharper disable once UnusedMember.Local async Task <int> OnExecuteAsync() { try { string connectionString = this.DeviceConnectionString ?? await SecretsHelper.GetSecretFromConfigKey("iotHubConnStrKey"); string endpoint = this.EventHubCompatibleEndpointWithEntityPath ?? await SecretsHelper.GetSecretFromConfigKey("eventHubConnStrKey"); var test = new LeafDevice( connectionString, endpoint, this.DeviceId, this.CertificateFileName, this.EdgeHostName); await test.RunAsync(); } catch (Exception ex) { Console.WriteLine(ex); return(1); } Console.WriteLine("Success!"); return(0); }
// ReSharper disable once UnusedMember.Local async Task <int> OnExecuteAsync() { try { string connectionString = this.DeviceConnectionString ?? await SecretsHelper.GetSecretFromConfigKey("iotHubConnStrKey"); string endpoint = this.EventHubCompatibleEndpointWithEntityPath ?? await SecretsHelper.GetSecretFromConfigKey("eventHubConnStrKey"); if (!string.IsNullOrWhiteSpace(this.X509PrimaryCertPath) && !string.IsNullOrWhiteSpace(this.X509PrimaryKeyPath) && !string.IsNullOrWhiteSpace(this.X509SecondaryCertPath) && !string.IsNullOrWhiteSpace(this.X509SecondaryKeyPath)) { // use thumbprint auth and perform test for both primary and secondary certificates var thumbprintCerts = new List <string> { this.X509PrimaryCertPath, this.X509SecondaryCertPath }; var testPrimaryCertificate = new LeafDevice( connectionString, endpoint, this.DeviceId, this.TrustedCACertificateFileName, this.EdgeHostName, this.UseWebSockets, this.X509PrimaryCertPath, this.X509PrimaryKeyPath, thumbprintCerts); await testPrimaryCertificate.RunAsync(); var testSeondaryCertificate = new LeafDevice( connectionString, endpoint, this.DeviceId, this.TrustedCACertificateFileName, this.EdgeHostName, this.UseWebSockets, this.X509SecondaryCertPath, this.X509SecondaryKeyPath, thumbprintCerts); await testSeondaryCertificate.RunAsync(); } else if (!string.IsNullOrWhiteSpace(this.X509CACertPath) && !string.IsNullOrWhiteSpace(this.X509CAKeyPath)) { // use X.509 CA auth and perform test using CA chained certificates var testCa = new LeafDevice( connectionString, endpoint, this.DeviceId, this.TrustedCACertificateFileName, this.EdgeHostName, this.UseWebSockets, this.X509CACertPath, this.X509CAKeyPath); await testCa.RunAsync(); } else { // non certificate flow use SAS tokens var testSas = new LeafDevice( connectionString, endpoint, this.DeviceId, this.TrustedCACertificateFileName, this.EdgeHostName, this.UseWebSockets); await testSas.RunAsync(); } } catch (Exception ex) { Console.WriteLine(ex); return(1); } Console.WriteLine("Success!"); return(0); }