//****************************************************************************************************** // SerializableMeasurement.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: // ---------------------------------------------------------------------------------------------------- // 12/16/2009 - Stephen C. Wills // Generated original version of source code. // 12/13/2012 - Starlynn Danyelle Gilliam // MOdified Header. // //****************************************************************************************************** using System; using System.Data; using System.Runtime.Serialization; using System.Xml.Serialization; using GSF; using GSF.TimeSeries; namespace DataQualityMonitoring { /// /// Represents a serializable that can be serialized using , or . /// [XmlType("Measurement"), DataContract(Name = "Measurement", Namespace = "")] public class SerializableMeasurement { #region [ Members ] // Events /// /// Occurs when an System.Exception is encountered when processing a request. /// /// is the exception encountered when processing a request. public event EventHandler> ProcessException; // Fields readonly IMeasurement m_sourceMeasurement; #endregion #region [ Constructors ] /// /// Initializes a new instance of the class. /// public SerializableMeasurement() { Key = string.Empty; SignalID = string.Empty; Timestamp = string.Empty; SignalType = string.Empty; Device = string.Empty; } /// /// Initializes a new instance of the class. /// /// from which is to be initialized. public SerializableMeasurement(IMeasurement measurement) { m_sourceMeasurement = measurement; Key = measurement.Key.ToString(); SignalID = measurement.ID.ToString(); Value = measurement.AdjustedValue; Timestamp = ((DateTime)measurement.Timestamp).ToString("yyyy-MM-dd HH:mm:ss.fff"); SignalType = string.Empty; Device = string.Empty; } #endregion #region [ Properties ] /// /// Gets or sets the . /// [XmlAttribute, DataMember(Order = 0)] public string Key { get; set; } /// /// Gets or sets the . /// [XmlAttribute, DataMember(Order = 1)] public string SignalID { get; set; } /// /// Gets or sets the . /// [XmlAttribute, DataMember(Order = 2)] public double Value { get; set; } /// /// Gets or sets the in string format. /// [XmlAttribute, DataMember(Order = 3)] public string Timestamp { get; set; } /// /// Gets or sets the signal type of the . /// [XmlAttribute, DataMember(Order = 4)] public string SignalType { get; set; } /// /// Gets or sets the device of the . /// [XmlAttribute, DataMember(Order = 5)] public string Device { get; set; } #endregion #region [ Methods ] /// /// Acquires and sets the device and signal type of the source measurement. /// /// which contains information about the device and the signal type of the source measurement. public void SetDeviceAndSignalType(DataSet dataSource) { try { DataRow row = dataSource.Tables["ActiveMeasurements"].Select(string.Format("ID = '{0}'", m_sourceMeasurement.Key.ToString()))[0]; TrySetDevice(row); TrySetSignalType(row); } catch (Exception ex) { OnProcessException(ex); } } /// /// Raises the event. /// /// to send to event. protected virtual void OnProcessException(Exception exception) { if (ProcessException != null) ProcessException(this, new EventArgs(exception)); } private bool TrySetDevice(DataRow row) { try { Device = row["Device"].ToString(); return true; } catch (Exception ex) { OnProcessException(ex); return false; } } private bool TrySetSignalType(DataRow row) { try { SignalType = row["SignalType"].ToString(); return true; } catch (Exception ex) { OnProcessException(ex); return false; } } #endregion } }