/// <summary>
        /// End get additional aggregator configuration data (async)
        /// </summary>
        /// <param name="asyncResult"></param>
        /// <returns>Aggregator configuration data</returns>
        public AggregatorConfig EndGetAggregatorConfig(IAsyncResult asyncResult)
        {
            if (_signingServiceProtocol == null)
            {
                throw new KsiServiceException("Signing service protocol is missing from service.");
            }

            KsiServiceAsyncResult serviceAsyncResult = GetKsiServiceAsyncResult(asyncResult);

            if (!serviceAsyncResult.IsCompleted)
            {
                serviceAsyncResult.AsyncWaitHandle.WaitOne();
            }

            byte[]     data    = _signingServiceProtocol.EndGetAggregatorConfig(serviceAsyncResult);
            PduPayload payload = AggregatorConfigRequestResponseParser.Parse(data);
            AggregatorConfigResponsePayload configResponsePayload = payload as AggregatorConfigResponsePayload;

            if (configResponsePayload == null)
            {
                Logger.Warn("Aggregator config request failed. Invalid response payload.{0}Payload:{0}{1}", Environment.NewLine, payload);
                throw new KsiServiceException("Invalid config response payload. Type: " + payload.Type);
            }

            return(new AggregatorConfig(configResponsePayload));
        }
예제 #2
0
 /// <summary>
 /// Create new aggregator configuration data instance
 /// </summary>
 /// <param name="payload">Aggregator config response payload</param>
 public AggregatorConfig(AggregatorConfigResponsePayload payload) : base(payload.ParentsUris)
 {
     if (payload == null)
     {
         throw new ArgumentNullException(nameof(payload));
     }
     MaxLevel             = payload.MaxLevel;
     AggregationAlgorithm = payload.AggregationAlgorithm;
     AggregationPeriod    = payload.AggregationPeriod;
     MaxRequests          = payload.MaxRequests;
 }
        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);
                    }
                }
            }
        }
 /// <summary>
 /// Parse child tag
 /// </summary>
 protected override ITlvTag ParseChild(ITlvTag childTag)
 {
     switch (childTag.Type)
     {
         case Constants.AggregationResponsePayload.TagType:
             AggregationResponsePayload aggregationResponsePayload = childTag as AggregationResponsePayload ?? new AggregationResponsePayload(childTag);
             Payloads.Add(aggregationResponsePayload);
             return aggregationResponsePayload;
         case Constants.ErrorPayload.TagType:
             return ErrorPayload = childTag as AggregationErrorPayload ?? new AggregationErrorPayload(childTag);
         case Constants.AggregatorConfigResponsePayload.TagType:
             AggregatorConfigResponsePayload aggregatorConfigResponsePayload = childTag as AggregatorConfigResponsePayload ?? new AggregatorConfigResponsePayload(childTag);
             Payloads.Add(aggregatorConfigResponsePayload);
             return aggregatorConfigResponsePayload;
         // not implemented yet, so just return the tag
         case Constants.AggregationAcknowledgmentResponsePayload.TagType:
             return childTag;
         default:
             return base.ParseChild(childTag);
     }
 }