public async Task HistoryGetConfigurationAsync()

in src/Azure.IIoT.OpcUa.Publisher/src/Services/NodeServices.cs [1053:1194]


        public async Task<HistoryConfigurationResponseModel> HistoryGetConfigurationAsync(
            T endpoint, HistoryConfigurationRequestModel request,
            CancellationToken ct)
        {
            ArgumentNullException.ThrowIfNull(request);
            if (string.IsNullOrEmpty(request.NodeId))
            {
                throw new ArgumentException("Bad node id missing", nameof(request));
            }
            using var trace = _activitySource.StartActivity("HistoryGetConfiguration");
            return await _client.ExecuteAsync(endpoint, async context =>
            {
                var nodeId = request.NodeId.ToNodeId(context.Session.MessageContext);
                if (NodeId.IsNull(nodeId))
                {
                    throw new ArgumentException("Bad node id", nameof(request));
                }

                // load the defaults for the historical configuration object.
                var config =
                    new HistoricalDataConfigurationState(null);
                config.Definition =
                    new PropertyState<string>(config);
                config.MaxTimeInterval =
                    new PropertyState<double>(config);
                config.MinTimeInterval =
                    new PropertyState<double>(config);
                config.ExceptionDeviation =
                    new PropertyState<double>(config);
                config.ExceptionDeviationFormat =
                    new PropertyState<ExceptionDeviationFormat>(config);
                config.StartOfArchive =
                    new PropertyState<DateTime>(config);
                config.StartOfOnlineArchive =
                    new PropertyState<DateTime>(config);
                config.Stepped =
                    new PropertyState<bool>(config);
                config.ServerTimestampSupported =
                    new PropertyState<bool>(config);
                config.AggregateFunctions =
                    new FolderState(config);

                var aggregate = new AggregateConfigurationState(config);
                aggregate.TreatUncertainAsBad =
                    new PropertyState<bool>(aggregate);
                aggregate.UseSlopedExtrapolation =
                    new PropertyState<bool>(aggregate);
                aggregate.PercentDataBad =
                    new PropertyState<byte>(aggregate);
                aggregate.PercentDataGood =
                    new PropertyState<byte>(aggregate);
                config.AggregateConfiguration =
                    aggregate;

                config.Create(context.Session.SystemContext, null,
                    BrowseNames.HAConfiguration, null, false);

                var relativePath = new RelativePath();
                relativePath.Elements.Add(new RelativePathElement
                {
                    ReferenceTypeId = ReferenceTypeIds.HasHistoricalConfiguration,
                    IsInverse = false,
                    IncludeSubtypes = false,
                    TargetName = BrowseNames.HAConfiguration
                });
                var errorInfo = await context.Session.ReadNodeStateAsync(
                    request.Header.ToRequestHeader(_timeProvider), config,
                    nodeId, relativePath, context.Ct).ConfigureAwait(false);
                if (errorInfo != null)
                {
                    return new HistoryConfigurationResponseModel
                    {
                        ErrorInfo = errorInfo
                    };
                }
                var startTime = config.StartOfOnlineArchive.GetValueOrDefaultEx()
                    ?? config.StartOfArchive.GetValueOrDefaultEx();
                if (startTime == null)
                {
                    startTime = await HistoryReadTimestampAsync(
                        context.Session, request.Header, nodeId, true,
                        _timeProvider, context.Ct).ConfigureAwait(false);
                }
                DateTime? endTime = null;
                if (endTime == null)
                {
                    endTime = await HistoryReadTimestampAsync(
                        context.Session, request.Header, nodeId, false,
                        _timeProvider, context.Ct).ConfigureAwait(false);
                }
                var children = new List<BaseInstanceState>();
                config.AggregateFunctions.GetChildren(context.Session.SystemContext, children);
                var aggregateFunctions = children.OfType<BaseObjectState>().ToDictionary(
                    c => request.Header.AsString(c.BrowseName, context.Session.MessageContext, _options),
                    c => request.Header.AsString(c.NodeId, context.Session.MessageContext, _options));
                return new HistoryConfigurationResponseModel
                {
                    Configuration = errorInfo != null ? null : new HistoryConfigurationModel
                    {
                        MinTimeInterval =
                            config.MinTimeInterval.GetValueOrDefaultEx(
                                v => v.HasValue && v.Value != 0 ?
                                TimeSpan.FromMilliseconds(v.Value) : (TimeSpan?)null),
                        MaxTimeInterval =
                            config.MaxTimeInterval.GetValueOrDefaultEx(
                                v => v.HasValue && v.Value != 0 ?
                                TimeSpan.FromMilliseconds(v.Value) : (TimeSpan?)null),
                        ExceptionDeviation =
                            config.ExceptionDeviation.GetValueOrDefaultEx(),
                        ExceptionDeviationType =
                            config.ExceptionDeviationFormat.GetValueOrDefaultEx(
                                v => v.ToExceptionDeviationType()),
                        ServerTimestampSupported =
                            config.ServerTimestampSupported.GetValueOrDefaultEx(),
                        Stepped =
                            config.Stepped.GetValueOrDefaultEx(),
                        Definition =
                            config.Definition.GetValueOrDefaultEx(),
                        AggregateFunctions =
                            aggregateFunctions.Count == 0 ? null : aggregateFunctions,
                        AggregateConfiguration = new AggregateConfigurationModel
                        {
                            PercentDataBad =
                                aggregate.PercentDataBad.GetValueOrDefaultEx(),
                            PercentDataGood =
                                aggregate.PercentDataGood.GetValueOrDefaultEx(),
                            TreatUncertainAsBad =
                                aggregate.TreatUncertainAsBad.GetValueOrDefaultEx(),
                            UseSlopedExtrapolation =
                                aggregate.UseSlopedExtrapolation.GetValueOrDefaultEx()
                        },
                        StartOfOnlineArchive = startTime ??
                            config.StartOfOnlineArchive.GetValueOrDefaultEx(
                                v => v == DateTime.MinValue ? startTime : v),
                        StartOfArchive =
                            config.StartOfArchive.GetValueOrDefaultEx(
                                v => v == DateTime.MinValue ? startTime : v) ?? startTime,
                        EndOfArchive = endTime
                    }
                };
            }, request.Header, ct).ConfigureAwait(false);
        }