コード例 #1
0
        /// <summary>
        /// A sample to illustrate how to send telemetry messages to a device.
        /// </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>();

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

            var sample = new ServiceClientSample(parameters.HubConnectionString, parameters.TransportType, parameters.DeviceId, logger);
            await sample.RunSampleAsync();

            Console.WriteLine("Done.");
            return(0);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: shanthalakc/MyApp
        //private static TransportType s_transportType = TransportType.Amqp_WebSocket_Only;

        public static int Main(string[] args)
        {
            if (string.IsNullOrEmpty(s_connectionString) && args.Length > 0)
            {
                s_connectionString = args[0];
            }

            if (args.Length < 1)
            {
                Console.WriteLine("\nUsage: \n");
                Console.WriteLine("\tServiceClientSample <deviceID> [connectionString]\n");
                return(1);
            }

            string deviceId = args[0];

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

            ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(s_connectionString, s_transportType);

            var sample = new ServiceClientSample(serviceClient);

            sample.RunSampleAsync(deviceId).GetAwaiter().GetResult();

            Console.WriteLine("Done.\n");
            return(0);
        }
コード例 #3
0
        //private static TransportType s_transportType = TransportType.Amqp_WebSocket_Only;

        public static async Task <int> Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("\nUsage: \n");
                Console.WriteLine("\tServiceClientSample <deviceID> [connectionString]\n");
                return(1);
            }

            string deviceId = args[0];

            if (string.IsNullOrWhiteSpace(s_connectionString) && args.Length > 1)
            {
                s_connectionString = args[1];
            }

            using ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(s_connectionString, s_transportType);

            var sample = new ServiceClientSample(serviceClient);
            await sample.RunSampleAsync(deviceId).ConfigureAwait(false);

            await serviceClient.CloseAsync().ConfigureAwait(false);

            Console.WriteLine("Done.\n");
            return(0);
        }