//******************************************************************************************************
// CommonMeasurementFields.cs - Gbtc
//
// Copyright © 2016, Grid Protection Alliance. All Rights Reserved.
//
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
// file except in compliance with the License. You may obtain a copy of the License at:
//
// http://opensource.org/licenses/MIT
//
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
// License for the specific language governing permissions and limitations.
//
// Code Modification History:
// ----------------------------------------------------------------------------------------------------
// 11/18/2016 - Steven E. Chisholm
// Generated original version of source code.
//
//******************************************************************************************************
using System;
namespace GSF.TimeSeries
{
///
/// Represents a set of meta-data fields for that should rarely change.
///
///
/// This class allows measurement meta-data to be quickly transferred from one to
/// another. This class is immutable, so any change to these values requires that the class be recreated.
///
[Serializable]
public class MeasurementMetadata
{
#region [ Members ]
// Fields
///
/// Gets or sets the primary key of this .
///
public readonly MeasurementKey Key;
///
/// Gets or sets the text based tag name of this .
///
public readonly string TagName;
///
/// Defines an offset to add to the value.
///
///
/// Implementers should make sure this value defaults to zero.
///
public readonly double Adder;
///
/// Defines a multiplicative offset to apply to the value.
///
///
/// Implementers should make sure this value defaults to one.
///
public readonly double Multiplier;
///
/// Gets or sets function used to apply a down-sampling filter over a sequence of values.
///
public readonly MeasurementValueFilterFunction MeasurementValueFilter;
#endregion
#region [ Constructors ]
///
/// Creates a
///
/// Gets or sets the primary key of this .
/// Gets or sets the text based tag name of this .
/// Defines an offset to add to the value.
/// Defines a multiplicative offset to apply to the value.
/// Gets or sets function used to apply a down-sampling filter over a sequence of values.
public MeasurementMetadata(MeasurementKey key, string tagName, double adder, double multiplier, MeasurementValueFilterFunction measurementValueFilter)
{
Key = key;
TagName = tagName;
Adder = adder;
Multiplier = multiplier;
MeasurementValueFilter = measurementValueFilter;
}
#endregion
#region [ Methods ]
///
/// Creates a new instance of using the provided measurement . All other fields remain the same.
///
/// The key to set.
/// New instance of using the provided measurement .
public MeasurementMetadata ChangeKey(MeasurementKey key) => Key == key ? this : new MeasurementMetadata(key, TagName, Adder, Multiplier, MeasurementValueFilter);
///
/// Creates a new instance of using the provided . All other fields remain the same.
///
/// The adder to set.
/// New instance of using the provided .
public MeasurementMetadata ChangeAdder(double adder) => Adder == adder ? this : new MeasurementMetadata(Key, TagName, adder, Multiplier, MeasurementValueFilter);
///
/// Creates a new instance of using the provided and . All other fields remain the same.
///
/// The adder to set.
/// The multiplier to set.
/// New instance of using the provided and .
public MeasurementMetadata ChangeAdderMultiplier(double adder, double multiplier) => Adder == adder && Multiplier == multiplier ? this : new MeasurementMetadata(Key, TagName, adder, multiplier, MeasurementValueFilter);
///
/// Creates a new instance of using the provided . All other fields remain the same.
///
/// The multiplier to set.
/// New instance of using the provided .
public MeasurementMetadata ChangeMultiplier(double multiplier) => Multiplier == multiplier ? this : new MeasurementMetadata(Key, TagName, Adder, multiplier, MeasurementValueFilter);
///
/// Creates a new instance of using the provided . All other fields remain the same.
///
/// The tag name to set.
/// New instance of using the provided .
public MeasurementMetadata ChangeTagName(string tagName) => TagName == tagName ? this : new MeasurementMetadata(Key, tagName, Adder, Multiplier, MeasurementValueFilter);
///
/// Creates a new instance of using the provided . All other fields remain the same.
///
/// the measurementValueFilter to set.
/// New instance of using the provided .
public MeasurementMetadata ChangeMeasurementValueFilter(MeasurementValueFilterFunction measurementValueFilter) => ReferenceEquals(MeasurementValueFilter, measurementValueFilter) ? this : new MeasurementMetadata(Key, TagName, Adder, Multiplier, measurementValueFilter);
#endregion
#region [ Static ]
// Static Fields
private static MeasurementMetadata s_undefined;
// Static Properties
///
/// Represents an undefined .
///
public static MeasurementMetadata Undefined => s_undefined;
// Static Methods
// Create measurement metadata for undefined
internal static void CreateUndefinedMeasurementMetadata()
{
s_undefined = s_undefined ?? new MeasurementMetadata(MeasurementKey.Undefined, null, 0, 1, null);
}
#endregion
}
}