// NOTE: For the purposes of this example, the s_certificatePassword is
        // hard coded. In a production device, the password will need to be stored
        // in a more secure manner. Additionally, the certificate file (PFX) should
        // be stored securely on a production device using a Hardware Security Module.

        // ////////////////////////////////////////////////////////

        public static async Task <int> Main(string[] args)
        {
            var tasks = new List <Task>();

            foreach (var fileName in s_certificateFileNames)
            {
                X509Certificate2 certificate = LoadProvisioningCertificate(fileName);

                using (var security = new SecurityProviderX509Certificate(certificate))
                {
                    using (var transport = new ProvisioningTransportHandlerAmqp(TransportFallbackType.TcpOnly))
                    {
                        ProvisioningDeviceClient provClient =
                            ProvisioningDeviceClient.Create(GlobalDeviceEndpoint, dpsIdScope, security, transport);


                        var provisioningDeviceLogic = new ProvisioningDeviceLogic(provClient, security);
                        tasks.Add(provisioningDeviceLogic.RunAsync());
                        await Task.Delay(30000); // add a device every 30 seconds
                    }
                }
            }

            await Task.WhenAll(tasks);

            return(0);
        }
예제 #2
0
        public static int Main(string[] args)
        {
            X509Certificate2 certificate = LoadProvisioningCertificate();

            using (var security = new SecurityProviderX509Certificate(certificate))
            {
                using (var transport = new ProvisioningTransportHandlerAmqp(TransportFallbackType.TcpOnly))
                {
                    ProvisioningDeviceClient provClient =
                        ProvisioningDeviceClient.Create(GlobalDeviceEndpoint, dpsIdScope, security, transport);

                    var provisioningDeviceLogic = new ProvisioningDeviceLogic(provClient, security);
                    provisioningDeviceLogic.RunAsync().GetAwaiter().GetResult();
                }
            }

            return(0);
        }