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.");
            }
        }
        private void EndAggregatorConfigChanged(IAsyncResult asyncResult)
        {
            if (AggregatorConfigChanged == null)
            {
                return;
            }

            try
            {
                AggregatorConfigChanged.EndInvoke(asyncResult);
            }
            catch (Exception ex)
            {
                Logger.Warn("Ending aggregator configuration changed call failed.", ex);
            }
        }
        private void CheckAggregatorConfigChange(Pdu pdu)
        {
            if (AggregatorConfigChanged != null)
            {
                AggregatorConfigResponsePayload configPayload = GetPayload(pdu, Constants.AggregatorConfigResponsePayload.TagType, null) as AggregatorConfigResponsePayload;
                if (configPayload != null)
                {
                    AggregatorConfig aggregatorConfig = new AggregatorConfig(configPayload);

                    if (_currentAggregatorConfig == null || !_currentAggregatorConfig.Equals(aggregatorConfig))
                    {
                        _currentAggregatorConfig = aggregatorConfig;
                        AggregatorConfigChanged?.BeginInvoke(this, new AggregatorConfigChangedEventArgs(_currentAggregatorConfig), EndAggregatorConfigChanged, null);
                    }
                }
            }
        }
Esempio n. 4
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));
 }