Пример #1
0
        public async Task SimulateDevice(string deviceType, int messageDelay, int n, string caFile)
        {
            var producer = new IoTHubProducerCommands(CurrentContext, service);


            if (!String.IsNullOrWhiteSpace(caFile))
            {
                Console.WriteLine($"Registering CA certificate: {caFile}");
                var caCert = await CertificateUtilities.LoadPemCACertificate(caFile, null);

                CertificateUtilities.RegisterCert2(caCert);
            }

            if (string.Compare(deviceType, "temperature", true) == 0)
            {
                await producer.
                SimulateTemperatureSensor(messageDelay, n);
            }
            else if (string.Compare(deviceType, "temperature_pair", true) == 0)
            {
                await producer.
                SimulateTemperatureSensorPair(messageDelay, n);
            }
            else
            {
                Console.WriteLine($"No matching device type: {deviceType}");
            }

            await Task.CompletedTask;
        }
Пример #2
0
        public async Task SimulateDevice(string deviceType, int messageDelay, int n, string caFile, string[] deviceContext, string pattern, string patternPeriod, string output)
        {
            bool isJson = String.Compare(output, "json", true) == 0;
            bool isCsv  = String.Compare(output, "csv", true) == 0;

            OutputFormat of;

            if (isJson)
            {
                of = OutputFormat.Json;
            }
            else if (isCsv)
            {
                of = OutputFormat.Csv;
            }
            else
            {
                Console.WriteLine($"No matching output format: {output}");
                return;
            }

            var producer = new IoTHubProducerCommands(CurrentContext, service);


            if (!String.IsNullOrWhiteSpace(caFile))
            {
                Console.WriteLine($"Registering CA certificate: {caFile}");
                var caCert = await CertificateUtilities.LoadPemCACertificate(caFile, null);

                CertificateUtilities.RegisterCert2(caCert);
            }

            if (string.Compare(deviceType, "temperature", true) == 0)
            {
                if (deviceContext == null || deviceContext.Length == 0)
                {
                    await producer.
                    SimulateTemperatureSensor(messageDelay, n, pattern, patternPeriod);
                }
                else
                {
                    await producer.SimulateMultipleTemperatureSensors(deviceContext, messageDelay, n, pattern, patternPeriod, of);
                }
            }
            else if (string.Compare(deviceType, "temperature_pair", true) == 0)
            {
                await producer.
                SimulateTemperatureSensorPair(messageDelay, n);
            }
            else
            {
                Console.WriteLine($"No matching device type: {deviceType}");
            }

            await Task.CompletedTask;
        }
Пример #3
0
        public async Task Device2CloudMessage(string message, string fromFile, TransportType transportType)
        {
            var pc = new IoTHubProducerCommands(CurrentContext, service);

            if (fromFile != null)
            {
                await pc.Device2CloudMessageFromFile(fromFile, transportType);
            }
            else
            {
                await pc.Device2CloudSingleMessage(message, transportType);
            }
        }