Beispiel #1
0
        /// <summary>
        /// Host the module giving it its connection string.
        /// </summary>
        private static async Task HostAsync(IIoTHubConfig config, ILogger logger,
                                            string deviceId, string moduleId, string[] args, bool verbose = false,
                                            bool acceptAll = false)
        {
            Console.WriteLine("Create or retrieve connection string...");

            var cs = await Retry.WithExponentialBackoff(logger,
                                                        () => AddOrGetAsync(config, deviceId, moduleId));

            // Hook event source
            using (var broker = new EventSourceBroker()) {
                LogControl.Level.MinimumLevel = verbose ?
                                                LogEventLevel.Verbose : LogEventLevel.Information;

                Console.WriteLine("Starting publisher module...");
                broker.Subscribe(IoTSdkLogger.EventSource, new IoTSdkLogger(logger));
                var arguments = args.ToList();
                arguments.Add($"--ec={cs}");
                arguments.Add($"--si=0");
                arguments.Add($"--ms=0");
                if (acceptAll)
                {
                    arguments.Add("--aa");
                }
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    arguments.Add("--at=X509Store");
                }
                Publisher.Program.Main(arguments.ToArray());
                Console.WriteLine("Publisher module exited.");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Host the module giving it its connection string.
        /// </summary>
        private static async Task HostAsync(IIoTHubConfig config,
                                            string deviceId, string moduleId, bool verbose = false)
        {
            Console.WriteLine("Create or retrieve connection string...");
            var logger = ConsoleLogger.Create(LogEventLevel.Error);
            var cs     = await Retry.WithExponentialBackoff(logger,
                                                            () => AddOrGetAsync(config, deviceId, moduleId));

            // Hook event source
            using (var broker = new EventSourceBroker()) {
                LogControl.Level.MinimumLevel = verbose ?
                                                LogEventLevel.Verbose : LogEventLevel.Information;

                Console.WriteLine("Starting discovery module...");
                broker.Subscribe(IoTSdkLogger.EventSource, new IoTSdkLogger(logger));
                var arguments = new List <string> {
                    $"EdgeHubConnectionString={cs}"
                };
                Discovery.Program.Main(arguments.ToArray());
                Console.WriteLine("Discovery module exited.");
            }
        }