Пример #1
0
        public async Task Init(IConfigSource configProvider)
        {
            Preconditions.CheckNotNull(configProvider, nameof(configProvider));
            try
            {
                using (await this.updateLock.LockAsync())
                {
                    configProvider.SetConfigUpdatedCallback(this.UpdateConfig);
                    Option <EdgeHubConfig> edgeHubConfig = await configProvider.GetConfig();

                    if (!edgeHubConfig.HasValue)
                    {
                        Events.EmptyConfigReceived();
                    }
                    else
                    {
                        await edgeHubConfig.ForEachAsync(async ehc =>
                        {
                            await this.UpdateRoutes(ehc.Routes, false);
                            this.UpdateStoreAndForwardConfig(ehc.StoreAndForwardConfiguration);
                        });

                        Events.Initialized();
                    }
                }
            }
            catch (Exception ex)
            {
                Events.InitializingError(ex);
            }
        }
Пример #2
0
 public void Init(IConfigSource configProvider)
 {
     Preconditions.CheckNotNull(configProvider, nameof(configProvider));
     try
     {
         configProvider.SetConfigUpdatedCallback(this.UpdateConfig);
         this.configProvider = Option.Some(configProvider);
         this.configUpdater  = Option.Some(new PeriodicTask(this.PullConfig, this.configUpdateFrequency, TimeSpan.Zero, Events.Log, "Get EdgeHub config"));
         Events.Initialized();
     }
     catch (Exception ex)
     {
         Events.InitializingError(ex);
         throw;
     }
 }
Пример #3
0
        public async Task Init(IConfigSource configProvider)
        {
            Preconditions.CheckNotNull(configProvider, nameof(configProvider));
            try
            {
                configProvider.SetConfigUpdatedCallback(this.UpdateConfig);
                this.configProvider = Option.Some(configProvider);

                // Get the config and initialize the EdgeHub now.
                await this.PullConfig();

                // Start a periodic task to pull the config.
                this.configUpdater = Option.Some(new PeriodicTask(this.PullConfig, this.configUpdateFrequency, this.configUpdateFrequency, Events.Log, "Get EdgeHub config"));
                Events.Initialized();
            }
            catch (Exception ex)
            {
                Events.InitializingError(ex);
                throw;
            }
        }
Пример #4
0
        public async Task Init(IConfigSource configProvider)
        {
            Preconditions.CheckNotNull(configProvider, nameof(configProvider));
            try
            {
                configProvider.SetConfigUpdatedCallback(this.HandleUpdateConfig);
                this.configProvider = Option.Some(configProvider);

                // first try to update config with the cached config
                await this.PullConfig(c => c.GetCachedConfig());

                // Get the config and initialize the EdgeHub
                // but don't wait if it has a prefetched config
                Task pullTask = this.PullConfig(c => c.GetConfig());
                await this.currentConfig.Match(
                    (config) =>
                {
                    Events.InitializedWithPrefetchedConfig();
                    return(Task.FromResult(this.currentConfig));
                },
                    async() =>
                {
                    Events.GettingConfig();
                    await pullTask;
                    return(this.currentConfig);
                });

                // Start a periodic task to pull the config.
                this.configUpdater = Option.Some(new PeriodicTask(() => this.PullConfig(c => c.GetConfig()), this.configUpdateFrequency, this.configUpdateFrequency, Events.Log, "Get EdgeHub config"));
                Events.Initialized();
            }
            catch (Exception ex)
            {
                Events.InitializingError(ex);
                throw;
            }
        }