Esempio n. 1
0
        private void RecalculateAggregatorConfig()
        {
            AggregatorConfig mergedConfig = null;

            foreach (IKsiService service in SigningServices)
            {
                if (!_currentAggregatorConfigList.ContainsKey(service))
                {
                    continue;
                }

                AggregatorConfig config = _currentAggregatorConfigList[service];
                Logger.Debug("AggregatorConfig in cache: " + config + "; Sub-service: " + service.AggregatorAddress);
                mergedConfig = HAAggregatorConfigRequestRunner.MergeConfigs(mergedConfig, config);
            }

            if (_currentAggregatorConfig == null || !_currentAggregatorConfig.Equals(mergedConfig))
            {
                Logger.Debug("New merged AggregatorConfig: " + mergedConfig);
                _currentAggregatorConfig = mergedConfig;
                AggregatorConfigChanged?.Invoke(this, new AggregatorConfigChangedEventArgs(mergedConfig, this));
            }
            else
            {
                Logger.Debug("Merged AggregationConfig not changed.");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// End get additional aggregator configuration data (async)
        /// </summary>
        /// <param name="asyncResult"></param>
        /// <returns>Aggregator configuration data</returns>
        public AggregatorConfig EndGetAggregatorConfig(IAsyncResult asyncResult)
        {
            HAAsyncResult haAsyncResult            = GetHAAsyncResult(asyncResult);
            HAAggregatorConfigRequestRunner runner = GetRequestRunner <HAAggregatorConfigRequestRunner>(haAsyncResult);
            AggregatorConfig config = runner.EndGetAggregatorConfig(haAsyncResult);

            if (config == null)
            {
                lock (_aggregatorConfigChangedLock)
                {
                    _currentAggregatorConfigList.Clear();
                    _currentAggregatorConfig = null;
                }

                HAKsiServiceException ex = new HAKsiServiceException("Could not get aggregator configuration.", runner.SubServiceErrors);
                Logger.Warn(ex);
                AggregatorConfigChangedEventArgs aggregatorConfigChangedEventArgs = new AggregatorConfigChangedEventArgs(ex, this);
                AggregatorConfigChanged?.Invoke(this, aggregatorConfigChangedEventArgs);
                throw ex;
            }

            // if sub-service config request failed then remove corresponding config from cache
            foreach (HAKsiSubServiceException ex in runner.SubServiceErrors)
            {
                if (ex.ThrownBySubService == null)
                {
                    continue;
                }

                lock (_aggregatorConfigChangedLock)
                {
                    if (_currentAggregatorConfigList.ContainsKey(ex.ThrownBySubService))
                    {
                        _currentAggregatorConfigList.Remove(ex.ThrownBySubService);
                        RecalculateAggregatorConfig();
                    }
                }
            }

            return(config);
        }
 private void RequestResponseParser_AggregatorConfigChanged(object sender, AggregatorConfigChangedEventArgs e)
 {
     AggregatorConfigChanged?.Invoke(this, new AggregatorConfigChangedEventArgs(e.AggregatorConfig, this));
 }