context: /*****************************************************************************
  *
  * Copyright (c) [2009] Novell, Inc.
  * All Rights Reserved.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License as
  * published by the Free Software Foundation.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, contact Novell, Inc.
  *
  * To contact Novell about this file by physical or electronic mail,
  * you may find current contact information at www.novell.com
  *
  *-----------------------------------------------------------------------------
  *
  *                 $Author: Russ Young
  *                 $Modified by: <Modifier>
  *                 $Mod Date: <Date Modified>
  *                 $Revision: 0.1
  *-----------------------------------------------------------------------------
  * This module is used to:
  *        <Description of the functionality of the file >
  *
  *
  *******************************************************************************/
  
  
  using System;
  using System.Xml;
  using System.Text;
  using System.IO;
  using System.Collections;
  using System.Reflection;
  using System.Runtime.Remoting;
  using System.Runtime.Remoting.Activation;
  using System.Runtime.Remoting.Channels;
  using System.Security.Principal;
  using System.Threading;
  using System.Diagnostics;
  using Simias;
  //using Simias.Storage.Provider.Flaim;
  
  namespace Simias.Storage.Provider
  {	
  	/// <summary>
  	/// Represents a Collection Store Provider.
  	/// </summary>
  	public abstract class Provider
  	{
  		private static readonly ISimiasLog logger = SimiasLogManager.GetLogger(typeof(Provider));
  
  		#region Static Methods.
  
  		/// <summary>
  		/// Connect to the store using the provided configuration.
  		/// </summary>
  		/// <param name="conf"></param>
  		/// <param name="created"></param>
  		/// <returns></returns>
  		public static IProvider Connect(ProviderConfig conf, out bool created)
  		{
  			string assembly = conf.Assembly;
  			string providerType = conf.TypeName;
  			created = false;
  			IProvider provider = null;
  
  			// Load the assembly and find our provider.
  			Assembly pAssembly = AppDomain.CurrentDomain.Load(Path.GetFileNameWithoutExtension(assembly));
  			object[] args = {conf};
  			object[] activationAttrs = null;
  			
  			provider = (IProvider)pAssembly.CreateInstance(providerType, false, 0, null, args, null, activationAttrs);
  			if (provider != null)
  			{
  				try
  				{
  					provider.OpenStore();
  				}
  				catch
  				{
  					provider.CreateStore();
  					created = true;
  					logger.Info("Created new store {0}.", conf.Path);
  				}
  			}
  			
  			return (provider);
  		}
  
  		/// <summary>
  		/// Called to remove the Database path.
  		/// </summary>
  		public static void Delete(string path)
  		{
  			if (Directory.Exists(path))
  			{
  				Directory.Delete(path, true);
  				logger.Info("Deleted store {0}.", path);
  			}
  		}
  		
  		#endregion
  	}
  
  	/// <summary>
  	/// Store configuration class.
  	/// </summary>
  	public class ProviderConfig
  	{
  		private const string CFG_Section = "StoreProvider";
  		private const string CFG_Path = "Path";
  		private const string CFG_Assembly = "Assembly";
  		private const string CFG_TypeName = "Type";
  		private const string StoreName = "simias";
  		private string assembly = null;
  		private string typeName = null;
  		private Hashtable settingTable = new Hashtable();
  
  		private Simias.Configuration conf;
  		private string storePath;
  		
  
  		/// <summary>
  		/// Default Constructor
  		/// </summary>
  		public ProviderConfig(Configuration config, string storePath)
  		{
  			this.conf = config;
  			this.storePath = storePath;
  		}
  
  		/// <summary>
  		/// Gets and Sets the DB Path.
  		/// </summary>
  		public string Path
  		{
  			get
  			{
  				return storePath;
  			}
  		}
  
  
  		/// <summary>
  		/// Gets and Sets the Assembly that implements the provider instance used.
  		/// </summary>
  		public string Assembly
  		{
  			get
  			{
  				lock(this)
  				{
  					if (assembly == null)
  					{
  						assembly = conf.Get(CFG_Section, CFG_Assembly);
  						if ( assembly == null )
  						{
  							assembly = "SimiasLib.dll";
  						}
  					}
  				}
  				return assembly;
  			}
  		}
  
  		/// <summary>
  		/// Gets and Sets the Class Type of the implemented provider.
  		/// </summary>
  		public string TypeName
  		{
  			get
  			{
  				lock(this)
  				{
  					if (typeName == null)
  					{
  						typeName = conf.Get(CFG_Section, CFG_TypeName);
  						if ( typeName == null )
  						{
  							typeName = "Simias.Storage.Provider.Flaim.FlaimProvider";
  						}
  					}
  				}
  				return typeName;
  			}
  		}
  
  		/// <summary>
  		/// Get the specified configuration setting.
  		/// </summary>
  		/// <param name="key">The setting to retrieve.</param>
  		/// <param name="defaultValue">The default setting.</param>
  		/// <returns>The stored setting.</returns>
  		public string Get(string key, string defaultValue)
  		{
  			string setting;
  			lock (this)
  			{
  				if (!settingTable.Contains(key))
  				{
  
gt: 					setting = conf.Get(CFG_Section, key);