public async Task <Try <ICloudConnection> > Connect(IIdentity identity, Action <string, CloudConnectionStatus> connectionStatusChangedHandler)
        {
            if (!await this.IsConnected())
            {
                return(new Try <ICloudConnection>(new Exception("Bridge is not connected upstream")));
            }

            var cloudProxy = new BrokeredCloudProxy(identity, this.cloudProxyDispatcher, connectionStatusChangedHandler);

            return(new Try <ICloudConnection>(new BrokeredCloudConnection(identity, cloudProxy)));
        }
        public async Task <Try <ICloudConnection> > Connect(IIdentity identity, Action <string, CloudConnectionStatus> connectionStatusChangedHandler)
        {
            if (!await this.IsConnected())
            {
                return(Try <ICloudConnection> .Failure(new IotHubException("Bridge is not connected upstream")));
            }

            try
            {
                // TODO: Check disconnect reason and refresh identity when MQTT5 is supported
                // The identity is not refreshed for now because there is no way to detect when the connection was dropped from upstream because unauthorized
                await this.deviceScopeIdentitiesCache.VerifyServiceIdentityAuthChainState(identity.Id, isNestedEdgeEnabled : true, refreshCachedIdentity : false);
            }
            catch (DeviceInvalidStateException ex)
            {
                return(Try <ICloudConnection> .Failure(ex));
            }

            var cloudProxy = new BrokeredCloudProxy(identity, this.cloudProxyDispatcher, connectionStatusChangedHandler);
            await cloudProxy.OpenAsync();

            return(new Try <ICloudConnection>(new BrokeredCloudConnection(identity, cloudProxy)));
        }
Ejemplo n.º 3
0
 public BrokeredCloudConnection(BrokeredCloudProxy cloudProxy)
 {
     this.IsActive   = true;
     this.CloudProxy = Option.Some(cloudProxy as ICloudProxy);
 }
        public Task <Try <ICloudConnection> > Connect(IIdentity identity, Action <string, CloudConnectionStatus> connectionStatusChangedHandler)
        {
            var cloudProxy = new BrokeredCloudProxy(identity, this.cloudProxyDispatcher, connectionStatusChangedHandler);

            return(Task.FromResult(new Try <ICloudConnection>(new BrokeredCloudConnection(cloudProxy))));
        }