using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Threading;
using Orciid.Core;

namespace webtests
{
	public class Utilities
	{
		string filepath;
		string servertype;
		string connection;

		public string Connection
		{
			get
			{
				return connection;
			}
		}

		public Utilities(string filepath)
		{
			this.filepath = filepath;

			Configuration.Instance.Initialize(filepath);

			servertype = Configuration.Instance.GetString("database.servertype");
			connection = Configuration.Instance.GetString("database.connection");
			
//			if (servertype != "MSSQL")
//				throw new Exception("Only Microsoft SQL Server supported at this time");
		}

/*		public void DumpDataToXML()
		{
			DataSet ds = new DataSet();
			ds.ReadXmlSchema(Path.Combine(filepath, "OrciidDataset.xsd"));

			DataSet data = new DataSet();
			data.DataSetName = "OrciidData";

			using (SqlConnection conn = new SqlConnection(connection))
			{
				conn.Open();
				foreach (DataTable table in ds.Tables)
				{
					SqlCommand c = new SqlCommand("SELECT * FROM " + table.TableName, conn);
					SqlDataAdapter a = new SqlDataAdapter(c);
					a.Fill(data, table.TableName);
				}
			}

			data.WriteXml(Path.Combine(filepath, "OrciidData.xml"), XmlWriteMode.IgnoreSchema);
		}
*/
/*		public void ResetDatabase()
		{
			DataSet ds = new DataSet();
			ds.ReadXmlSchema(Path.Combine(filepath, "OrciidDataset.xsd"));

			// drop all tables
			using (SqlConnection conn = new SqlConnection(connection))
			{
				conn.Open();
				foreach (DataTable table in ds.Tables)
				{
					try
					{
						SqlCommand c = new SqlCommand("DROP TABLE " + table.TableName, conn);
						c.ExecuteNonQuery();
					}
					catch (SqlException)
					{
					}
				}
			}

			// reset tested connection cache to force database check and recreation of tables
			DBConnection.ResetTestedConnections();
			using (DBConnection conn = DBConnector.GetConnection(true))
			{
			}

		}
*/	
	}
}
