//****************************************************************************************************** // ChannelMetadata.cs - Gbtc // // Copyright © 2010, 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://www.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: // ---------------------------------------------------------------------------------------------------- // 06/19/2013 - J. Ritchie Carroll // Generated original version of source code. // //****************************************************************************************************** using System.Collections.Generic; using GSF.Units.EE; namespace GSF.COMTRADE { /// /// Defines a minimal set of channel metadata for a COMTRADE config file. /// public struct ChannelMetadata { /// /// Channel name. /// public string Name; /// /// Channel signal type. /// public SignalType SignalType; /// /// Determines if channel is a digital. /// /// /// Channel is assumed to be an analog if field is false. /// public bool IsDigital; /// /// Defines units to use for channel. /// /// /// Leave null for defaults. /// public string Units; /// /// Defines circuit component channel. /// /// /// Leave null for none. /// public string CircuitComponent; } /// /// Defines a comparison class to property sort metadata. /// public class ChannelMetadataSorter : IComparer { /// /// Compares one metadata record to another. /// /// Left metadata record to compare. /// Right metadata record to compare. /// Comparison sort order of metadata record. public int Compare(ChannelMetadata left, ChannelMetadata right) { // Make sure digitals (status flags first) fall behind analogs. All // values not in the dictionary will return 0 thus sorting higher. s_sortOrder.TryGetValue(left.SignalType, out int leftIndex); s_sortOrder.TryGetValue(right.SignalType, out int rightIndex); return leftIndex.CompareTo(rightIndex); } /// /// Default instance of the metadata record sorter. /// public static readonly ChannelMetadataSorter Default; private static readonly Dictionary s_sortOrder; static ChannelMetadataSorter() { // Define proper sort order for key signal types. Status flags are types of digital fields, but // they are stored as a 32-bit value with an abstracted set of flags (high order) as well as the // original flags (low order), since they are greater than 16-bits they are defined in the historian // as an analog value. Even so they need to sort as a digital. s_sortOrder = new Dictionary { { SignalType.FLAG, 1 }, // Status Flags { SignalType.DIGI, 2 }, // Digital Value { SignalType.QUAL, 3 } // Quality Flags }; Default = new ChannelMetadataSorter(); } } }