Exemple #1
0
        /// <summary>
        /// Clear registry
        /// </summary>
        private static async Task ClearSupervisorsAsync()
        {
            var logger   = ConsoleOutLogger.Create();
            var config   = new IoTHubConfig(null);
            var registry = new IoTHubServiceHttpClient(new HttpClient(logger),
                                                       config, logger);

            var query = "SELECT * FROM devices.modules WHERE " +
                        $"properties.reported.{TwinProperty.Type} = '{IdentityType.Supervisor}'";
            var supers = await registry.QueryAllDeviceTwinsAsync(query);

            foreach (var item in supers)
            {
                foreach (var tag in item.Tags.Keys.ToList())
                {
                    item.Tags[tag] = null;
                }
                foreach (var property in item.Properties.Desired.Keys.ToList())
                {
                    item.Properties.Desired[property] = null;
                }
                foreach (var property in item.Properties.Reported.Keys.ToList())
                {
                    if (!item.Properties.Desired.ContainsKey(property))
                    {
                        item.Properties.Desired.Add(property, null);
                    }
                }
                await registry.CreateAsync(item, true, CancellationToken.None);
            }
        }
Exemple #2
0
        /// <summary>
        /// Create supervisor module identity in device registry
        /// </summary>
        private static async Task MakeSupervisorAsync(string deviceId, string moduleId)
        {
            var logger   = ConsoleOutLogger.Create();
            var config   = new IoTHubConfig(null);
            var registry = new IoTHubServiceHttpClient(new HttpClient(logger),
                                                       config, logger);


            await registry.CreateAsync(new DeviceTwinModel {
                Id       = deviceId,
                ModuleId = moduleId
            }, true, CancellationToken.None);

            var module = await registry.GetRegistrationAsync(deviceId, moduleId, CancellationToken.None);

            Console.WriteLine(JsonConvert.SerializeObject(module));
            var twin = await registry.GetAsync(deviceId, moduleId, CancellationToken.None);

            Console.WriteLine(JsonConvert.SerializeObject(twin));
            var cs = ConnectionString.Parse(config.IoTHubConnString);

            Console.WriteLine("Connection string:");
            Console.WriteLine($"HostName={cs.HostName};DeviceId={deviceId};" +
                              $"ModuleId={moduleId};SharedAccessKey={module.Authentication.PrimaryKey}");
        }
Exemple #3
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfiguration configuration) : base(configuration)
 {
     _ep  = new EventProcessorConfig(configuration);
     _eh  = new IoTHubEventConfig(configuration);
     _sb  = new ServiceBusConfig(configuration);
     _hub = new IoTHubConfig(configuration);
 }
Exemple #4
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfigurationRoot configuration) :
     base(configuration)
 {
     _sb  = new ServiceBusConfig(configuration);
     _hub = new IoTHubConfig(configuration);
     _ai  = new ApplicationInsightsConfig(configuration);
 }
Exemple #5
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="serviceId"></param>
 /// <param name="configuration"></param>
 public Config(string serviceId, IConfigurationRoot configuration) :
     base(configuration)
 {
     _tasks = new TaskProcessorConfig(configuration);
     _ep    = new EventProcessorConfig(configuration, serviceId);
     _eh    = new IoTHubEventConfig(configuration, serviceId);
     _hub   = new IoTHubConfig(configuration, serviceId);
 }
Exemple #6
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfiguration configuration) :
     base(configuration)
 {
     _tasks   = new TaskProcessorConfig(configuration);
     _db      = new CosmosDbConfig(configuration);
     _storage = new StorageConfig(configuration);
     _hub     = new IoTHubConfig(configuration);
 }
        // TODO - set false

        /// <summary>
        /// Configuration constructor
        /// </summary>
        /// <param name="serviceId"></param>
        /// <param name="configuration"></param>
        public Config(string serviceId, IConfigurationRoot configuration) :
            base(configuration)
        {
            _tasks   = new TaskProcessorConfig(configuration);
            _db      = new CosmosDbConfig(configuration);
            _storage = new StorageConfig(configuration);
            _hub     = new IoTHubConfig(configuration, serviceId);
        }
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfiguration configuration) :
     base(configuration)
 {
     _openApi = new OpenApiConfig(configuration);
     _host    = new WebHostConfig(configuration);
     _hub     = new IoTHubConfig(configuration);
     _cors    = new CorsConfig(configuration);
     _fh      = new ForwardedHeadersConfig(configuration);
 }
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="serviceId"></param>
 /// <param name="configuration"></param>
 public Config(string serviceId, IConfigurationRoot configuration) :
     base(configuration)
 {
     _swagger = new SwaggerConfig(configuration, serviceId);
     _auth    = new AuthConfig(configuration, serviceId);
     _hub     = new IoTHubConfig(configuration, serviceId);
     _cors    = new CorsConfig(configuration);
     _eh      = new EventHubConfig(configuration, serviceId);
 }
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfiguration configuration) :
     base(configuration)
 {
     _sb   = new ServiceBusConfig(configuration);
     _hub  = new IoTHubConfig(configuration);
     _id   = new IdentityTokenUpdaterConfig(configuration);
     _sync = new ActivationSyncConfig(configuration);
     _edge = new JobOrchestratorEndpointConfig(configuration);
 }
Exemple #11
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfiguration configuration) :
     base(configuration)
 {
     _openApi = new OpenApiConfig(configuration);
     _auth    = new AuthConfig(configuration);
     _host    = new HostConfig(configuration);
     _hub     = new IoTHubConfig(configuration);
     _cors    = new CorsConfig(configuration);
 }
Exemple #12
0
        // TODO - set false

        /// <summary>
        /// Configuration constructor
        /// </summary>
        /// <param name="configuration"></param>
        public Config(IConfigurationRoot configuration) :
            base(configuration)
        {
            _tasks   = new TaskProcessorConfig(configuration);
            _db      = new CosmosDbConfig(configuration);
            _storage = new StorageConfig(configuration);
            _hub     = new IoTHubConfig(configuration);
            _ai      = new ApplicationInsightsConfig(configuration);
        }
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="serviceId"></param>
 /// <param name="configuration"></param>
 public Config(string serviceId, IConfigurationRoot configuration) :
     base(configuration)
 {
     _auth     = new AuthConfig(configuration, serviceId);
     _hub      = new IoTHubConfig(configuration, serviceId);
     _cors     = new CorsConfig(configuration);
     _eh       = new EventHubConfig(configuration, serviceId);
     _sessions = new SessionServicesConfig(configuration);
 }
Exemple #14
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfigurationRoot configuration) :
     base(configuration)
 {
     _swagger = new SwaggerConfig(configuration);
     _auth    = new AuthConfig(configuration);
     _hub     = new IoTHubConfig(configuration);
     _cors    = new CorsConfig(configuration);
     _eh      = new EventHubConfig(configuration);
     _ai      = new ApplicationInsightsConfig(configuration);
 }
Exemple #15
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfiguration configuration) :
     base(configuration)
 {
     _auth     = new AuthConfig(configuration);
     _host     = new HostConfig(configuration);
     _hub      = new IoTHubConfig(configuration);
     _cors     = new CorsConfig(configuration);
     _sessions = new SessionServicesConfig(configuration);
     _api      = new RegistryConfig(configuration);
 }
Exemple #16
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfigurationRoot configuration) :
     base(configuration)
 {
     _tasks = new TaskProcessorConfig(configuration);
     _ep    = new EventProcessorConfig(configuration);
     _eh    = new IoTHubEventConfig(configuration);
     _hub   = new IoTHubConfig(configuration);
     _sb    = new ServiceBusConfig(configuration);
     _ai    = new ApplicationInsightsConfig(configuration);
 }
Exemple #17
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfiguration configuration) :
     base(configuration)
 {
     _host     = new WebHostConfig(configuration);
     _hub      = new IoTHubConfig(configuration);
     _cors     = new CorsConfig(configuration);
     _sessions = new SessionServicesConfig(configuration);
     _api      = new RegistryConfig(configuration);
     _fh       = new ForwardedHeadersConfig(configuration);
 }
Exemple #18
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfigurationRoot configuration) :
     base(configuration)
 {
     _auth     = new AuthConfig(configuration);
     _hub      = new IoTHubConfig(configuration);
     _cors     = new CorsConfig(configuration);
     _eh       = new EventHubConfig(configuration);
     _sessions = new SessionServicesConfig(configuration);
     _api      = new ApiConfig(configuration);
     _ai       = new ApplicationInsightsConfig(configuration);
 }
Exemple #19
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfiguration configuration) :
     base(configuration)
 {
     _openApi = new OpenApiConfig(configuration);
     _host    = new HostConfig(configuration);
     _auth    = new AuthConfig(configuration);
     _cors    = new CorsConfig(configuration);
     _hub     = new IoTHubConfig(configuration);
     _cr      = new ContainerRegistryConfig(configuration);
     _fh      = new ForwardedHeadersConfig(configuration);
 }
Exemple #20
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfiguration configuration) :
     base(configuration)
 {
     _openApi = new OpenApiConfig(configuration);
     _host    = new WebHostConfig(configuration);
     _hub     = new IoTHubConfig(configuration);
     _cors    = new CorsConfig(configuration);
     _cosmos  = new CosmosDbConfig(configuration);
     _jobs    = new JobOrchestratorConfig(configuration);
     _fh      = new ForwardedHeadersConfig(configuration);
 }
Exemple #21
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfigurationRoot configuration) :
     base(configuration)
 {
     _swagger = new SwaggerConfig(configuration);
     _auth    = new AuthConfig(configuration);
     _hub     = new IoTHubConfig(configuration);
     _cors    = new CorsConfig(configuration);
     _sb      = new ServiceBusConfig(configuration);
     _cosmos  = new CosmosDbConfig(configuration);
     _ai      = new ApplicationInsightsConfig(configuration);
 }
Exemple #22
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfiguration configuration) :
     base(configuration)
 {
     _openApi = new OpenApiConfig(configuration);
     _auth    = new AuthConfig(configuration);
     _host    = new HostConfig(configuration);
     _hub     = new IoTHubConfig(configuration);
     _cors    = new CorsConfig(configuration);
     _sb      = new ServiceBusConfig(configuration);
     _cosmos  = new CosmosDbConfig(configuration);
     _fh      = new ForwardedHeadersConfig(configuration);
 }
Exemple #23
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfiguration configuration) :
     base(configuration)
 {
     _openApi = new OpenApiConfig(configuration);
     _auth    = new AuthConfig(configuration);
     _host    = new HostConfig(configuration);
     _hub     = new IoTHubConfig(configuration);
     _cors    = new CorsConfig(configuration);
     _cosmos  = new CosmosDbConfig(configuration);
     _jobs    = new JobOrchestratorConfig(configuration);
     _edge    = new JobOrchestratorApiConfig(configuration);
 }
Exemple #24
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfiguration configuration) :
     base(configuration)
 {
     _openApi = new OpenApiConfig(configuration);
     _auth    = new AuthConfig(configuration);
     _host    = new HostConfig(configuration);
     _hub     = new IoTHubConfig(configuration);
     _cors    = new CorsConfig(configuration);
     _sb      = new ServiceBusConfig(configuration);
     _cosmos  = new CosmosDbConfig(configuration);
     _sr      = new SignalRServiceConfig(configuration);
 }
Exemple #25
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfiguration configuration) :
     base(configuration)
 {
     _openApi = new OpenApiConfig(configuration);
     _host    = new WebHostConfig(configuration);
     _hub     = new IoTHubConfig(configuration);
     _cors    = new CorsConfig(configuration);
     _api     = new ApiConfig(configuration);
     _cosmos  = new CosmosDbConfig(configuration);
     _fh      = new ForwardedHeadersConfig(configuration);
     _cr      = new ContainerRegistryConfig(configuration);
     _ps      = new PublishServicesConfig(configuration);
 }
Exemple #26
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 public Config(IConfiguration configuration) :
     base(configuration)
 {
     _openApi = new OpenApiConfig(configuration);
     _host    = new WebHostConfig(configuration);
     _hub     = new IoTHubConfig(configuration);
     _cors    = new CorsConfig(configuration);
     _sb      = new ServiceBusConfig(configuration);
     _cosmos  = new CosmosDbConfig(configuration);
     _fh      = new ForwardedHeadersConfig(configuration);
     _cr      = new ContainerRegistryConfig(configuration);
     _lwc     = new LogWorkspaceConfig(configuration);
 }
Exemple #27
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 internal Config(IConfigurationRoot configuration) :
     base(configuration)
 {
     _vault    = new VaultConfig(configuration);
     _keyVault = new KeyVaultConfig(configuration);
     _cosmos   = new CosmosDbConfig(configuration);
     _swagger  = new SwaggerConfig(configuration);
     _auth     = new AuthConfig(configuration);
     _cors     = new CorsConfig(configuration);
     _sb       = new ServiceBusConfig(configuration);
     _hub      = new IoTHubConfig(configuration);
     _registry = new ApiConfig(configuration);
     _ai       = new ApplicationInsightsConfig(configuration);
 }
Exemple #28
0
 /// <summary>
 /// Configuration constructor
 /// </summary>
 /// <param name="configuration"></param>
 internal Config(IConfiguration configuration) :
     base(configuration)
 {
     _vault    = new VaultConfig(configuration);
     _keyVault = new KeyVaultConfig(configuration);
     _cosmos   = new CosmosDbConfig(configuration);
     _openApi  = new OpenApiConfig(configuration);
     _host     = new WebHostConfig(configuration);
     _cors     = new CorsConfig(configuration);
     _sb       = new ServiceBusConfig(configuration);
     _hub      = new IoTHubConfig(configuration);
     _registry = new RegistryConfig(configuration);
     _fh       = new ForwardedHeadersConfig(configuration);
 }
Exemple #29
0
        /// <summary>
        /// Clear registry
        /// </summary>
        private static async Task ClearRegistryAsync()
        {
            var logger   = ConsoleOutLogger.Create();
            var config   = new IoTHubConfig(null);
            var registry = new IoTHubServiceHttpClient(new HttpClient(logger),
                                                       config, logger);

            var result = await registry.QueryAllDeviceTwinsAsync(
                "SELECT * from devices where IS_DEFINED(tags.DeviceType)");

            foreach (var item in result)
            {
                await registry.DeleteAsync(item.Id, item.ModuleId, null, CancellationToken.None);
            }
        }
Exemple #30
0
        /// <summary>
        /// The constructor
        /// </summary>
        /// <param name="ioTHubConfig">IoT Hub Configuration</param>
        /// <param name="onRetryError">The delegating action for each retry error</param>
        public IotHubService(
            IoTHubConfig ioTHubConfig,
            Action <int, Exception> onRetryError = null
            )
        {
            if (string.IsNullOrEmpty(ioTHubConfig.ConnectionString))
            {
                throw new ArgumentNullException($"[{nameof(IotHubService)}] {nameof(IotHubService)}(): Connection String is empty");
            }

            _ioTHubConfig = ioTHubConfig;

            _deviceClient =
                DeviceClient.CreateFromConnectionString(
                    _ioTHubConfig.ConnectionString,
                    InitTransportSettings()
                    );

            //The time out milliseconds for whole operation, default is 240000
            _deviceClient.OperationTimeoutInMilliseconds = _ioTHubConfig.OperationTimeoutSeconds * 1000;

            if (0 < _ioTHubConfig.DeviceRetryTimes)
            {
                var retryPolicy = new CustomRetryPolicy(
                    _ioTHubConfig.DeviceRetryTimes,
                    TimeSpan.FromSeconds(1),
                    TimeSpan.FromSeconds(_ioTHubConfig.RetryWaitSeconds),
                    TimeSpan.FromSeconds(1)
                    )
                {
                    OnRetryError = onRetryError
                };

                _deviceClient.SetRetryPolicy(retryPolicy);
            }
            else
            {
                _deviceClient.SetRetryPolicy(new NoRetry());
            }
        }