//******************************************************************************************************
// Statistic.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:
// ----------------------------------------------------------------------------------------------------
// 07/20/2011 - Mehulbhai P Thakkar
// Generated original version of source code.
//
//******************************************************************************************************
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data;
using GSF.Data;
using GSF.TimeSeries.UI;
namespace GSF.PhasorProtocols.UI.DataModels
{
///
/// Represents a record of information as defined in the database.
///
public class Statistic : DataModelBase
{
#region [ Members ]
// Fields
private int m_id;
private string m_source;
private int m_signalIndex;
private string m_name;
private string m_description;
private string m_assemblyName;
private string m_typeName;
private string m_methodName;
private string m_arguments;
private bool m_enabled;
private string m_dataType;
private string m_displayFormat;
private bool m_isConnectedState;
private int m_loadOrder;
//private string m_value;
//private string m_timeTag;
//private string m_quality;
#endregion
#region [ Properties ]
///
/// Gets or sets the current 's ID.
///
// Field is populated by database via auto-increment and has no screen interaction, so no validation attributes are applied
public int ID
{
get
{
return m_id;
}
set
{
m_id = value;
}
}
///
/// Gets or sets the current 's Source.
///
[Required(ErrorMessage = "Statistic Source is a required field, please provide a value.")]
[StringLength(20, ErrorMessage = "Statistic Source cannot exceed 20 characters.")]
public string Source
{
get
{
return m_source;
}
set
{
m_source = value;
OnPropertyChanged("Source");
}
}
///
/// Gets or sets the current 's SignalIndex.
///
[Required(ErrorMessage = "Statistic Signal Index is a required field, please provice a value.")]
public int SignalIndex
{
get
{
return m_signalIndex;
}
set
{
m_signalIndex = value;
OnPropertyChanged("SignalIndex");
}
}
///
/// Gets or sets the current 's Name.
///
[Required(ErrorMessage = "Statistic Name is a required field, please provide a value.")]
[StringLength(200, ErrorMessage = "Statistic Name cannot exceed 200 characters.")]
public string Name
{
get
{
return m_name;
}
set
{
m_name = value;
OnPropertyChanged("Name");
}
}
///
/// Gets or sets the current 's Description.
///
public string Description
{
get
{
return m_description;
}
set
{
m_description = value;
OnPropertyChanged("Description");
}
}
///
/// Gets or sets the current 's AssemblyName.
///
[Required(ErrorMessage = "Statistic Assembly Name is a required field, please provide a value.")]
public string AssemblyName
{
get
{
return m_assemblyName;
}
set
{
m_assemblyName = value;
OnPropertyChanged("AssemblyName");
}
}
///
/// Gets or sets the current 's TypeName.
///
[Required(ErrorMessage = "Statistic Type Name is a required field, please provide a value.")]
public string TypeName
{
get
{
return m_typeName;
}
set
{
m_typeName = value;
OnPropertyChanged("TypeName");
}
}
///
/// Gets or sets the current 's MethodName.
///
[Required(ErrorMessage = "Statistic Method Name is a required field, please provide a value.")]
public string MethodName
{
get
{
return m_methodName;
}
set
{
m_methodName = value;
OnPropertyChanged("MethodName");
}
}
///
/// Gets or sets the current 's Arguments.
///
public string Arguments
{
get
{
return m_arguments;
}
set
{
m_arguments = value;
OnPropertyChanged("Arguments");
}
}
///
/// Gets or sets the current Enabled.
///
[DefaultValue(true)]
public bool Enabled
{
get
{
return m_enabled;
}
set
{
m_enabled = value;
OnPropertyChanged("Enabled");
}
}
///
/// Gets or sets the current 's DataType.
///
[StringLength(200, ErrorMessage = "Statistic DataType cannot exceed 200 characters.")]
public string DataType
{
get
{
return m_dataType;
}
set
{
m_dataType = value;
OnPropertyChanged("DataType");
}
}
///
/// Gets or sets the current 's DisplayFormat.
///
[StringLength(200, ErrorMessage = "Statistic DisplayFormat cannot exceed 200 characters.")]
public string DisplayFormat
{
get
{
return m_displayFormat;
}
set
{
m_displayFormat = value;
OnPropertyChanged("DisplayFormat");
}
}
///
/// Gets or sets the current 's IsConnectedState.
///
public bool IsConnectedState
{
get
{
return m_isConnectedState;
}
set
{
m_isConnectedState = value;
OnPropertyChanged("IsConnectedState");
}
}
///
/// Gets or sets the current 's LoadOrder.
///
[DefaultValue(0)]
public int LoadOrder
{
get
{
return m_loadOrder;
}
set
{
m_loadOrder = value;
OnPropertyChanged("LoadOrder");
}
}
#endregion
#region [ Static ]
// Static Methods
///
/// Loads information as an style list.
///
/// to connection to database.
/// Collection of .
public static ObservableCollection Load(AdoDataConnection database)
{
bool createdConnection = false;
try
{
createdConnection = CreateConnection(ref database);
ObservableCollection statisticList = new();
DataTable statisticTable = database.Connection.RetrieveData(database.AdapterType, "SELECT Source, SignalIndex, Name, Description, DataType, DisplayFormat, " +
"IsConnectedState, LoadOrder FROM Statistic ORDER BY Source, SignalIndex");
foreach (DataRow row in statisticTable.Rows)
{
statisticList.Add(new Statistic()
{
Source = row.Field("Source"),
SignalIndex = row.ConvertField("SignalIndex"),
Name = row.Field("Name"),
Description = row.Field("Description"),
DataType = row.Field("DataType"),
DisplayFormat = row.Field("DisplayFormat"),
IsConnectedState = Convert.ToBoolean(row.Field