Пример #1
0
        protected Details(
            string iothubConnectionString,
            string eventhubCompatibleEndpointWithEntityPath,
            string deviceId,
            string trustedCACertificateFileName,
            string edgeHostName,
            bool useWebSockets,
            Option <DeviceCertificate> clientCertificatePaths,
            Option <IList <string> > thumbprintCertificatePaths)
        {
            this.iothubConnectionString = iothubConnectionString;
            this.eventhubCompatibleEndpointWithEntityPath = eventhubCompatibleEndpointWithEntityPath;
            this.deviceId = deviceId;
            this.trustedCACertificateFileName = trustedCACertificateFileName;
            this.edgeHostName = edgeHostName;
            (this.authType,
             this.clientCertificate,
             this.clientCertificateChain,
             this.thumbprints) = this.ObtainAuthDetails(clientCertificatePaths, thumbprintCertificatePaths);

            if (useWebSockets)
            {
                this.serviceClientTransportType  = ServiceClientTransportType.Amqp_WebSocket_Only;
                this.eventHubClientTransportType = EventHubClientTransportType.AmqpWebSockets;
                this.deviceTransportSettings     = new ITransportSettings[] { new MqttTransportSettings(DeviceClientTransportType.Mqtt_WebSocket_Only) };
            }
            else
            {
                this.serviceClientTransportType  = ServiceClientTransportType.Amqp;
                this.eventHubClientTransportType = EventHubClientTransportType.Amqp;
                this.deviceTransportSettings     = new ITransportSettings[] { new MqttTransportSettings(DeviceClientTransportType.Mqtt_Tcp_Only) };
            }
        }
Пример #2
0
        protected Details(
            string iothubConnectionString,
            string eventhubCompatibleEndpointWithEntityPath,
            string deviceId,
            string certificateFileName,
            string edgeHostName,
            bool useWebSockets
            )
        {
            this.iothubConnectionString = iothubConnectionString;
            this.eventhubCompatibleEndpointWithEntityPath = eventhubCompatibleEndpointWithEntityPath;
            this.deviceId            = deviceId;
            this.certificateFileName = certificateFileName;
            this.edgeHostName        = edgeHostName;

            if (useWebSockets)
            {
                this.serviceClientTransportType  = ServiceClientTransportType.Amqp_WebSocket_Only;
                this.eventHubClientTransportType = EventHubClientTransportType.AmqpWebSockets;
                this.deviceClientTransportType   = DeviceClientTransportType.Mqtt_WebSocket_Only;
            }
            else
            {
                this.serviceClientTransportType  = ServiceClientTransportType.Amqp;
                this.eventHubClientTransportType = EventHubClientTransportType.Amqp;
                this.deviceClientTransportType   = DeviceClientTransportType.Mqtt;
            }
        }
Пример #3
0
        protected Details(
            IBootstrapper bootstrapper,
            Option <RegistryCredentials> credentials,
            string iothubConnectionString,
            string eventhubCompatibleEndpointWithEntityPath,
            UpstreamProtocolType upstreamProtocol,
            Option <string> proxy,
            string imageTag,
            string deviceId,
            string hostname,
            Option <string> deploymentFileName,
            Option <string> twinTestFileName,
            string deviceCaCert,
            string deviceCaPk,
            string deviceCaCerts,
            bool optimizedForPerformance,
            bool initializeWithAgentArtifact,
            LogLevel runtimeLogLevel,
            bool cleanUpExistingDeviceOnSuccess,
            Option <DPSAttestation> dpsAttestation)
        {
            this.bootstrapper           = bootstrapper;
            this.credentials            = credentials;
            this.iothubConnectionString = iothubConnectionString;
            this.dpsAttestation         = dpsAttestation;
            this.eventhubCompatibleEndpointWithEntityPath = eventhubCompatibleEndpointWithEntityPath;

            switch (upstreamProtocol)
            {
            case UpstreamProtocolType.Amqp:
            case UpstreamProtocolType.Mqtt:
                this.serviceClientTransportType  = ServiceClientTransportType.Amqp;
                this.eventHubClientTransportType = EventHubClientTransportType.Amqp;
                break;

            case UpstreamProtocolType.AmqpWs:
            case UpstreamProtocolType.MqttWs:
                this.serviceClientTransportType  = ServiceClientTransportType.Amqp_WebSocket_Only;
                this.eventHubClientTransportType = EventHubClientTransportType.AmqpWebSockets;
                break;

            default:
                throw new Exception($"Unexpected upstream protocol type {upstreamProtocol}");
            }

            this.imageTag                       = imageTag;
            this.deviceId                       = deviceId;
            this.hostname                       = hostname;
            this.DeploymentFileName             = deploymentFileName;
            this.TwinTestFileName               = twinTestFileName;
            this.deviceCaCert                   = deviceCaCert;
            this.deviceCaPk                     = deviceCaPk;
            this.deviceCaCerts                  = deviceCaCerts;
            this.optimizedForPerformance        = optimizedForPerformance;
            this.initializeWithAgentArtifact    = initializeWithAgentArtifact;
            this.runtimeLogLevel                = runtimeLogLevel;
            this.cleanUpExistingDeviceOnSuccess = cleanUpExistingDeviceOnSuccess;
            this.proxy = proxy.Map(p => new WebProxy(p) as IWebProxy);
        }
Пример #4
0
        public MsgServiceEventProcessor(IConfiguration config, ILogger logger, TelemetryClient tc)
        {
            _logger          = logger;
            _telemetryClient = tc;

            iothub_connectionString = config.GetValue <string>("IOT_E2E_IOTHUB_SERVICE_CONNECTIONSTRING");;
            s_transportType         = Microsoft.Azure.Devices.TransportType.Amqp;
        }
Пример #5
0
        public static async Task <DirectMethodCloudSender> CreateAsync(
            string connectionString,
            TransportType transportType,
            ILogger logger)
        {
            ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(connectionString, transportType);
            await serviceClient.OpenAsync();

            return(new DirectMethodCloudSender(
                       serviceClient,
                       logger));
        }
Пример #6
0
        protected Details(
            string iothubConnectionString,
            string eventhubCompatibleEndpointWithEntityPath,
            string deviceId,
            string trustedCACertificateFileName,
            string edgeHostName,
            string edgeDeviceId,
            bool useWebSockets,
            Option <DeviceCertificate> clientCertificatePaths,
            Option <IList <string> > thumbprintCertificatePaths)
        {
            this.iothubConnectionString = iothubConnectionString;
            this.eventhubCompatibleEndpointWithEntityPath = eventhubCompatibleEndpointWithEntityPath;
            this.deviceId = deviceId;
            this.trustedCACertificateFileName = trustedCACertificateFileName;
            this.edgeHostName = edgeHostName;
            if (!edgeDeviceId.IsNullOrWhiteSpace())
            {
                this.edgeDeviceId = Option.Some(edgeDeviceId);
            }

            (this.authType,
             this.clientCertificate,
             this.clientCertificateChain,
             this.thumbprints) = ObtainAuthDetails(clientCertificatePaths, thumbprintCertificatePaths);

            if (useWebSockets)
            {
                this.serviceClientTransportType  = ServiceClientTransportType.Amqp_WebSocket_Only;
                this.eventHubClientTransportType = EventHubClientTransportType.AmqpWebSockets;
                this.deviceTransportSettings     = new ITransportSettings[] { new MqttTransportSettings(DeviceClientTransportType.Mqtt_WebSocket_Only) };
            }
            else
            {
                this.serviceClientTransportType  = ServiceClientTransportType.Amqp;
                this.eventHubClientTransportType = EventHubClientTransportType.Amqp;
                this.deviceTransportSettings     = new ITransportSettings[] { new MqttTransportSettings(DeviceClientTransportType.Mqtt_Tcp_Only) };
            }

            Console.WriteLine(
                $"Leaf Device Client: \n"
                + $"\t[authType={this.authType}] \n"
                + $"\t[clientCertificate subject name={this.clientCertificate.Match(c => c.SubjectName.ToString(), () => string.Empty)}] \n"
                + $"\t[clientCertificateChain count={this.clientCertificateChain.Match(c => c.Count(), () => 0)}] \n"
                + $"\t[service client transport type={this.serviceClientTransportType}]\n"
                + $"\t[event hub client transport type={this.eventHubClientTransportType}]\n"
                + $"\t[device transport type={this.deviceTransportSettings.First().GetTransportType()}]");
        }
        private void Button_Click_Svc(object sender, RoutedEventArgs e)
        {
            source = new CancellationTokenSource();
            token  = source.Token;
            string s_port             = tbSvcTimeout2.Text;
            int    port               = int.Parse(s_port, CultureInfo.InvariantCulture);
            string s_connectionString = Azure_IoTHub_Connections.MyConnections.IoTHubConnectionString;

            Microsoft.Azure.Devices.TransportType s_transportType = Microsoft.Azure.Devices.TransportType.Amqp;
            string s_deviceId = Azure_IoTHub_Connections.MyConnections.DeviceId;

            Task.Run(async() =>
            {
                try
                {
                    using (ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(s_connectionString, s_transportType))
                    {
                        var sample = new DNStandardDeviceStreaming.DeviceStreamProxySvc(serviceClient, s_deviceId, port, OnSvcRecvText, OnSvcStatusUpdate);
                        await sample.RunSampleAsync();//.GetAwaiter().GetResult();
                    }
                }
                catch (Exception ex)
                {
                    OnSvcStatusUpdate(string.Format("Proxy Svc fail {0}", ex.Message));
                }
            });

            int i = 0;
            //using (ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(s_connectionString, s_transportType))
            //{
            //    var sample = new DeviceStreamProxySvc(serviceClient, s_deviceId, port);
            //    sample.RunSampleAsync()
            //}

            ////Store these current values then reset. These vales are passed to the device and remain so until changed.
            ////Whereas
            //int devAutoStart = DevAutoStart;
            //int devKeepListening = DevKeepListening;


            //ClearAllToggles();

            ////These values are passed if true with each connection. If not passed then the device clears them.
            //bool keepAlive = AppSettingsValues.Settings.KeepAliveSvc;
            //bool responseExpected = AppSettingsValues.Settings.ExpectResponse;



            //if (!DeviceStream_Svc.SignalSendMsgOut(msgOut, keepAlive, responseExpected))
            //{
            //    await Task.Run(() =>
            //    {
            //        try
            //        {
            //            if(svcBasicMode)
            //                DeviceStream_Svc.RunSvc(service_cs, device_id, msgOut, OnSvcRecvText).GetAwaiter().GetResult();
            //            else if (!svcCustomClassMode)
            //                DeviceStream_Svc.RunSvc(service_cs, device_id, msgOut, OnSvcRecvText, devKeepListening, devAutoStart, OnSvcStatusUpdate, keepAlive, responseExpected).GetAwaiter().GetResult();

            //            else
            //                DeviceStream_Svc.RunSvc(service_cs, device_id, msgOut, OnSvcRecvText, devKeepListening, devAutoStart, OnSvcStatusUpdate, keepAlive, responseExpected, new DeviceSvcCurrentSettings_Example()).GetAwaiter().GetResult();
            //        }
            //        catch (TaskCanceledException)
            //        {
            //            System.Diagnostics.Debug.WriteLine("Error App.RunSvc(): Task cancelled");
            //        }
            //        catch (OperationCanceledException)
            //        {
            //            System.Diagnostics.Debug.WriteLine("Error App.RunSvc(): Operation cancelled");
            //        }
            //        catch (Exception ex)
            //        {
            //            System.Diagnostics.Debug.WriteLine("Error App.RunSvc(): " + ex.Message);
            //        }
            //    });

            //}
        }