Esempio n. 1
0
        /// <summary>
        /// Creates a new <see cref="RedisTagDefinition"/> object.
        /// </summary>
        /// <param name="historian">The owning historian.</param>
        /// <param name="id">The tag ID.</param>
        /// <param name="settings">The tag settings.</param>
        /// <param name="metadata">The metadata for the tag.</param>
        /// <param name="initialTagValues">The initial tag values, used to prime the exception and compression filters for the tag.</param>
        /// <param name="changeHistory">The change history for the tag.</param>
        private RedisTagDefinition(RedisHistorian historian, string id, TagSettings settings, TagMetadata metadata, InitialTagValues initialTagValues, IEnumerable <TagChangeHistoryEntry> changeHistory) : base(historian, id, settings, metadata, CreateTagSecurity(), initialTagValues, changeHistory)
        {
            _historian           = historian ?? throw new ArgumentNullException(nameof(historian));
            _tagDefinitionKey    = _historian.GetKeyForTagDefinition(Id);
            _snapshotKey         = _historian.GetKeyForSnapshotData(Id);
            _archiveKey          = _historian.GetKeyForRawData(Id);
            _archiveCandidateKey = _historian.GetKeyForArchiveCandidateData(Id);

            _archiveCandidateValue = new ArchiveCandidateValue(initialTagValues?.LastExceptionValue, initialTagValues?.CompressionAngleMinimum ?? Double.NaN, initialTagValues?.CompressionAngleMaximum ?? Double.NaN);

            Updated += TagUpdated;
        }
Esempio n. 2
0
 /// <summary>
 /// Creates a new <see cref="ElasticsearchTagDefinition"/> object.
 /// </summary>
 /// <param name="historian">The owning historian.</param>
 /// <param name="id">The tag ID.</param>
 /// <param name="settings">The tag settings.</param>
 /// <param name="metadata">The tag metadata.</param>
 /// <param name="security">The tag security configuration.</param>
 /// <param name="initialTagValues">The initial tag values, to use with the exception and compression filters.</param>
 /// <param name="changeHistory">The change history information for the tag.</param>
 /// <exception cref="ArgumentNullException"><paramref name="historian"/> is <see langword="null"/>.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="security"/> is <see langword="null"/>.</exception>
 internal ElasticsearchTagDefinition(ElasticsearchHistorian historian, Guid id, TagSettings settings, TagMetadata metadata, TagSecurity security, InitialTagValues initialTagValues, IEnumerable <TagChangeHistoryEntry> changeHistory) : base(historian, id.ToString(), settings, metadata, security, initialTagValues, changeHistory)
 {
     _historian = historian ?? throw new ArgumentNullException(nameof(historian));
     IdAsGuid   = id;
 }
Esempio n. 3
0
        /// <summary>
        /// Loads a tag definition from the Redis database.
        /// </summary>
        /// <param name="historian">The Redis historian to load the tag from.</param>
        /// <param name="tagId">The ID of the tag to load.</param>
        /// <param name="cancellationToken">The cancellation token for the request.</param>
        /// <returns>
        /// A task that will return the loaded tag definition.
        /// </returns>
        internal static async Task <RedisTagDefinition> Load(RedisHistorian historian, string tagId, CancellationToken cancellationToken)
        {
            var values = await historian.Connection.GetDatabase().HashGetAllAsync(historian.GetKeyForTagDefinition(tagId)).ConfigureAwait(false);

            cancellationToken.ThrowIfCancellationRequested();

            string      name        = null;
            string      description = null;
            string      units       = null;
            TagDataType dataType    = default(TagDataType);
            string      stateSet    = null;

            bool exceptionFilterEnabled = false;
            TagValueFilterDeviationType exceptionFilterLimitType = default(TagValueFilterDeviationType);
            double   exceptionFilterLimit      = 0;
            TimeSpan exceptionFilterWindowSize = default(TimeSpan);

            bool compressionFilterEnabled = false;
            TagValueFilterDeviationType compressionFilterLimitType = default(TagValueFilterDeviationType);
            double   compressionFilterLimit      = 0;
            TimeSpan compressionFilterWindowSize = default(TimeSpan);

            DateTime createdAt  = DateTime.MinValue;
            string   creator    = null;
            DateTime modifiedAt = DateTime.MinValue;
            string   modifiedBy = null;

            foreach (var item in values)
            {
                switch (item.Name.ToString())
                {
                case "NAME":
                    name = item.Value;
                    break;

                case "DESC":
                    description = item.Value;
                    break;

                case "UNITS":
                    units = item.Value;
                    break;

                case "TYPE":
                    dataType = (TagDataType)((int)item.Value);
                    break;

                case "SSET":
                    stateSet = item.Value;
                    break;

                case "EXC_ENABLED":
                    exceptionFilterEnabled = Convert.ToBoolean((int)item.Value);
                    break;

                case "EXC_LIMIT_TYPE":
                    exceptionFilterLimitType = (TagValueFilterDeviationType)((int)item.Value);
                    break;

                case "EXC_LIMIT":
                    exceptionFilterLimit = (double)item.Value;
                    break;

                case "EXC_WINDOW":
                    exceptionFilterWindowSize = TimeSpan.Parse(item.Value);
                    break;

                case "COM_ENABLED":
                    compressionFilterEnabled = Convert.ToBoolean((int)item.Value);
                    break;

                case "COM_LIMIT_TYPE":
                    compressionFilterLimitType = (TagValueFilterDeviationType)((int)item.Value);
                    break;

                case "COM_LIMIT":
                    compressionFilterLimit = (double)item.Value;
                    break;

                case "COM_WINDOW":
                    compressionFilterWindowSize = TimeSpan.Parse(item.Value);
                    break;

                case "MD_CREATEDAT":
                    createdAt = new DateTime((long)item.Value, DateTimeKind.Utc);
                    break;

                case "MD_CREATEDBY":
                    creator = item.Value;
                    break;

                case "MD_MODIFIEDAT":
                    modifiedAt = new DateTime((long)item.Value, DateTimeKind.Utc);
                    break;

                case "MD_MODIFIEDBY":
                    modifiedBy = item.Value;
                    break;
                }
            }

            if (String.IsNullOrWhiteSpace(name))
            {
                name = tagId;
            }

            var settings = new TagSettings()
            {
                Name                    = name,
                Description             = description,
                Units                   = units,
                DataType                = dataType,
                StateSet                = stateSet,
                ExceptionFilterSettings = new TagValueFilterSettingsUpdate()
                {
                    IsEnabled  = exceptionFilterEnabled,
                    LimitType  = exceptionFilterLimitType,
                    Limit      = exceptionFilterLimit,
                    WindowSize = exceptionFilterWindowSize
                },
                CompressionFilterSettings = new TagValueFilterSettingsUpdate()
                {
                    IsEnabled  = compressionFilterEnabled,
                    LimitType  = compressionFilterLimitType,
                    Limit      = compressionFilterLimit,
                    WindowSize = compressionFilterWindowSize
                }
            };

            var metadata = new TagMetadata(createdAt, creator, modifiedAt, modifiedBy);

            var snapshotTask         = LoadSnapshotValue(historian, tagId, cancellationToken);
            var lastArchivedTask     = LoadLastArchivedValue(historian, tagId, cancellationToken);
            var archiveCandidateTask = LoadArchiveCandidateValue(historian, tagId, cancellationToken);

            await Task.WhenAll(snapshotTask, lastArchivedTask, archiveCandidateTask).ConfigureAwait(false);

            cancellationToken.ThrowIfCancellationRequested();

            var initialValues = new InitialTagValues(snapshotTask.Result, lastArchivedTask.Result, archiveCandidateTask.Result.Value, archiveCandidateTask.Result.CompressionAngleMinimum, archiveCandidateTask.Result.CompressionAngleMaximum);

            var result = new RedisTagDefinition(historian,
                                                tagId,
                                                settings,
                                                metadata,
                                                initialValues,
                                                null);

            return(result);
        }