1
/****************************************************************************
3
| Copyright (c) 2007 Novell, Inc.
6
| This program is free software; you can redistribute it and/or
7
| modify it under the terms of version 2 of the GNU General Public License as
8
| published by the Free Software Foundation.
10
| This program is distributed in the hope that it will be useful,
11
| but WITHOUT ANY WARRANTY; without even the implied warranty of
12
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
| GNU General Public License for more details.
15
| You should have received a copy of the GNU General Public License
16
| along with this program; if not, contact Novell, Inc.
18
| To contact Novell about this file by physical or electronic mail,
19
| you may find current contact information at www.novell.com
22
|***************************************************************************/
29
using System.Collections;
30
using System.Reflection;
31
using System.Runtime.Remoting;
32
using System.Runtime.Remoting.Activation;
33
using System.Runtime.Remoting.Channels;
34
using System.Security.Principal;
35
using System.Threading;
36
using System.Diagnostics;
38
//using Simias.Storage.Provider.Flaim;
40
namespace Simias.Storage.Provider
43
/// Represents a Collection Store Provider.
45
public abstract class Provider
47
private static readonly ISimiasLog logger = SimiasLogManager.GetLogger(typeof(Provider));
49
#region Static Methods.
52
/// Connect to the store using the provided configuration.
54
/// <param name="conf"></param>
55
/// <param name="created"></param>
56
/// <returns></returns>
57
public static IProvider Connect(ProviderConfig conf, out bool created)
59
string assembly = conf.Assembly;
60
string providerType = conf.TypeName;
62
IProvider provider = null;
64
// Load the assembly and find our provider.
65
Assembly pAssembly = AppDomain.CurrentDomain.Load(Path.GetFileNameWithoutExtension(assembly));
66
object[] args = {conf};
67
object[] activationAttrs = null;
69
provider = (IProvider)pAssembly.CreateInstance(providerType, false, 0, null, args, null, activationAttrs);
78
provider.CreateStore();
80
logger.Info("Created new store {0}.", conf.Path);
88
/// Called to remove the Database path.
90
public static void Delete(string path)
92
if (Directory.Exists(path))
94
Directory.Delete(path, true);
95
logger.Info("Deleted store {0}.", path);
103
/// Store configuration class.
105
public class ProviderConfig
107
private const string CFG_Section = "StoreProvider";
108
private const string CFG_Path = "Path";
109
private const string CFG_Assembly = "Assembly";
110
private const string CFG_TypeName = "Type";
111
private const string StoreName = "simias";
112
private string assembly = null;
113
private string typeName = null;
114
private Hashtable settingTable = new Hashtable();
116
private Simias.Configuration conf;
117
private string storePath;
121
/// Default Constructor
123
public ProviderConfig(Configuration config, string storePath)
126
this.storePath = storePath;
130
/// Gets and Sets the DB Path.
142
/// Gets and Sets the Assembly that implements the provider instance used.
144
public string Assembly
150
if (assembly == null)
152
assembly = conf.Get(CFG_Section, CFG_Assembly);
153
if ( assembly == null )
155
assembly = "SimiasLib.dll";
164
/// Gets and Sets the Class Type of the implemented provider.
166
public string TypeName
172
if (typeName == null)
174
typeName = conf.Get(CFG_Section, CFG_TypeName);
175
if ( typeName == null )
177
typeName = "Simias.Storage.Provider.Flaim.FlaimProvider";
186
/// Get the specified configuration setting.
188
/// <param name="key">The setting to retrieve.</param>
189
/// <param name="defaultValue">The default setting.</param>
190
/// <returns>The stored setting.</returns>
191
public string Get(string key, string defaultValue)
196
if (!settingTable.Contains(key))
198
setting = conf.Get(CFG_Section, key);
199
if ( setting == null )
201
setting = defaultValue;
204
settingTable[key] = setting;
207
return (string)settingTable[key];
214
public class CommitException : SimiasException
219
public XmlDocument CreateDoc;
223
public XmlDocument DeleteDoc;
228
/// <param name="createDoc"></param>
229
/// <param name="deleteDoc"></param>
230
/// <param name="ex"></param>
231
public CommitException(XmlDocument createDoc, XmlDocument deleteDoc, Exception ex) :
232
base("Failed to commite Records", ex)
234
CreateDoc = createDoc;
235
DeleteDoc = deleteDoc;
241
public override string Message
245
StringBuilder sb = new StringBuilder();
247
if (CreateDoc != null)
249
sb.Append("Failed to create:" + Environment.NewLine);
250
XmlElement root = CreateDoc.DocumentElement;
251
XmlNodeList recordList = root.SelectNodes(XmlTags.ObjectTag);
252
foreach (XmlElement recordEl in recordList)
254
sb.Append(String.Format("{0}, {1}{2}", recordEl.GetAttribute(XmlTags.IdAttr), recordEl.GetAttribute(XmlTags.NameAttr), Environment.NewLine));
258
if (DeleteDoc != null)
260
sb.Append("Failed to delete:" + Environment.NewLine);
261
XmlElement root = DeleteDoc.DocumentElement;
262
XmlNodeList recordList = root.SelectNodes(XmlTags.ObjectTag);
263
foreach (XmlElement recordEl in recordList)
265
sb.Append(String.Format("{0}, {1}{2}", recordEl.GetAttribute(XmlTags.IdAttr), recordEl.GetAttribute(XmlTags.NameAttr), Environment.NewLine));
268
return (sb.ToString());