public async Task <Try <ICloudConnection> > Connect(IClientCredentials identity, Action <string, CloudConnectionStatus> connectionStatusChangedHandler) { Preconditions.CheckNotNull(identity, nameof(identity)); try { var cloudListener = new CloudListener(this.edgeHub.Expect(() => new InvalidOperationException("EdgeHub reference should not be null")), identity.Identity.Id); var cloudConnection = new CloudConnection( connectionStatusChangedHandler, this.transportSettings, this.messageConverterProvider, this.clientProvider, cloudListener, this.edgeHubTokenProvider, this.deviceScopeIdentitiesCache, this.idleTimeout, this.closeOnIdleTimeout); await cloudConnection.CreateOrUpdateAsync(identity); Events.SuccessCreatingCloudConnection(identity.Identity); return(Try.Success <ICloudConnection>(cloudConnection)); } catch (Exception ex) { Events.ErrorCreatingCloudConnection(identity.Identity, ex); return(Try <ICloudConnection> .Failure(ex)); } }
public async Task <Try <ICloudConnection> > Connect(IClientCredentials identity, Action <string, CloudConnectionStatus> connectionStatusChangedHandler) { Preconditions.CheckNotNull(identity, nameof(identity)); try { var cloudConnection = new CloudConnection(connectionStatusChangedHandler, this.transportSettings, this.messageConverterProvider, this.clientProvider); await cloudConnection.CreateOrUpdateAsync(identity); Events.SuccessCreatingCloudConnection(identity.Identity); return(Try.Success <ICloudConnection>(cloudConnection)); } catch (Exception ex) { Events.ErrorCreatingCloudConnection(identity.Identity, ex); return(Try <ICloudConnection> .Failure(ex)); } }