예제 #1
0
        /// <summary>
        /// A sample to illustrate device streaming.
        /// </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);
            });

            using var deviceClient = DeviceClient.CreateFromConnectionString(
                      parameters.PrimaryConnectionString,
                      parameters.TransportType);
            var sample = new DeviceStreamSample(deviceClient);
            await sample.RunSampleAsync();

            await deviceClient.CloseAsync();

            Console.WriteLine("Done.");
            return(0);
        }
예제 #2
0
        //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 int Main(string[] args)
        {
            if (string.IsNullOrEmpty(s_deviceConnectionString) && args.Length > 0)
            {
                s_deviceConnectionString = args[0];
            }

            if (string.IsNullOrEmpty(s_deviceConnectionString))
            {
                Console.WriteLine("Please provide a device connection string");
                Console.WriteLine("Usage: DeviceClientC2DStreamingSample [iotHubDeviceConnString]");
                return(1);
            }

            using (DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(s_deviceConnectionString, s_transportType))
            {
                if (deviceClient == null)
                {
                    Console.WriteLine("Failed to create DeviceClient!");
                    return(1);
                }

                var sample = new DeviceStreamSample(deviceClient);
                sample.RunSampleAsync().GetAwaiter().GetResult();
            }

            Console.WriteLine("Done.\n");
            return(0);
        }
예제 #3
0
        //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 int Main(string[] args)
        {
            if (string.IsNullOrEmpty(s_deviceConnectionString) && args.Length > 0)
            {
                s_deviceConnectionString = args[0];
            }

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

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

            if (string.IsNullOrEmpty(s_deviceConnectionString) ||
                string.IsNullOrEmpty(s_hostName) ||
                string.IsNullOrEmpty(s_port))
            {
                Console.WriteLine("Please provide a connection string, target host and port");
                Console.WriteLine("Usage: DeviceLocalProxyC2DStreamingSample [iotHubConnString] [targetServiceHostName] [targetServicePort]");
                return(1);
            }

            int port = int.Parse(s_port, CultureInfo.InvariantCulture);

            using (DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(s_deviceConnectionString, s_transportType))
            {
                if (deviceClient == null)
                {
                    Console.WriteLine("Failed to create DeviceClient!");
                    return(1);
                }

                var sample = new DeviceStreamSample(deviceClient, s_hostName, port);
                sample.RunSampleAsync(new CancellationTokenSource()).GetAwaiter().GetResult();
            }

            Console.WriteLine("Done.\n");
            return(0);
        }
예제 #4
0
        public static int Main(string[] args)
        {
            Console.WriteLine("HostName: " + s_hostName);
            Console.WriteLine("Port: " + s_port);
            if (string.IsNullOrEmpty(s_hostName) || string.IsNullOrEmpty(s_port))
            {
                Console.WriteLine("Please provide a target host and port");
                return(1);
            }
            int port = int.Parse(s_port, CultureInfo.InvariantCulture);

            Console.WriteLine($"{DateTime.UtcNow} - Starting...");
            var deviceStream = new DeviceStreamSample(s_hostName, port);

            deviceStream.Init(new CancellationTokenSource()).GetAwaiter().GetResult();

            Console.WriteLine("Done.\n");
            return(0);
        }
예제 #5
0
        //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)
        {
            if (string.IsNullOrEmpty(s_deviceConnectionString) && args.Length > 0)
            {
                s_deviceConnectionString = args[0];
            }

            if (string.IsNullOrEmpty(s_deviceConnectionString))
            {
                Console.WriteLine("Please provide a device connection string");
                Console.WriteLine("Usage: DeviceClientC2DStreamingSample [iotHubDeviceConnString]");
                return(1);
            }

            using (var deviceClient = DeviceClient.CreateFromConnectionString(s_deviceConnectionString, s_transportType))
            {
                var sample = new DeviceStreamSample(deviceClient);
                await sample.RunSampleAsync().ConfigureAwait(false);
            }

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