Ejemplo n.º 1
0
        /// <summary>
        /// Attempts to convert the string representation of a <see cref="MeasurementKey"/> into its value equivalent.
        /// </summary>
        /// <param name="value">A string representing the <see cref="MeasurementKey"/> to convert.</param>
        /// <param name="key">Output <see cref="MeasurementKey"/> in which to stored parsed value.</param>
        /// <returns>A <c>true</c> if <see cref="MeasurementKey"/>representation contained in <paramref name="value"/> could be parsed; otherwise <c>false</c>.</returns>
        public static bool TryParse(string value, out MeasurementKey key)
        {
            // Split the input into source and ID
            if (TrySplit(value, out string source, out ulong id))
            {
                // First attempt to look up an existing key
                key = LookUpBySource(source, id);

                if (key == Undefined)
                {
                    try
                    {
                        // Lookup failed - attempt to create it with a newly generated signal ID
                        key = CreateOrUpdate(Guid.NewGuid(), source, id);
                    }
                    catch
                    {
                        // source is null or empty
                        key = Undefined;
                    }
                }
            }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new instance of <see cref="MeasurementMetadata"/> using the provided measurement <paramref name="key"/>. All other fields remain the same.
 /// </summary>
 /// <param name="key">The key to set.</param>
 /// <returns>New instance of <see cref="MeasurementMetadata"/> using the provided measurement <paramref name="key"/>.</returns>
 public MeasurementMetadata ChangeKey(MeasurementKey key) => Key == key ? this : new MeasurementMetadata(key, TagName, Adder, Multiplier);