//
// (C) Copyright 2003-2007 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit;
using System.Data;
using System.Collections.ObjectModel;
namespace Revit.SDK.Samples.RDBLink.CS
{
///
/// Provides generic methods to export and import data.
///
public abstract class APIObjectList
{
#region Fields
///
/// Revit Document object
///
private static Document s_activeDocument;
///
/// Extra columns which do not exist in the original database.
///
private List m_extraColumns = new List();
///
/// DataTable which represents the real table in database.
///
private DataTable m_dataTable;
///
/// Table name.
///
private string m_tableName;
///
/// DataRow collection which will be deleted from data table at the end of importing.
///
private List m_garbageRows = new List();
///
/// DataRow collection which will be updated at the end of importing.
///
private Dictionary m_pendingRows = new Dictionary();
#endregion
#region Properties
///
/// Gets or sets the table name.
///
public string TableName
{
get { return m_tableName; }
set { m_tableName = value; }
}
///
/// Gets or sets DataTable.
///
public DataTable DataTable
{
get { return m_dataTable; }
set { m_dataTable = value; }
}
///
/// Gets active document
///
protected static Document ActiveDocument
{
get { return APIObjectList.s_activeDocument; }
}
///
/// Gets extra column list.
///
protected List ExtraColumns
{
get { return m_extraColumns; }
}
///
/// Gets garbage rows which will be deleted from data table at the end of importing.
///
protected List GarbageRows
{
get { return m_garbageRows; }
}
///
/// Gets pending rows which will be updated at the end of importing.
///
protected Dictionary PendingRows
{
get { return m_pendingRows; }
}
#endregion
#region Methods
///
/// Sets Revit Document object.
///
public static void SetRevitDocument(Document activeDocument)
{
s_activeDocument = activeDocument;
}
///
/// Exports data to dataTable
///
/// DataTable which revit data will be exported into
abstract public void Export(DataTable dataTable);
///
/// Imports data from dataTable
///
/// DataTable to import
abstract public void Import(DataTable dataTable);
///
/// Delete the rows in garbage row collection.
///
public void ClearGarbageRows()
{
foreach (DataRow row in m_garbageRows)
{
row.Delete();
}
}
///
/// Update the rows in pending row collection
///
public void UpdatePendingRows()
{
foreach (KeyValuePair pair in m_pendingRows)
{
pair.Value.ItemArray = pair.Key.ItemArray;
}
}
///
/// Add a new column which need to deal with.
///
/// column name that added
public void AppendColumn(string columnName)
{
if (!m_extraColumns.Contains(columnName))
{
m_extraColumns.Add(columnName);
}
}
///
/// Add some new columns which need to deal with.
///
/// column name list that added
public void AppendColumns(List columnNames)
{
foreach (string columnName in columnNames)
{
AppendColumn(columnName);
}
}
///
/// Clear extra columns
///
public void ClearExtraColumns()
{
m_extraColumns.Clear();
}
#endregion
};
}