示例#1
0
        public static Task <LeafDevice> CreateAsync(
            string leafDeviceId,
            Protocol protocol,
            AuthenticationType auth,
            Option <string> parentId,
            bool useSecondaryCertificate,
            CertificateAuthority ca,
            IotHub iotHub,
            string edgeHostname,
            CancellationToken token,
            Option <string> modelId,
            bool nestedEdge)
        {
            ClientOptions options = new ClientOptions();

            modelId.ForEach(m => options.ModelId = m);
            return(Profiler.Run(
                       async() =>
            {
                ITransportSettings transport = protocol.ToTransportSettings();
                OsPlatform.Current.InstallCaCertificates(ca.EdgeCertificates.TrustedCertificates, transport);

                switch (auth)
                {
                case AuthenticationType.Sas:
                    return await CreateWithSasAsync(
                        leafDeviceId,
                        parentId,
                        iotHub,
                        transport,
                        edgeHostname,
                        token,
                        options,
                        nestedEdge);

                case AuthenticationType.CertificateAuthority:
                    {
                        string p = parentId.Expect(() => new ArgumentException("Missing parent ID"));
                        return await CreateWithCaCertAsync(
                            leafDeviceId,
                            p,
                            ca,
                            iotHub,
                            transport,
                            edgeHostname,
                            token,
                            options);
                    }

                case AuthenticationType.SelfSigned:
                    {
                        string p = parentId.Expect(() => new ArgumentException("Missing parent ID"));
                        return await CreateWithSelfSignedCertAsync(
                            leafDeviceId,
                            p,
                            useSecondaryCertificate,
                            ca,
                            iotHub,
                            transport,
                            edgeHostname,
                            token,
                            options);
                    }

                default:
                    throw new InvalidEnumArgumentException();
                }
            },
                       "Created leaf device '{Device}' on hub '{IotHub}'",
                       leafDeviceId,
                       iotHub.Hostname));
        }