200 lines · 8.3 KB · C#
RawDownload
//******************************************************************************************************//  StateRecordSummary.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 source code.//  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{    /// <summary>    /// A class with just <see cref="StateRecord.CurrentData"/>. The generated binary image of <see cref="MetadataRecordSummary"/>     /// is sent back as a reply to <see cref="Historian.Packets.PacketType11"/>.    /// </summary>    /// <seealso cref="StateRecord"/>    /// <seealso cref="Historian.Packets.PacketType11"/>    public class StateRecordSummary : ISupportBinaryImage    {        // **************************************************************************************************        // *                                        Binary Structure                                        *        // **************************************************************************************************        // * # Of Bytes Byte Index Data Type  Property Name                                                 *        // * ---------- ---------- ---------- --------------------------------------------------------------*        // * 4          0-3        Int32      HistorianID                                                   *        // * 16         4-19       Byte(16)   CurrentData                                                   *        // **************************************************************************************************         #region [ Members ]         // Constants         /// <summary>        /// Specifies the number of bytes in the binary image of <see cref="StateRecordSummary"/>.        /// </summary>        public const int FixedLength = 20;         // Fields        private int m_historianID;        private StateRecordDataPoint m_currentData;         #endregion         #region [ Constructors ]         /// <summary>        /// Initializes a new instance of the <see cref="StateRecordSummary"/> class.        /// </summary>        /// <param name="record">A <see cref="StateRecord"/> object.</param>        public StateRecordSummary(StateRecord record)        {            HistorianID = record.HistorianID;            CurrentData = record.CurrentData;        }         /// <summary>        /// Initializes a new instance of the <see cref="StateRecordSummary"/> class.        /// </summary>        /// <param name="buffer">Binary image to be used for initializing <see cref="StateRecordSummary"/>.</param>        /// <param name="startIndex">0-based starting index of initialization data in the <paramref name="buffer"/>.</param>        /// <param name="length">Valid number of bytes in <paramref name="buffer"/> from <paramref name="startIndex"/>.</param>        public StateRecordSummary(byte[] buffer, int startIndex, int length)        {            ParseBinaryImage(buffer, startIndex, length);        }         #endregion         #region [ Properties ]         /// <summary>        /// Same as <see cref="StateRecord.HistorianID"/>.        /// </summary>        /// <exception cref="ArgumentException">The value being assigned is not positive or -1.</exception>        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;            }        }         /// <summary>        /// Same as <see cref="StateRecord.CurrentData"/>.        /// </summary>        /// <exception cref="ArgumentNullException">The value being assigned is null.</exception>        public StateRecordDataPoint CurrentData        {            get            {                return m_currentData;            }            private set            {                if ((object)value == null)                    throw new ArgumentNullException(nameof(value));                 m_currentData = value;            }        }         /// <summary>        /// Gets the length of the <see cref="StateRecordSummary"/>.        /// </summary>        public int BinaryLength        {            get            {                return FixedLength;            }        }         #endregion         #region [ Methods ]         /// <summary>        /// Initializes <see cref="StateRecordSummary"/> from the specified <paramref name="buffer"/>.        /// </summary>        /// <param name="buffer">Binary image to be used for initializing <see cref="StateRecordSummary"/>.</param>        /// <param name="startIndex">0-based starting index of initialization data in the <paramref name="buffer"/>.</param>        /// <param name="length">Valid number of bytes in <paramref name="buffer"/> from <paramref name="startIndex"/>.</param>        /// <returns>Number of bytes used from the <paramref name="buffer"/> for initializing <see cref="StateRecordSummary"/>.</returns>        public int ParseBinaryImage(byte[] buffer, int startIndex, int length)        {            if (length >= FixedLength)            {                // Binary image has sufficient data.                HistorianID = LittleEndian.ToInt32(buffer, startIndex);                CurrentData = new StateRecordDataPoint(HistorianID, buffer, startIndex + 4, length - 4);                 return FixedLength;            }            else            {                // Binary image does not have sufficient data.                return 0;            }        }         /// <summary>        /// Generates binary image of the <see cref="StateRecordSummary"/> and copies it into the given buffer, for <see cref="BinaryLength"/> bytes.        /// </summary>        /// <param name="buffer">Buffer used to hold generated binary image of the source object.</param>        /// <param name="startIndex">0-based starting index in the <paramref name="buffer"/> to start writing.</param>        /// <returns>The number of bytes written to the <paramref name="buffer"/>.</returns>        /// <exception cref="ArgumentNullException"><paramref name="buffer"/> is null.</exception>        /// <exception cref="ArgumentOutOfRangeException">        /// <paramref name="startIndex"/> or <see cref="BinaryLength"/> is less than 0 -or-         /// <paramref name="startIndex"/> and <see cref="BinaryLength"/> will exceed <paramref name="buffer"/> length.        /// </exception>        public int GenerateBinaryImage(byte[] buffer, int startIndex)        {            int length = BinaryLength;             buffer.ValidateParameters(startIndex, length);             Buffer.BlockCopy(LittleEndian.GetBytes(m_historianID), 0, buffer, startIndex, 4);            m_currentData.GenerateBinaryImage(buffer, startIndex + 4);             return length;        }         #endregion    }}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t