/// <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; }
/// <summary> /// Loads the snapshot value for the specified tag from Redis. /// </summary> /// <param name="historian">The historian.</param> /// <param name="tagId">The tag ID.</param> /// <param name="cancellationToken">The cancellation token for the request.</param> /// <returns> /// A task that will return the snapshot value. /// </returns> private static async Task <TagValue> LoadSnapshotValue(RedisHistorian historian, string tagId, CancellationToken cancellationToken) { var key = historian.GetKeyForSnapshotData(tagId); var valuesTask = historian.Connection.GetDatabase().HashGetAllAsync(key); await Task.WhenAny(valuesTask, Task.Delay(-1, cancellationToken)).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); if (valuesTask.Result.Length == 0) { return(null); } return(GetTagValueFromHashValues(valuesTask.Result)); }