//******************************************************************************************************
// MetadataRecord.cs - Gbtc
//
// Copyright © 2015, 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:
// ----------------------------------------------------------------------------------------------------
// 10/28/2015 - Ritchie Carroll
// Generated original version of source code.
//
//******************************************************************************************************
using System;
using System.Text;
using GSF.IO.Checksums;
namespace KafkaAdapters
{
///
/// Represents a record of Kafka time-series metadata.
///
public class MetadataRecord
{
#region [ Constructors ]
///
/// Creates a new .
///
public MetadataRecord()
{
UniqueID = Guid.Empty.ToString();
}
#endregion
#region [ Members ]
// Constants
///
/// Date-time format used by .
///
public const string DateTimeFormat = "yyyy-MM-dd HH:mm:ss.fff";
// Fields
///
/// Measurement ID, i.e., locally unique metadata index.
///
public uint ID;
///
/// Cross-system unique measurement identification.
///
public string UniqueID;
///
/// Assigned point tag of measurement, if any.
///
public string PointTag;
///
/// Acronym of primary measurement source, e.g., a historian.
///
public string Source;
///
/// Acronym of device that creates measurements.
///
public string Device;
///
/// Longitude of device that creates the measurements.
///
public float Longitude;
///
/// Latitude of device that creates the measurements.
///
public float Latitude;
///
/// Acronym of device protocol used for transporting measured values.
///
public string Protocol;
///
/// Acronym of type of measured value, e.g., FREQ for frequency.
///
public string SignalType;
///
/// Engineering units associated with signal type, if any.
///
public string EngineeringUnits;
///
/// When measurement is part of a phasor, value will be V for voltage or I for current; otherwise null.
///
public string PhasorType;
///
/// When measurement is part of a phasor, represents the phase of the measured value; otherwise null.
///
public string Phase;
///
/// Description of the measurement.
///
public string Description;
///
/// Last update date and time of the metadata record in UTC. Format = yyyy-MM-dd HH:mm:ss.fff
///
public string LastUpdate;
#endregion
#region [ Methods ]
///
/// Parses string as a .
///
/// as a .
public Guid ParseSignalID()
{
Guid id;
Guid.TryParse(UniqueID, out id);
return id;
}
///
/// Calculates a CRC-32 based check-sum on this instance.
///
/// CRC-32 based check-sum on this instance.
public long CalculateChecksum()
{
Crc32 checksum = new Crc32();
checksum.Update(BitConverter.GetBytes(ID));
checksum.Update(Encoding.Default.GetBytes(UniqueID ?? ""));
checksum.Update(Encoding.Default.GetBytes(PointTag ?? ""));
checksum.Update(Encoding.Default.GetBytes(Source ?? ""));
checksum.Update(Encoding.Default.GetBytes(Device ?? ""));
checksum.Update(BitConverter.GetBytes(Longitude));
checksum.Update(BitConverter.GetBytes(Latitude));
checksum.Update(Encoding.Default.GetBytes(Protocol ?? ""));
checksum.Update(Encoding.Default.GetBytes(SignalType ?? ""));
checksum.Update(Encoding.Default.GetBytes(EngineeringUnits ?? ""));
checksum.Update(Encoding.Default.GetBytes(PhasorType ?? ""));
checksum.Update(Encoding.Default.GetBytes(Phase ?? ""));
checksum.Update(Encoding.Default.GetBytes(Description ?? ""));
checksum.Update(Encoding.Default.GetBytes(LastUpdate ?? ""));
return checksum.Value;
}
#endregion
}
}