//******************************************************************************************************
// IaonTree.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/13/2011 - Magdiel Lorenzo
// Generated original version of source code.
// 12/20/2012 - Starlynn Danyelle Gilliam
// Modified Header.
//
//******************************************************************************************************
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using GSF.Data;
namespace GSF.TimeSeries.UI.DataModels
{
///
/// Represents a record of information as defined in the database.
///
public class IaonTree : DataModelBase
{
#region [ Members ]
private string m_adapterType;
private ObservableCollection m_adapterList;
#endregion
#region [ Properties ]
///
/// Gets the adapter type.
///
public string AdapterType
{
get
{
return m_adapterType;
}
}
///
/// Gets the list of adapters associated with this Iaon tree.
///
public ObservableCollection AdapterList
{
get
{
return m_adapterList;
}
}
#endregion
#region [ Static ]
///
/// 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 iaonTreeList;
DataTable rootNodesTable = new DataTable();
rootNodesTable.Columns.Add(new DataColumn("AdapterType", Type.GetType("System.String")));
DataRow row;
row = rootNodesTable.NewRow();
row["AdapterType"] = "Input Adapters";
rootNodesTable.Rows.Add(row);
row = rootNodesTable.NewRow();
row["AdapterType"] = "Action Adapters";
rootNodesTable.Rows.Add(row);
row = rootNodesTable.NewRow();
row["AdapterType"] = "Output Adapters";
rootNodesTable.Rows.Add(row);
DataSet resultSet = new DataSet();
resultSet.Tables.Add(rootNodesTable);
DataTable iaonTreeTable = database.Connection.RetrieveData(database.AdapterType, database.ParameterizedQueryString("SELECT * FROM IaonTreeView WHERE NodeID = {0}", "nodeID"), database.CurrentNodeID());
resultSet.EnforceConstraints = false;
resultSet.Tables.Add(iaonTreeTable.Copy());
resultSet.Tables[0].TableName = "RootNodesTable";
resultSet.Tables[1].TableName = "AdapterData";
iaonTreeList = new ObservableCollection(from item in resultSet.Tables["RootNodesTable"].AsEnumerable()
select new IaonTree
{
m_adapterType = item.Field("AdapterType"),
m_adapterList = new ObservableCollection(from obj in resultSet.Tables["AdapterData"].AsEnumerable()
where obj.Field("AdapterType") == item.Field("AdapterType")
select new Adapter
{
NodeID = database.Guid(obj, "NodeID"),
ID = obj.ConvertField("ID"),
AdapterName = obj.Field("AdapterName"),
AssemblyName = obj.Field("AssemblyName"),
TypeName = obj.Field("TypeName"),
ConnectionString = obj.Field("ConnectionString")
})
});
return iaonTreeList;
}
finally
{
if (createdConnection && database != null)
database.Dispose();
}
}
///
/// Gets a style list of information.
///
/// containing ID and Name of adapters defined in the database.
public static Dictionary GetLookupList()
{
return null;
}
///
/// Saves information to database.
///
/// String, for display use, indicating success.
public static string Save()
{
return "";
}
///
/// Deletes specified record from database.
///
/// String, for display use, indicating success.
public static string Delete()
{
return "";
}
#endregion
}
}