📄 metadataxmlprovider.cs
字号:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using Epi.Collections;
using Epi;
using Epi.Data;
using Epi.DataSets;
using Epi.Fields;
using Epi.Resources;
namespace Epi.Data.Services
{
/// <summary>
/// Xml implementation of Metadata provider
/// </summary>
public class MetadataXmlProvider : IMetadataProvider
{
#region MetadataProvider Database Members
[Obsolete("Use of DataTable in this context is no different than the use of a multidimensional System.Object array (not recommended).", false)]
public DataTable GetCodeTableColumnSchema(string tableName)
{
Util.Assert(tableName.StartsWith("meta") == false);
return db.GetTableColumnSchema(tableName);
}
public DataTable GetCodeTableData(string tableName)
{
Util.Assert(tableName.StartsWith("meta") == false);
return db.GetTableData(tableName);
}
public DataTable GetCodeTableData(string tableName, string columnNames)
{
Util.Assert(tableName.StartsWith("meta") == false);
return this.db.GetTableData(tableName, columnNames);
}
public DataTable GetCodeTableData(string tableName, string columnNames, string sortCriteria)
{
return this.db.GetTableData(tableName, columnNames, sortCriteria);
}
#endregion
#region Fields
private Project project;
private IDbDriverFactory dbFactory = null;
/// <summary>
/// The unerlying physical databsae
/// </summary>
protected IDbDriver db;
#endregion Fields
#region Events
public event ProgressReportBeginEventHandler ProgressReportBeginEvent;
public event ProgressReportUpdateEventHandler ProgressReportUpdateEvent;
public event SimpleEventHandler ProgressReportEndEvent;
#endregion Events
#region Constructors
/// <summary>
/// Constructor for the class.
/// </summary>
/// <param name="proj">Project the metadata belongs to</param>
public MetadataXmlProvider(Project proj)
{
#region Input validation
if (proj == null)
throw new System.ArgumentNullException("proj");
#endregion Input validation
project = proj;
//string connectionString = proj.MetadataConnectionString;
//if (Util.IsFilePath(connectionString) && !Path.IsPathRooted(connectionString))
//{
// connectionString = Path.Combine(proj.Location, connectionString);
//}
//db = DatabaseFactory.CreateDatabaseInstance(proj.MetadataDriver, connectionString);
//if (createXml)
//{
// this.CreateDatabase(new ConnectionStringInfo(connectionString).DbName);
// CreateMetadataTables();
//}
//else
//{
// // if you've come this far, the connection string should be valid
// db.TestConnection();
//}
}
#endregion Constructors
#region Public Properties
public Project Project
{
get
{
return project;
}
}
/// <summary>
/// MetaData DBFactory
/// </summary>
public IDbDriverFactory DBFactory
{
get { return dbFactory; }
}
#endregion Public Properties
#region Public Methods
/// <summary>
/// Gets list of code tables in the metadata database
/// </summary>
/// <returns>DataRow of table names</returns>
public DataSets.TableSchema.TablesDataTable GetCodeTableList()
{
try
{
DataSets.TableSchema.TablesDataTable tables = db.GetTableSchema();
DataRow[] rowsFiltered = tables.Select("TABLE_NAME NOT LIKE 'code%'");
foreach (DataRow rowFiltered in rowsFiltered)
{
tables.Rows.Remove(rowFiltered);
}
return tables;
}
catch (Exception ex)
{
throw new System.ApplicationException("Could not retrieve code tables from database", ex);
}
}
#region Select Statements
/// <summary>
/// Gets all views belonging to a project
/// </summary>
/// <returns>Datatable containing view info</returns>
public virtual DataTable GetViewsAsDataTable()
{
try
{
Query query = db.CreateQuery(
@"SELECT [ViewId], [Name], [CheckCodeBefore], [CheckCodeAfter], [RecordCheckCodeBefore],
[RecordCheckCodeAfter], [CheckCodeVariableDefinitions], [IsRelatedView]
FROM metaViews"
);
//query.Parameters.Add(new DbParameter("@ProjectId", DbType.Guid, Project.Id));
return db.Select(query);
}
catch (Exception ex)
{
throw new GeneralException("Could not retrieve view data table", ex);
}
}
/// <summary>
/// Gets all views belonging to a project
/// </summary>
/// <returns>A collection of views</returns>
public ViewCollection GetViews()
{
try
{
Collections.ViewCollection views = new Collections.ViewCollection();
DataTable table = GetViewsAsDataTable();
foreach (DataRow row in table.Rows)
{
views.Add(new View(row, this.Project));
}
return views;
}
catch (Exception ex)
{
throw new GeneralException("Could not retrieve view collection", ex);
}
}
/*
/// <summary>
/// Gets all pages belonging to the project
/// </summary>
/// <returns>Datatable containing page info</returns>
public DataTable GetPagesForProject()
{
try
{
DbQuery query = db.CreateQuery("SELECT P.[PageId], V.[ViewId], P.[Name] AS PageName, V.[Name] AS ViewName, P.[Position] " +
"FROM metaViews V INNER JOIN metaPages P ON V.[ViewId] = P.[ViewId] " +
"ORDER BY V.[Name], P.[Position]");
return db.Select(query);
}
catch (Exception ex)
{
throw new GeneralException("Could not retrieve page", ex);
}
}
*/
/// <summary>
/// Gets all pages belonging to a view
/// </summary>
/// <param name="viewId">Id of the view</param>
/// <returns>Datatable containing page info</returns>
public DataTable GetPagesForView(int viewId)
{
try
{
#region Input Validation
if (viewId < 1)
{
throw new ArgumentOutOfRangeException("ViewId");
}
#endregion
Query query = db.CreateQuery("SELECT [PageId], [ViewId], [Name], [Position], [CheckCodeBefore], [CheckCodeAfter] " +
"FROM metaPages " +
"WHERE [ViewId] = @ViewId " +
"ORDER BY [Position] ASC");
query.Parameters.Add(new QueryParameter("@ViewId", DbType.Int32, viewId));
return db.Select(query);
}
catch (Exception ex)
{
throw new GeneralException("Could not retrieve page", ex);
}
}
/// <summary>
/// Fetches the collection of pages of a view from metadata database.
/// </summary>
/// <param name="view"></param>
/// <returns></returns>
public virtual List<Page> GetViewPages(View view)
{
try
{
List<Page> pages = new List<Page>();
DataTable table = GetPagesForView(view.Id);
foreach (DataRow row in table.Rows)
{
pages.Add(new Page(row, view));
}
return (pages);
}
catch (Exception ex)
{
throw new GeneralException("Could not retrieve page collection", ex);
}
}
/// <summary>
/// Gets a view's check code for the "Before" event
/// </summary>
/// <param name="viewID">Id of the view</param>
/// <returns>Datatable containing check code info</returns>
[Obsolete("Use of DataTable in this context is no different than the use of a multidimensional System.Object array (not recommended).", false)]
public DataTable GetViewCheckCode_Before(int viewID)
{
try
{
#region Input Validation
if (viewID < 1)
{
throw new ArgumentOutOfRangeException("ViewId");
}
#endregion
Query query = db.CreateQuery("SELECT V.[ViewID], V.[Name], V.[CheckCodeBefore] " +
"FROM metaViews V " +
"WHERE V.[ViewId] = @ViewID");
query.Parameters.Add(new QueryParameter("@ViewID", DbType.Int32, viewID));
return db.Select(query);
}
catch (Exception ex)
{
throw new GeneralException("Could not retrieve view's check code", ex);
}
}
/// <summary>
/// Gets a view's check code for the "After" event
/// </summary>
/// <param name="viewID">Id of the view</param>
/// <returns>Datatable containing check code info</returns>
[Obsolete("Use of DataTable in this context is no different than the use of a multidimensional System.Object array (not recommended).", false)]
public DataTable GetViewCheckCode_After(int viewID)
{
try
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -