예제 #1
0
        /// <summary>
        /// Main entry point to the sample.
        /// </summary>
        public static async Task Main(string[] args)
        {
            Options options = null;
            ParserResult <Options> result = Parser.Default.ParseArguments <Options>(args)
                                            .WithParsed(parsedOptions => { options = parsedOptions; })
                                            .WithNotParsed(errors => Options.HandleParseError(errors));

            var httpClient = new HttpClient();
            DigitalTwinsClient dtClient = GetDigitalTwinsClient(
                options.TenantId,
                options.ClientId,
                options.ClientSecret,
                options.AdtEndpoint,
                httpClient);

            var dtLifecycleSamples = new DigitalTwinsLifecycleSamples(dtClient, options.EventHubName);
            await dtLifecycleSamples.RunSamplesAsync().ConfigureAwait(false);

            var modelLifecycleSamples = new ModelLifecycleSamples(dtClient);
            await modelLifecycleSamples.RunSamplesAsync().ConfigureAwait(false);

            var componentSamples = new ComponentSamples(dtClient);
            await componentSamples.RunSamplesAsync().ConfigureAwait(false);

            httpClient.Dispose();
        }
예제 #2
0
        /// <summary>
        /// Main entry point to the sample.
        /// </summary>
        public static async Task Main(string[] args)
        {
            Options options = null;
            ParserResult <Options> result = Parser.Default.ParseArguments <Options>(args)
                                            .WithParsed(parsedOptions =>
            {
                options = parsedOptions;
            })
                                            .WithNotParsed(errors =>
            {
                Environment.Exit(1);
            });

            if (options.GetLoginMethod() == LoginMethod.AppId &&
                string.IsNullOrWhiteSpace(options.ClientSecret))
            {
                Console.Error.WriteLine("When LoginMethod is AppId, ClientSecret parameter is required.");
                Console.Error.WriteLine(HelpText.AutoBuild(result, null, null));
                Environment.Exit(1);
            }

            var httpClient = new HttpClient();
            DigitalTwinsClient dtClient = (options.GetLoginMethod()) switch
            {
                LoginMethod.AppId => GetDigitalTwinsClient(
                    options.TenantId,
                    options.ClientId,
                    options.ClientSecret,
                    options.AdtEndpoint),

                LoginMethod.User => GetDigitalTwinsClient(
                    options.TenantId,
                    options.ClientId,
                    options.AdtEndpoint,
                    httpClient),

                _ => throw new Exception("Unsupported login method"),
            };

            var dtLifecycleSamples = new DigitalTwinsLifecycleSamples(dtClient, options.EventHubName);
            await dtLifecycleSamples.RunSamplesAsync().ConfigureAwait(false);

            var modelLifecycleSamples = new ModelLifecycleSamples(dtClient);
            await modelLifecycleSamples.RunSamplesAsync().ConfigureAwait(false);

            var componentSamples = new ComponentSamples(dtClient);
            await componentSamples.RunSamplesAsync().ConfigureAwait(false);

            var publishTelemetrySamples = new PublishTelemetrySamples(dtClient);
            await publishTelemetrySamples.RunSamplesAsync().ConfigureAwait(false);

            httpClient.Dispose();
        }
예제 #3
0
        /// <summary>
        /// Main entry point to the sample.
        /// </summary>
        public static async Task Main(string[] args)
        {
            // Parse and validate paramters

            Options options = null;
            ParserResult <Options> result = Parser.Default.ParseArguments <Options>(args)
                                            .WithParsed(parsedOptions =>
            {
                options = parsedOptions;
            })
                                            .WithNotParsed(errors =>
            {
                Environment.Exit(1);
            });

            // Instantiate the client
            DigitalTwinsClient dtClient = GetDigitalTwinsClient(
                options.TenantId,
                options.ClientId,
                options.ClientSecret,
                options.AdtEndpoint);

            // Run the samples

            var dtLifecycleSamples = new DigitalTwinsLifecycleSamples(dtClient, options.EventHubEndpointName);
            await dtLifecycleSamples.RunSamplesAsync();

            var modelLifecycleSamples = new ModelLifecycleSamples();
            await modelLifecycleSamples.RunSamplesAsync(dtClient);

            var componentSamples = new ComponentSamples();
            await componentSamples.RunSamplesAsync(dtClient);

            var publishTelemetrySamples = new PublishTelemetrySamples();
            await publishTelemetrySamples.RunSamplesAsync(dtClient);

            var relationshipSamples = new RelationshipSamples();
            await relationshipSamples.RunSamplesAsync(dtClient);
        }