Ejemplo n.º 1
0
        /// <summary>
        /// Converts an Aika <see cref="TagValue"/> into an Elasticsearch <see cref="TagValueDocument"/>.
        /// </summary>
        /// <param name="value">The Aika tag value.</param>
        /// <param name="tag">The tag that the value is for.</param>
        /// <param name="documentId">
        ///   The optional document ID to assign to the <see cref="TagValueDocument"/>.  Specify
        ///   <see langword="null"/> for archive values, and the tag ID for snapshot and archive
        ///   candidate values (so that the existing snapshot or archive candidate document for
        ///   the tag will be replaced).
        /// </param>
        /// <returns>
        /// An equivalent <see cref="TagValueDocument"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="value"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="tag"/> is <see langword="null"/>.</exception>
        public static TagValueDocument ToTagValueDocument(this TagValue value, ElasticsearchTagDefinition tag, Guid?documentId)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (tag == null)
            {
                throw new ArgumentNullException(nameof(tag));
            }

            return(new TagValueDocument()
            {
                Id = documentId.HasValue
                    ? documentId.Value
                    : Guid.NewGuid(),
                TagId = tag.IdAsGuid,
                UtcSampleTime = value.UtcSampleTime,
                NumericValue = tag.DataType == TagDataType.Text
                    ? Double.NaN
                    : value.NumericValue,
                TextValue = tag.DataType == TagDataType.FloatingPoint || tag.DataType == TagDataType.Integer
                    ? null
                    : value.TextValue,
                Quality = value.Quality
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the index name to use when archiving a value for the specified sample time and tag definition.
        /// </summary>
        /// <param name="baseName">The base index name.</param>
        /// <param name="tag">The tag.</param>
        /// <param name="utcSampleTime">The UTC sample time for the tag to be archived.</param>
        /// <param name="suffixGenerator">
        ///   A delegate function that can determine the suffix to use for the index.  Specify
        ///   <see langword="null"/> to use the default suffix, which is the <paramref name="utcSampleTime"/>
        ///   in <c>yyyy-MM</c> format (i.e. the year and month of the sample time).
        /// </param>
        /// <returns>
        /// The index name to use.
        /// </returns>
        public static string GetIndexNameForArchiveTagValue(string baseName, ElasticsearchTagDefinition tag, DateTime utcSampleTime, ArchiveIndexNameSuffixGenerator suffixGenerator)
        {
            var suffix = suffixGenerator == null
                ? utcSampleTime.ToString("yyyy-MM")
                : suffixGenerator.Invoke(tag, utcSampleTime);

            return(baseName + suffix);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts an <see cref="ElasticsearchTagDefinition"/> into a <see cref="TagDocument"/> that
        /// will be stored in Elasticsearch.
        /// </summary>
        /// <param name="tag">The tag definition.</param>
        /// <returns>
        /// The equivalent <see cref="TagDocument"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="tag"/> is <see langword="null"/>.</exception>
        public static TagDocument ToTagDocument(this ElasticsearchTagDefinition tag)
        {
            if (tag == null)
            {
                throw new ArgumentNullException(nameof(tag));
            }

            return(new TagDocument()
            {
                Id = tag.IdAsGuid,
                Name = tag.Name,
                Description = tag.Description,
                Units = tag.Units,
                DataType = tag.DataType,
                StateSet = tag.StateSet,
                ExceptionFilter = new TagValueFilterSettingsUpdate()
                {
                    IsEnabled = tag.DataFilter.ExceptionFilter.Settings.IsEnabled,
                    LimitType = tag.DataFilter.ExceptionFilter.Settings.LimitType,
                    Limit = tag.DataFilter.ExceptionFilter.Settings.Limit,
                    WindowSize = tag.DataFilter.ExceptionFilter.Settings.WindowSize
                },
                CompressionFilter = new TagValueFilterSettingsUpdate()
                {
                    IsEnabled = tag.DataFilter.CompressionFilter.Settings.IsEnabled,
                    LimitType = tag.DataFilter.CompressionFilter.Settings.LimitType,
                    Limit = tag.DataFilter.CompressionFilter.Settings.Limit,
                    WindowSize = tag.DataFilter.CompressionFilter.Settings.WindowSize
                },
                Security = tag.Security.ToTagDocumentSecurity(),
                Metadata = new TagDocument.TagMetadata()
                {
                    UtcCreatedAt = tag.Metadata.UtcCreatedAt,
                    Creator = tag.Metadata.Creator,
                    UtcLastModifiedAt = tag.Metadata.UtcLastModifiedAt,
                    LastModifiedBy = tag.Metadata.LastModifiedBy
                }
            });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Converts an Aika <see cref="ArchiveCandidateValue"/> into an Elasticsearch <see cref="TagValueDocument"/>.
        /// </summary>
        /// <param name="value">The Aika archive candidate value.</param>
        /// <param name="tag">The tag that the value is for.</param>
        /// <param name="documentId">
        ///   The optional document ID to assign to the <see cref="TagValueDocument"/>.  Specify
        ///   <see langword="null"/> for archive values, and the tag ID for snapshot and archive
        ///   candidate values (so that the existing snapshot or archive candidate document for
        ///   the tag will be replaced).
        /// </param>
        /// <returns>
        /// An equivalent <see cref="TagValueDocument"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="value"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="tag"/> is <see langword="null"/>.</exception>
        public static TagValueDocument ToTagValueDocument(this ArchiveCandidateValue value, ElasticsearchTagDefinition tag, Guid?documentId)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (tag == null)
            {
                throw new ArgumentNullException(nameof(tag));
            }

            var val = value?.Value.ToTagValueDocument(tag, documentId);

            val.Properties = new Dictionary <string, object>()
            {
                { "CompressionAngleMinimum", value.CompressionAngleMinimum },
                { "CompressionAngleMaximum", value.CompressionAngleMaximum }
            };

            return(val);
        }