//private static TransportType s_transportType = TransportType.Mqtt;
        //private static TransportType s_transportType = TransportType.Amqp_WebSocket_Only;
        //private static TransportType s_transportType = TransportType.Mqtt_WebSocket_Only;

        public static async Task <int> Main(string[] args)
        {
            // Create a console logger, that logs all events that are categorized at Debug level or higher.
            // For additional details, see https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.ilogger?view=dotnet-plat-ext-3.1.
            ILoggerFactory loggerFactory = new LoggerFactory();

            loggerFactory.AddColorConsoleLogger(
                new ColorConsoleLoggerConfiguration
            {
                MinLogLevel = LogLevel.Debug,
            });
            var logger           = loggerFactory.CreateLogger <Program>();
            var sdkEventListener = new ConsoleEventListener(SdkEventProviderPrefix, logger);

            if (string.IsNullOrEmpty(s_deviceConnectionString) && args.Length > 0)
            {
                s_deviceConnectionString = args[0];
            }

            var sample = new DeviceReconnectionSample(s_deviceConnectionString, s_transportType, logger);
            await sample.RunSampleAsync();

            logger.LogInformation("Done, exiting...");
            return(0);
        }
Exemple #2
0
        /// <summary>
        /// A sample for illustrating how a device should handle connection status updates.
        /// </summary>
        /// <param name="args">
        /// Run with `--help` to see a list of required and optional parameters.
        /// </param>
        public static async Task <int> Main(string[] args)
        {
            // Parse application parameters
            Parameters parameters            = null;
            ParserResult <Parameters> result = Parser.Default.ParseArguments <Parameters>(args)
                                               .WithParsed(parsedParams =>
            {
                parameters = parsedParams;
            })
                                               .WithNotParsed(errors =>
            {
                Environment.Exit(1);
            });

            // Set up logging
            ILoggerFactory loggerFactory = new LoggerFactory();

            loggerFactory.AddColorConsoleLogger(
                new ColorConsoleLoggerConfiguration
            {
                MinLogLevel = LogLevel.Debug,
            });
            var logger = loggerFactory.CreateLogger <Program>();

            const string SdkEventProviderPrefix = "Microsoft-Azure-";

            // Instantiating this seems to do all we need for outputting SDK events to our console log
            _ = new ConsoleEventListener(SdkEventProviderPrefix, logger);

            // Run the sample
            var runningTime = parameters.ApplicationRunningTime != null
                ? TimeSpan.FromSeconds((double)parameters.ApplicationRunningTime)
                : Timeout.InfiniteTimeSpan;

            var sample = new DeviceReconnectionSample(parameters.GetConnectionStrings(), parameters.TransportType, logger);
            await sample.RunSampleAsync(runningTime);

            logger.LogInformation("Done.");
            return(0);
        }