Beispiel #1
0
 /// <summary>
 /// When implemented in a derived class, inserts values into the historian archive.
 /// </summary>
 /// <param name="values">The values to insert.  Can be <see langword="null"/> or empty if only the <paramref name="nextArchiveCandidate"/> is being updated.</param>
 /// <param name="nextArchiveCandidate">The candidate for the next value to write to the archive.</param>
 /// <param name="cancellationToken">The cancellation token for the request.</param>
 /// <returns>
 /// The result of the insert.
 /// </returns>
 protected abstract Task <WriteTagValuesResult> InsertArchiveValues(IEnumerable <TagValue> values, ArchiveCandidateValue nextArchiveCandidate, CancellationToken cancellationToken);
Beispiel #2
0
        /// <summary>
        /// Inserts values into the historian archive, optionally skipping value validation (e.g. if
        /// the insert is because of a value emitted from the compression filter).
        /// </summary>
        /// <param name="identity">The identity of the caller.</param>
        /// <param name="values">The values to insert.</param>
        /// <param name="nextArchiveCandidate">The current candidate for the next value to be inserted.</param>
        /// <param name="validate">Flags if the values should be validated before sending to the archive.</param>
        /// <param name="cancellationToken">The cancellation token for the request.</param>
        /// <returns>
        /// A task that will return the write result.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="identity"/> is <see langword="null"/>.</exception>
        private async Task <WriteTagValuesResult> InsertArchiveValuesInternal(ClaimsPrincipal identity, IEnumerable <TagValue> values, ArchiveCandidateValue nextArchiveCandidate, bool validate, CancellationToken cancellationToken)
        {
            if (!values?.Any() ?? false)
            {
                await InsertArchiveValues(null, nextArchiveCandidate, cancellationToken).ConfigureAwait(false);

                return(WriteTagValuesResult.CreateEmptyResult());
            }

            var stateSet = await GetStateSet(identity, cancellationToken).ConfigureAwait(false);

            if (validate)
            {
                var vals = new List <TagValue>();
                foreach (var value in values)
                {
                    if (validate)
                    {
                        if (!this.TryValidateIncomingTagValue(value, stateSet, out var validatedValue))
                        {
                            continue;
                        }

                        vals.Add(validatedValue);
                    }
                }

                values = vals.ToArray();
            }

            try {
                return(await InsertArchiveValues(values, nextArchiveCandidate, cancellationToken).ConfigureAwait(false));
            }
            catch (Exception e) {
                return(new WriteTagValuesResult(false, 0, null, null, new[] { e.Message }));
            }
        }