Esempio n. 1
0
            /// <summary>
            /// Creates a new <see cref="SnapshotValueSubscription"/> object.
            /// </summary>
            /// <param name="tag">The tag.</param>
            /// <param name="onValueChange">The value change callback.</param>
            internal SnapshotValueSubscription(TagDefinition tag, Action <TagValue> onValueChange)
            {
                _tag           = tag ?? throw new ArgumentNullException(nameof(tag));
                _onValueChange = onValueChange ?? throw new ArgumentNullException(nameof(onValueChange));

                _tag._snapshotSubscriptions[this] = new object();
                _tag.SnapshotValueSubscriptionChange?.Invoke(_tag);
            }
Esempio n. 2
0
 /// <summary>
 /// Tests if the specified identity is authorized to write tag data.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <param name="identity">The identity.</param>
 /// <returns>
 /// <see langword="true"/> if the caller is authorized, otherwise <see langword="false"/>.
 /// </returns>
 /// <exception cref="ArgumentNullException"><paramref name="tag"/> is <see langword="null"/>.</exception>
 public static bool CanWrite(this TagDefinition tag, ClaimsPrincipal identity)
 {
     if (tag == null)
     {
         throw new ArgumentNullException(nameof(tag));
     }
     return(tag.IsAuthorized(identity, Tags.Security.TagSecurityPolicy.DataWrite, Tags.Security.TagSecurityPolicy.Administrator));
 }
Esempio n. 3
0
        /// <summary>
        /// Attempts to validate an incoming tag value.
        /// </summary>
        /// <param name="tag">The tag that the value is for.</param>
        /// <param name="incoming">The incoming tag value.</param>
        /// <param name="stateSet">
        ///   The state set for the tag.  Can be <see langword="null"/> when the tag's data type is not
        ///   <see cref="TagDataType.State"/>.
        /// </param>
        /// <param name="validatedValue">The validated tag value.</param>
        /// <returns>
        /// <see langword="true"/> if the value could be validated, or <see langword="false"/> otherwise.
        /// When the result is <see langword="false"/>, <paramref name="validatedValue"/> will be
        /// <see langword="null"/>.
        /// </returns>
        internal static bool TryValidateIncomingTagValue(this TagDefinition tag, TagValue incoming, StateSet stateSet, out TagValue validatedValue)
        {
            if (tag == null)
            {
                throw new ArgumentNullException(nameof(tag));
            }
            if (incoming == null)
            {
                throw new ArgumentNullException(nameof(incoming));
            }

            bool result;

            switch (tag.DataType)
            {
            case TagDataType.FloatingPoint:
                result = TryValidateDoubleValue(tag, incoming, out validatedValue);
                break;

            case TagDataType.Integer:
                result = TryValidateInt32Value(tag, incoming, out validatedValue);
                break;

            case TagDataType.Text:
                result = TryValidateStringValue(tag, incoming, out validatedValue);
                break;

            case TagDataType.State:
                result = TryValidateStateValue(tag, incoming, stateSet, out validatedValue);
                break;

            default:
                validatedValue = null;
                result         = false;
                break;
            }

            return(result);
        }
Esempio n. 4
0
 /// <summary>
 /// Attempts to validate an incoming floating-point tag value.
 /// </summary>
 /// <param name="tag">The tag for the value.</param>
 /// <param name="originalValue">The incoming value.</param>
 /// <param name="validatedValue">The validated value.</param>
 /// <returns>
 /// A flag that indicates if the value was validated.
 /// </returns>
 private static bool TryValidateDoubleValue(TagDefinition tag, TagValue originalValue, out TagValue validatedValue)
 {
     validatedValue = new TagValue(originalValue.UtcSampleTime, originalValue.NumericValue, Convert.ToString(originalValue.NumericValue, CultureInfo.InvariantCulture), originalValue.Quality, tag.Units);
     return(true);
 }
Esempio n. 5
0
 /// <summary>
 /// Attempts to validate an incoming string tag value.
 /// </summary>
 /// <param name="tag">The tag for the value.</param>
 /// <param name="originalValue">The incoming value.</param>
 /// <param name="validatedValue">The validated value.</param>
 /// <returns>
 /// A flag that indicates if the value was validated.
 /// </returns>
 private static bool TryValidateStringValue(TagDefinition tag, TagValue originalValue, out TagValue validatedValue)
 {
     validatedValue = new TagValue(originalValue.UtcSampleTime, Double.NaN, originalValue.TextValue, originalValue.Quality, null);
     return(true);
 }