コード例 #1
0
ファイル: Program.cs プロジェクト: garolion/Industrial-IoT
        /// <summary>
        /// Create supervisor module identity in device registry
        /// </summary>
        private static async Task MakeSupervisorAsync(string deviceId, string moduleId)
        {
            var logger   = ConsoleOutLogger.Create();
            var config   = new IoTHubConfig(null);
            var registry = new IoTHubServiceHttpClient(new HttpClient(logger),
                                                       config, logger);


            await registry.CreateAsync(new DeviceTwinModel {
                Id       = deviceId,
                ModuleId = moduleId
            }, true, CancellationToken.None);

            var module = await registry.GetRegistrationAsync(deviceId, moduleId, CancellationToken.None);

            Console.WriteLine(JsonConvert.SerializeObject(module));
            var twin = await registry.GetAsync(deviceId, moduleId, CancellationToken.None);

            Console.WriteLine(JsonConvert.SerializeObject(twin));
            var cs = ConnectionString.Parse(config.IoTHubConnString);

            Console.WriteLine("Connection string:");
            Console.WriteLine($"HostName={cs.HostName};DeviceId={deviceId};" +
                              $"ModuleId={moduleId};SharedAccessKey={module.Authentication.PrimaryKey}");
        }
コード例 #2
0
        /// <summary>
        /// Reset supervisor
        /// </summary>
        private static async Task ResetAsync(IIoTHubConfig config,
                                             string deviceId, string moduleId)
        {
            var logger   = LogEx.Console(LogEventLevel.Error);
            var registry = new IoTHubServiceHttpClient(new HttpClient(logger),
                                                       config, logger);

            await ResetAsync(registry, await registry.GetAsync(deviceId, moduleId));
        }
コード例 #3
0
        /// <summary>
        /// Reset supervisor
        /// </summary>
        private static async Task ResetAsync(IIoTHubConfig config,
                                             string deviceId, string moduleId)
        {
            var logger   = ConsoleLogger.Create(LogEventLevel.Error);
            var registry = new IoTHubServiceHttpClient(new HttpClient(logger),
                                                       config, new NewtonSoftJsonSerializer(), logger);

            await ResetAsync(registry, await registry.GetAsync(deviceId, moduleId,
                                                               CancellationToken.None));
        }