/// <inheritdoc/>
        public async Task <HistoryReadResponseApiModel <VariantValue> > HistoryReadRawAsync(
            EndpointApiModel endpoint, HistoryReadRequestApiModel <VariantValue> request,
            CancellationToken ct)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }
            if (string.IsNullOrEmpty(endpoint.Url))
            {
                throw new ArgumentNullException(nameof(endpoint.Url));
            }
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (request.Details == null)
            {
                throw new ArgumentNullException(nameof(request.Details));
            }
            var response = await _methodClient.CallMethodAsync(_deviceId, _moduleId,
                                                               "HistoryRead_V2", _serializer.SerializeToString(new {
                endpoint,
                request
            }), null, ct);

            return(_serializer.Deserialize <HistoryReadResponseApiModel <VariantValue> >(response));
        }
        /// <summary>
        /// Read entire event history
        /// </summary>
        /// <param name="client"></param>
        /// <param name="endpointId"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public static async Task <IEnumerable <HistoricEventApiModel> > HistoryReadAllEventsAsync(
            this IHistoryServiceApi client, string endpointId,
            HistoryReadRequestApiModel <ReadEventsDetailsApiModel> request)
        {
            var result = await client.HistoryReadEventsAsync(endpointId, request);

            return(await HistoryReadAllRemainingEventsAsync(client, endpointId, request.Header,
                                                            result.ContinuationToken, result.History.AsEnumerable()));
        }
        public async Task <HistoryReadResponseApiModel <VariantValue> > HistoryReadRawAsync(
            string endpointId, [FromBody][Required] HistoryReadRequestApiModel <VariantValue> request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            var readresult = await _client.HistoryReadAsync(
                endpointId, request.ToServiceModel(d => d));

            return(readresult.ToApiModel(d => d));
        }
        /// <summary>
        /// Read history
        /// </summary>
        /// <param name="endpoint"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <HistoryReadResponseApiModel <VariantValue> > HistoryReadAsync(
            EndpointApiModel endpoint, HistoryReadRequestApiModel <VariantValue> request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            var result = await _historian.HistoryReadAsync(
                endpoint.ToServiceModel(), request.ToServiceModel());

            return(result.ToApiModel());
        }
Beispiel #5
0
        /// <summary>
        /// Read history
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <HistoryReadResponseApiModel> HistoryReadAsync(
            HistoryReadRequestApiModel request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            var result = await _historian.HistoryReadAsync(
                _twin.Endpoint, request.ToServiceModel());

            return(new HistoryReadResponseApiModel(result));
        }
        public async Task <HistoryReadResponseApiModel <HistoricValueApiModel[]> > HistoryReadValuesAsync(
            string endpointId,
            [FromBody][Required] HistoryReadRequestApiModel <ReadValuesDetailsApiModel> request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            var readresult = await _historian.HistoryReadValuesAsync(
                endpointId, request.ToServiceModel(d => d.ToServiceModel()));

            return(readresult.ToApiModel(d => d?.Select(v => v.ToApiModel()).ToArray()));
        }
Beispiel #7
0
 /// <summary>
 /// Convert to service model
 /// </summary>
 /// <typeparam name="S"></typeparam>
 /// <typeparam name="T"></typeparam>
 /// <param name="model"></param>
 /// <param name="convert"></param>
 /// <returns></returns>
 public static HistoryReadRequestModel <S> ToServiceModel <S, T>(
     this HistoryReadRequestApiModel <T> model, Func <T, S> convert)
 {
     if (model == null)
     {
         return(null);
     }
     return(new HistoryReadRequestModel <S> {
         Details = convert(model.Details),
         BrowsePath = model.BrowsePath,
         NodeId = model.NodeId,
         IndexRange = model.IndexRange,
         Header = model.Header.ToServiceModel()
     });
 }
Beispiel #8
0
        /// <inheritdoc/>
        public async Task <HistoryReadResponseApiModel <HistoricEventApiModel[]> > HistoryReadEventsAsync(
            string endpointId, HistoryReadRequestApiModel <ReadEventsDetailsApiModel> content)
        {
            if (string.IsNullOrEmpty(endpointId))
            {
                throw new ArgumentNullException(nameof(endpointId));
            }
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }
            var request = _httpClient.NewRequest(
                $"{_serviceUri}/v2/read/{endpointId}/events", _resourceId);

            request.SetContent(content);
            var response = await _httpClient.PostAsync(request).ConfigureAwait(false);

            response.Validate();
            return(response.GetContent <HistoryReadResponseApiModel <HistoricEventApiModel[]> >());
        }
        /// <inheritdoc/>
        public async Task <HistoryReadResponseApiModel <HistoricEventApiModel[]> > HistoryReadEventsAsync(
            string endpointId, HistoryReadRequestApiModel <ReadEventsDetailsApiModel> content,
            CancellationToken ct)
        {
            if (string.IsNullOrEmpty(endpointId))
            {
                throw new ArgumentNullException(nameof(endpointId));
            }
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }
            var request = _httpClient.NewRequest(
                $"{_serviceUri}/v2/read/{endpointId}/events", Resource.Platform);

            _serializer.SerializeToRequest(request, content);
            var response = await _httpClient.PostAsync(request, ct).ConfigureAwait(false);

            response.Validate();
            return(_serializer.DeserializeResponse <HistoryReadResponseApiModel <HistoricEventApiModel[]> >(response));
        }
        /// <inheritdoc/>
        public async Task <HistoryReadResponseApiModel <JToken> > HistoryReadRawAsync(
            string endpointId, HistoryReadRequestApiModel <JToken> content, CancellationToken ct)
        {
            if (string.IsNullOrEmpty(endpointId))
            {
                throw new ArgumentNullException(nameof(endpointId));
            }
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }
            if (content.Details == null)
            {
                throw new ArgumentNullException(nameof(content.Details));
            }
            var request = _httpClient.NewRequest(
                $"{_serviceUri}/v2/history/read/{endpointId}", _resourceId);

            request.SetContent(content);
            var response = await _httpClient.PostAsync(request, ct).ConfigureAwait(false);

            response.Validate();
            return(response.GetContent <HistoryReadResponseApiModel <JToken> >());
        }
Beispiel #11
0
 /// <summary>
 /// Read node history with custom encoded extension object details
 /// </summary>
 /// <param name="api"></param>
 /// <param name="endpointUrl"></param>
 /// <param name="request"></param>
 /// <param name="ct"></param>
 /// <returns></returns>
 public static Task <HistoryReadResponseApiModel <VariantValue> > HistoryReadRawAsync(
     this IHistoryModuleApi api, string endpointUrl, HistoryReadRequestApiModel <VariantValue> request,
     CancellationToken ct = default)
 {
     return(api.HistoryReadRawAsync(NewEndpoint(endpointUrl), request, ct));
 }