//****************************************************************************************************** // MetadataRecordSummary.cs - Gbtc // // Copyright © 2012, 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/14/2007 - Pinal C. Patel // Generated original version of code based on DatAWare system specifications by Brian B. Fox, GSF. // 04/20/2009 - Pinal C. Patel // Converted to C#. // 09/15/2009 - Stephen C. Wills // Added new header and license agreement. // 10/11/2010 - Mihir Brahmbhatt // Updated header and license agreement. // 11/30/2011 - J. Ritchie Carroll // Modified to support buffer optimized ISupportBinaryImage. // 12/14/2012 - Starlynn Danyelle Gilliam // Modified Header. // //****************************************************************************************************** using System; using GSF.Parsing; namespace GSF.Historian.Files { /// /// A class with a subset of information defined in . The generated binary image of /// is sent back as a reply to and /// . /// /// public class MetadataRecordSummary : ISupportBinaryImage { // ************************************************************************************************** // * Binary Structure * // ************************************************************************************************** // * # Of Bytes Byte Index Data Type Property Name * // * ---------- ---------- ---------- --------------------------------------------------------------* // * 4 0-3 Int32 HistorianID * // * 4 4-7 Single ExceptionLimit * // * 4 8-11 Int32 Enabled * // * 4 12-15 Single HighWarning * // * 4 16-19 Single LowWarning * // * 4 20-23 Single HighAlarm * // * 4 24-27 Single LowAlarm * // * 4 28-31 Single HighRange * // * 4 32-35 Single LowRange * // ************************************************************************************************** #region [ Members ] // Constants /// /// Specifies the number of bytes in the binary image of . /// public const int FixedLength = 36; // Fields private int m_historianID; private float m_exceptionLimit; private int m_enabled; private float m_highWarning; private float m_lowWarning; private float m_highAlarm; private float m_lowAlarm; private float m_highRange; private float m_lowRange; #endregion #region [ Constructors ] /// /// Initializes a new instance of the class. /// /// A object. public MetadataRecordSummary(MetadataRecord record) { HistorianID = record.HistorianID; ExceptionLimit = record.AnalogFields.ExceptionLimit; Enabled = record.GeneralFlags.Enabled; HighWarning = record.AnalogFields.HighWarning; LowWarning = record.AnalogFields.LowWarning; HighAlarm = record.AnalogFields.HighAlarm; LowAlarm = record.AnalogFields.LowAlarm; HighRange = record.AnalogFields.HighRange; LowRange = record.AnalogFields.LowRange; } /// /// Initializes a new instance of the class. /// /// Binary image to be used for initializing . /// 0-based starting index of initialization data in the . /// Valid number of bytes in from . public MetadataRecordSummary(byte[] buffer, int startIndex, int length) { ParseBinaryImage(buffer, startIndex, length); } #endregion #region [ Properties ] /// /// Same as . /// /// The value being assigned is not positive or -1. public int HistorianID { get { return m_historianID; } private set { if (value < 1 && value != -1) throw new ArgumentException("Value must be positive or -1"); m_historianID = value; } } /// /// Same as . /// public float ExceptionLimit { get { return m_exceptionLimit; } private set { m_exceptionLimit = value; } } /// /// Same as . /// public bool Enabled { get { return Convert.ToBoolean(m_enabled); } private set { m_enabled = Convert.ToInt32(value); } } /// /// Same as . /// public float HighWarning { get { return m_highWarning; } private set { m_highWarning = value; } } /// /// Same as . /// public float LowWarning { get { return m_lowWarning; } private set { m_lowWarning = value; } } /// /// Same as . /// public float HighAlarm { get { return m_highAlarm; } private set { m_highAlarm = value; } } /// /// Same as . /// public float LowAlarm { get { return m_lowAlarm; } private set { m_lowAlarm = value; } } /// /// Same as . /// public float HighRange { get { return m_highRange; } private set { m_highRange = value; } } /// /// Same as . /// public float LowRange { get { return m_lowRange; } private set { m_lowRange = value; } } /// /// Gets the length of the . /// public int BinaryLength { get { return FixedLength; } } #endregion #region [ Methods ] /// /// Initializes from the specified . /// /// Binary image to be used for initializing . /// 0-based starting index of initialization data in the . /// Valid number of bytes in from . /// Number of bytes used from the for initializing . public int ParseBinaryImage(byte[] buffer, int startIndex, int length) { if (length >= FixedLength) { // Binary image has sufficient data. HistorianID = LittleEndian.ToInt32(buffer, startIndex + 0); ExceptionLimit = LittleEndian.ToSingle(buffer, startIndex + 4); Enabled = Convert.ToBoolean(LittleEndian.ToInt32(buffer, startIndex + 8)); HighWarning = LittleEndian.ToSingle(buffer, startIndex + 12); LowWarning = LittleEndian.ToSingle(buffer, startIndex + 16); HighAlarm = LittleEndian.ToSingle(buffer, startIndex + 20); LowAlarm = LittleEndian.ToSingle(buffer, startIndex + 24); HighRange = LittleEndian.ToSingle(buffer, startIndex + 28); LowRange = LittleEndian.ToSingle(buffer, startIndex + 32); return FixedLength; } else { // Binary image does not have sufficient data. return 0; } } /// /// Generates binary image of the and copies it into the given buffer, for bytes. /// /// Buffer used to hold generated binary image of the source object. /// 0-based starting index in the to start writing. /// The number of bytes written to the . /// is null. /// /// or is less than 0 -or- /// and will exceed length. /// public virtual int GenerateBinaryImage(byte[] buffer, int startIndex) { int length = BinaryLength; buffer.ValidateParameters(startIndex, length); Buffer.BlockCopy(LittleEndian.GetBytes(m_historianID), 0, buffer, startIndex, 4); Buffer.BlockCopy(LittleEndian.GetBytes(m_exceptionLimit), 0, buffer, startIndex + 4, 4); Buffer.BlockCopy(LittleEndian.GetBytes(Convert.ToInt32(m_enabled)), 0, buffer, startIndex + 8, 4); Buffer.BlockCopy(LittleEndian.GetBytes(m_highWarning), 0, buffer, startIndex + 12, 4); Buffer.BlockCopy(LittleEndian.GetBytes(m_lowWarning), 0, buffer, startIndex + 16, 4); Buffer.BlockCopy(LittleEndian.GetBytes(m_highAlarm), 0, buffer, startIndex + 20, 4); Buffer.BlockCopy(LittleEndian.GetBytes(m_lowAlarm), 0, buffer, startIndex + 24, 4); Buffer.BlockCopy(LittleEndian.GetBytes(m_highRange), 0, buffer, startIndex + 28, 4); Buffer.BlockCopy(LittleEndian.GetBytes(m_lowRange), 0, buffer, startIndex + 32, 4); return length; } #endregion } }