Ejemplo n.º 1
0
        async Task <Try <ICloudProxy> > TryGetCloudConnection(string id)
        {
            IIdentity       identity = this.identityProvider.Create(Preconditions.CheckNonWhiteSpace(id, nameof(id)));
            ConnectedDevice device   = this.GetOrCreateConnectedDevice(identity);

            Try <ICloudConnection> cloudConnectionTry = await device.GetOrCreateCloudConnection(
                c => this.ConnectToCloud(c.Identity, this.CloudConnectionStatusChangedHandler));

            Events.GetCloudConnection(device.Identity, cloudConnectionTry);
            Try <ICloudProxy> cloudProxyTry = GetCloudProxyFromCloudConnection(cloudConnectionTry, device.Identity);

            return(cloudProxyTry);
        }
Ejemplo n.º 2
0
        // This method is not used, but it has important logic and this will be useful for offline scenarios.
        // So do not delete this method.
        public async Task <Try <ICloudProxy> > GetOrCreateCloudConnectionAsync(IClientCredentials credentials)
        {
            Preconditions.CheckNotNull(credentials, nameof(credentials));

            // Get an existing ConnectedDevice from this.devices or add a new non-connected
            // instance to this.devices and return that.
            ConnectedDevice device = this.GetOrCreateConnectedDevice(credentials.Identity);

            Try <ICloudConnection> cloudConnectionTry = await device.GetOrCreateCloudConnection((c) => this.CreateOrUpdateCloudConnection(c, credentials));

            Events.GetCloudConnection(credentials.Identity, cloudConnectionTry);
            Try <ICloudProxy> cloudProxyTry = GetCloudProxyFromCloudConnection(cloudConnectionTry, credentials.Identity);

            return(cloudProxyTry);
        }