예제 #1
0
        public static async Task <CloudConnection> Create(
            IIdentity identity,
            Action <string, CloudConnectionStatus> connectionStatusChangedHandler,
            ITransportSettings[] transportSettings,
            IMessageConverterProvider messageConverterProvider,
            IClientProvider clientProvider,
            ICloudListener cloudListener,
            ITokenProvider tokenProvider,
            TimeSpan idleTimeout,
            bool closeOnIdleTimeout,
            TimeSpan operationTimeout)
        {
            Preconditions.CheckNotNull(tokenProvider, nameof(tokenProvider));
            var cloudConnection = new CloudConnection(
                identity,
                connectionStatusChangedHandler,
                transportSettings,
                messageConverterProvider,
                clientProvider,
                cloudListener,
                idleTimeout,
                closeOnIdleTimeout,
                operationTimeout);
            ICloudProxy cloudProxy = await cloudConnection.CreateNewCloudProxyAsync(tokenProvider);

            cloudConnection.cloudProxy = Option.Some(cloudProxy);
            return(cloudConnection);
        }
예제 #2
0
 ClientTokenCloudConnection(
     IIdentity identity,
     Action <string, CloudConnectionStatus> connectionStatusChangedHandler,
     ITransportSettings[] transportSettings,
     IMessageConverterProvider messageConverterProvider,
     IClientProvider clientProvider,
     ICloudListener cloudListener,
     TimeSpan idleTimeout,
     bool closeOnIdleTimeout,
     TimeSpan operationTimeout,
     string productInfo,
     Option <string> modelId)
     : base(
         identity,
         connectionStatusChangedHandler,
         transportSettings,
         messageConverterProvider,
         clientProvider,
         cloudListener,
         idleTimeout,
         closeOnIdleTimeout,
         operationTimeout,
         productInfo,
         modelId)
 {
 }
예제 #3
0
 public CloudConnectionProvider(
     IMessageConverterProvider messageConverterProvider,
     int connectionPoolSize,
     IClientProvider clientProvider,
     Option <UpstreamProtocol> upstreamProtocol,
     ITokenProvider edgeHubTokenProvider,
     IDeviceScopeIdentitiesCache deviceScopeIdentitiesCache,
     ICredentialsCache credentialsCache,
     IIdentity edgeHubIdentity,
     TimeSpan idleTimeout,
     bool closeOnIdleTimeout,
     TimeSpan operationTimeout,
     bool useServerHeartbeat,
     Option <IWebProxy> proxy,
     IMetadataStore metadataStore,
     bool nestedEdgeEnabled = false)
 {
     this.messageConverterProvider = Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
     this.clientProvider           = Preconditions.CheckNotNull(clientProvider, nameof(clientProvider));
     this.upstreamProtocol         = upstreamProtocol;
     this.connectionPoolSize       = Preconditions.CheckRange(connectionPoolSize, 1, nameof(connectionPoolSize));
     this.proxy                      = proxy;
     this.edgeHub                    = Option.None <IEdgeHub>();
     this.idleTimeout                = idleTimeout;
     this.closeOnIdleTimeout         = closeOnIdleTimeout;
     this.useServerHeartbeat         = useServerHeartbeat;
     this.edgeHubTokenProvider       = Preconditions.CheckNotNull(edgeHubTokenProvider, nameof(edgeHubTokenProvider));
     this.deviceScopeIdentitiesCache = Preconditions.CheckNotNull(deviceScopeIdentitiesCache, nameof(deviceScopeIdentitiesCache));
     this.credentialsCache           = Preconditions.CheckNotNull(credentialsCache, nameof(credentialsCache));
     this.edgeHubIdentity            = Preconditions.CheckNotNull(edgeHubIdentity, nameof(edgeHubIdentity));
     this.operationTimeout           = operationTimeout;
     this.metadataStore              = Preconditions.CheckNotNull(metadataStore, nameof(metadataStore));
     this.nestedEdgeEnabled          = nestedEdgeEnabled;
 }
예제 #4
0
 public CloudConnectionProvider(
     IMessageConverterProvider messageConverterProvider,
     int connectionPoolSize,
     IClientProvider clientProvider,
     Option <UpstreamProtocol> upstreamProtocol,
     ITokenProvider edgeHubTokenProvider,
     IDeviceScopeIdentitiesCache deviceScopeIdentitiesCache,
     ICredentialsCache credentialsCache,
     IIdentity edgeHubIdentity,
     TimeSpan idleTimeout,
     bool closeOnIdleTimeout,
     TimeSpan operationTimeout,
     Option <IWebProxy> proxy,
     IProductInfoStore productInfoStore)
 {
     Preconditions.CheckRange(connectionPoolSize, 1, nameof(connectionPoolSize));
     this.messageConverterProvider = Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
     this.clientProvider           = Preconditions.CheckNotNull(clientProvider, nameof(clientProvider));
     this.transportSettings        = GetTransportSettings(upstreamProtocol, connectionPoolSize, proxy);
     this.edgeHub                    = Option.None <IEdgeHub>();
     this.idleTimeout                = idleTimeout;
     this.closeOnIdleTimeout         = closeOnIdleTimeout;
     this.edgeHubTokenProvider       = Preconditions.CheckNotNull(edgeHubTokenProvider, nameof(edgeHubTokenProvider));
     this.deviceScopeIdentitiesCache = Preconditions.CheckNotNull(deviceScopeIdentitiesCache, nameof(deviceScopeIdentitiesCache));
     this.credentialsCache           = Preconditions.CheckNotNull(credentialsCache, nameof(credentialsCache));
     this.edgeHubIdentity            = Preconditions.CheckNotNull(edgeHubIdentity, nameof(edgeHubIdentity));
     this.operationTimeout           = operationTimeout;
     this.productInfoStore           = Preconditions.CheckNotNull(productInfoStore, nameof(productInfoStore));
 }
예제 #5
0
        public static ITwinManager Create(
            IConnectionManager connectionManager,
            IMessageConverterProvider messageConverterProvider,
            IEntityStore <string, TwinStoreEntity> entityStore,
            IDeviceConnectivityManager deviceConnectivityManager,
            IValidator <TwinCollection> reportedPropertiesValidator,
            Option <TimeSpan> minTwinSyncPeriod,
            Option <TimeSpan> reportedPropertiesSyncFrequency)
        {
            Preconditions.CheckNotNull(connectionManager, nameof(connectionManager));
            Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
            Preconditions.CheckNotNull(entityStore, nameof(entityStore));
            Preconditions.CheckNotNull(deviceConnectivityManager, nameof(deviceConnectivityManager));
            Preconditions.CheckNotNull(reportedPropertiesValidator, nameof(reportedPropertiesValidator));

            IMessageConverter <TwinCollection> twinCollectionConverter = messageConverterProvider.Get <TwinCollection>();
            IMessageConverter <Twin>           twinConverter           = messageConverterProvider.Get <Twin>();
            ICloudSync cloudSync   = new CloudSync(connectionManager, twinCollectionConverter, twinConverter);
            var        twinManager = new StoringTwinManager(
                connectionManager,
                twinCollectionConverter,
                twinConverter,
                reportedPropertiesValidator,
                new TwinStore(entityStore),
                new ReportedPropertiesStore(entityStore, cloudSync, reportedPropertiesSyncFrequency),
                cloudSync,
                deviceConnectivityManager,
                minTwinSyncPeriod.GetOrElse(DefaultMinTwinSyncPeriod));

            return(twinManager);
        }
예제 #6
0
 protected CloudConnection(
     IIdentity identity,
     Action <string, CloudConnectionStatus> connectionStatusChangedHandler,
     ITransportSettings[] transportSettings,
     IMessageConverterProvider messageConverterProvider,
     IClientProvider clientProvider,
     ICloudListener cloudListener,
     TimeSpan idleTimeout,
     bool closeOnIdleTimeout,
     TimeSpan operationTimeout,
     string productInfo,
     Option <string> modelId)
 {
     this.Identity = Preconditions.CheckNotNull(identity, nameof(identity));
     this.ConnectionStatusChangedHandler = connectionStatusChangedHandler;
     this.transportSettingsList          = Preconditions.CheckNotNull(transportSettings, nameof(transportSettings));
     this.messageConverterProvider       = Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
     this.clientProvider     = Preconditions.CheckNotNull(clientProvider, nameof(clientProvider));
     this.cloudListener      = Preconditions.CheckNotNull(cloudListener, nameof(cloudListener));
     this.idleTimeout        = idleTimeout;
     this.closeOnIdleTimeout = closeOnIdleTimeout;
     this.cloudProxy         = Option.None <ICloudProxy>();
     this.operationTimeout   = operationTimeout;
     this.productInfo        = productInfo;
     this.modelId            = modelId;
 }
예제 #7
0
 public CloudConnectionProvider(IMessageConverterProvider messageConverterProvider, int connectionPoolSize, IClientProvider clientProvider, Option <UpstreamProtocol> upstreamProtocol)
 {
     Preconditions.CheckRange(connectionPoolSize, 1, nameof(connectionPoolSize));
     this.messageConverterProvider = Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
     this.clientProvider           = Preconditions.CheckNotNull(clientProvider, nameof(clientProvider));
     this.transportSettings        = GetTransportSettings(upstreamProtocol, connectionPoolSize);
 }
예제 #8
0
 public CloudProxy(IClient client, IMessageConverterProvider messageConverterProvider, string clientId, Action <string, CloudConnectionStatus> connectionStatusChangedHandler)
 {
     this.client = Preconditions.CheckNotNull(client, nameof(client));
     this.messageConverterProvider = Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
     this.clientId = Preconditions.CheckNonWhiteSpace(clientId, nameof(clientId));
     if (connectionStatusChangedHandler != null)
     {
         this.connectionStatusChangedHandler = connectionStatusChangedHandler;
     }
 }
 public CloudConnection(Action <string, CloudConnectionStatus> connectionStatusChangedHandler,
                        ITransportSettings[] transportSettings,
                        IMessageConverterProvider messageConverterProvider,
                        IClientProvider clientProvider)
 {
     this.connectionStatusChangedHandler = connectionStatusChangedHandler;
     this.transportSettingsList          = Preconditions.CheckNotNull(transportSettings, nameof(transportSettings));
     this.messageConverterProvider       = Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
     this.tokenGetter    = Option.None <TaskCompletionSource <string> >();
     this.clientProvider = Preconditions.CheckNotNull(clientProvider, nameof(clientProvider));
 }
예제 #10
0
        public static ITwinManager CreateTwinManager(
            IConnectionManager connectionManager,
            IMessageConverterProvider messageConverterProvider,
            Option <IStoreProvider> storeProvider)
        {
            Preconditions.CheckNotNull(connectionManager, nameof(connectionManager));
            Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
            Preconditions.CheckNotNull(storeProvider, nameof(storeProvider));
            var twinManager = new TwinManager(connectionManager, messageConverterProvider.Get <TwinCollection>(), messageConverterProvider.Get <Twin>(),
                                              storeProvider.Match(
                                                  s => Option.Some(s.GetEntityStore <string, TwinInfo>(Constants.TwinStorePartitionKey)),
                                                  () => Option.None <IEntityStore <string, TwinInfo> >()));

            connectionManager.CloudConnectionEstablished += twinManager.ConnectionEstablishedCallback;
            return(twinManager);
        }
예제 #11
0
 public CloudConnectionProvider(IMessageConverterProvider messageConverterProvider,
                                int connectionPoolSize,
                                IClientProvider clientProvider,
                                Option <UpstreamProtocol> upstreamProtocol,
                                ITokenProvider edgeHubTokenProvider,
                                IDeviceScopeIdentitiesCache deviceScopeIdentitiesCache,
                                TimeSpan idleTimeout)
 {
     Preconditions.CheckRange(connectionPoolSize, 1, nameof(connectionPoolSize));
     this.messageConverterProvider = Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
     this.clientProvider           = Preconditions.CheckNotNull(clientProvider, nameof(clientProvider));
     this.transportSettings        = GetTransportSettings(upstreamProtocol, connectionPoolSize);
     this.edgeHub                    = Option.None <IEdgeHub>();
     this.idleTimeout                = idleTimeout;
     this.edgeHubTokenProvider       = Preconditions.CheckNotNull(edgeHubTokenProvider, nameof(edgeHubTokenProvider));
     this.deviceScopeIdentitiesCache = Preconditions.CheckNotNull(deviceScopeIdentitiesCache, nameof(deviceScopeIdentitiesCache));
 }
예제 #12
0
 public CloudProxy(IClient client,
                   IMessageConverterProvider messageConverterProvider,
                   string clientId,
                   Action <string, CloudConnectionStatus> connectionStatusChangedHandler,
                   ICloudListener cloudListener,
                   TimeSpan idleTimeout)
 {
     this.client = Preconditions.CheckNotNull(client, nameof(client));
     this.messageConverterProvider = Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
     this.clientId       = Preconditions.CheckNonWhiteSpace(clientId, nameof(clientId));
     this.cloudReceiver  = new CloudReceiver(this, Preconditions.CheckNotNull(cloudListener, nameof(cloudListener)));
     this.timer          = new Timer(idleTimeout.TotalMilliseconds);
     this.timer.Elapsed += this.HandleIdleTimeout;
     this.timer.Start();
     if (connectionStatusChangedHandler != null)
     {
         this.connectionStatusChangedHandler = connectionStatusChangedHandler;
     }
 }
예제 #13
0
 public CloudConnection(Action <string, CloudConnectionStatus> connectionStatusChangedHandler,
                        ITransportSettings[] transportSettings,
                        IMessageConverterProvider messageConverterProvider,
                        IClientProvider clientProvider,
                        ICloudListener cloudListener,
                        ITokenProvider edgeHubTokenProvider,
                        IDeviceScopeIdentitiesCache deviceScopeIdentitiesCache,
                        TimeSpan idleTimeout)
 {
     this.connectionStatusChangedHandler = connectionStatusChangedHandler;
     this.transportSettingsList          = Preconditions.CheckNotNull(transportSettings, nameof(transportSettings));
     this.messageConverterProvider       = Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
     this.tokenGetter                = Option.None <TaskCompletionSource <string> >();
     this.clientProvider             = Preconditions.CheckNotNull(clientProvider, nameof(clientProvider));
     this.cloudListener              = Preconditions.CheckNotNull(cloudListener, nameof(cloudListener));
     this.idleTimeout                = idleTimeout;
     this.edgeHubTokenProvider       = Preconditions.CheckNotNull(edgeHubTokenProvider, nameof(edgeHubTokenProvider));
     this.deviceScopeIdentitiesCache = Preconditions.CheckNotNull(deviceScopeIdentitiesCache, nameof(deviceScopeIdentitiesCache));
 }
예제 #14
0
 public CloudProxy(IClient client,
                   IMessageConverterProvider messageConverterProvider,
                   string clientId,
                   Action <string, CloudConnectionStatus> connectionStatusChangedHandler,
                   ICloudListener cloudListener,
                   TimeSpan idleTimeout,
                   bool closeOnIdleTimeout)
 {
     this.client = Preconditions.CheckNotNull(client, nameof(client));
     this.messageConverterProvider = Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
     this.clientId      = Preconditions.CheckNonWhiteSpace(clientId, nameof(clientId));
     this.cloudReceiver = new CloudReceiver(this, Preconditions.CheckNotNull(cloudListener, nameof(cloudListener)));
     this.timer         = new ResettableTimer(this.HandleIdleTimeout, idleTimeout, Events.Log, true);
     this.timer.Start();
     this.closeOnIdleTimeout = closeOnIdleTimeout;
     if (connectionStatusChangedHandler != null)
     {
         this.connectionStatusChangedHandler = connectionStatusChangedHandler;
     }
     Events.Initialized(this);
 }
예제 #15
0
 public PassThroughTwinManager(IConnectionManager connectionManager, IMessageConverterProvider messageConverterProvider)
 {
     Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
     this.connectionManager = Preconditions.CheckNotNull(connectionManager, nameof(connectionManager));
     this.twinConverter     = messageConverterProvider.Get <Twin>();
 }