18 using System.Collections.Generic;
42 metadata =
new Dictionary<string, object>();
45 metadata[
"[env]:os.platform"] = Environment.OSVersion.Platform;
46 metadata[
"[env]:os.version"] = Environment.OSVersion.VersionString;
47 metadata[
"[env]:os.sp"] = Environment.OSVersion.ServicePack;
48 metadata[
"[env]:runtime.version"] = Environment.Version.ToString();
49 metadata[
"[env]:machineName"] = Environment.MachineName;
50 metadata[
"[env]:hostName"] = Dns.GetHostName();
53 metadata[
"[env]processors"] = Environment.ProcessorCount;
56 metadata[String.Format(
"[config]:{0}", config.Key)] = config.Value;
59 foreach (var module
in Modules) {
60 metadata[String.Format(
"[module]:{0}", module.ModuleName)] = module.Version;
66 if (databases == null)
70 if (!databases.TryGetValue(databaseName, out database))
77 public IEnumerable<ModuleInfo> Modules {
get;
private set; }
84 get {
return metadata; }
89 GC.SuppressFinalize(
this);
95 if (databases != null) {
96 foreach (var database
in databases.Values) {
120 get {
return Context.Configuration; }
125 if (databases == null)
126 return new string[0];
128 return databases.Keys;
134 if (configuration == null)
135 throw new ArgumentNullException(
"configuration");
137 var databaseName = configuration.GetString(
"database.name");
138 if (String.IsNullOrEmpty(databaseName))
139 throw new ArgumentException(
"The configuration must specify a database name.");
141 if (DatabaseExists(databaseName))
142 throw new InvalidOperationException(String.Format(
"Database '{0}' already exists in the system.", databaseName));
144 var dbContext =
Context.CreateDatabaseContext(configuration);
145 var database =
new Database(
this, dbContext);
148 throw new InvalidOperationException(String.Format(
"The database '{0}' was already created.", databaseName));
150 database.Create(adminUser, adminPassword);
153 if (databases == null)
154 databases =
new Dictionary<string, IDatabase>();
156 databases[databaseName] = database;
164 if (configuration == null)
165 throw new ArgumentNullException(
"configuration");
167 var databaseName = configuration.GetString(
"database.name");
168 if (String.IsNullOrEmpty(databaseName))
169 throw new ArgumentException(
"The configuration must specify a database name.");
172 if (databases == null ||
173 !databases.TryGetValue(databaseName, out database))
174 throw new InvalidOperationException(String.Format(
"Database '{0}' does not exist in the system.", databaseName));
176 if (!database.IsOpen)
185 if (String.IsNullOrEmpty(databaseName))
186 throw new ArgumentNullException(
"databaseName");
188 if (databases == null)
191 return databases.ContainsKey(databaseName);
197 if (String.IsNullOrEmpty(databaseName))
198 throw new ArgumentNullException(
"databaseName");
200 if (databases == null)
204 if (!databases.TryGetValue(databaseName, out database))
207 if (!database.Exists)
212 return databases.Remove(databaseName);
219 databases.Remove(database.
Name);
IDatabase OpenDatabase(IConfiguration configuration)
The execution context of a database system, that is defining the configurations and the components us...
IEnumerable< string > GetDatabases()
virtual void Dispose(bool disposing)
bool DeleteDatabase(string databaseName)
DatabaseSystem(ISystemContext context, IEnumerable< ModuleInfo > modules)
The default implementation of a database in a system.
The representation of a single database in the system.
IEventSource ParentSource
Gets an optional parent source.
IEnumerable< KeyValuePair< string, object > > Metadata
Gets the list of metadata associated to the source.
IDictionary< string, object > metadata
void RemoveDatabase(Database database)
Defines the contract for the configuration node of a component within the system or of the system its...
IDictionary< string, IDatabase > databases
void Open()
Opens the database making it ready to be accessed.
void Dispose(bool disposing)
IDatabase CreateDatabase(IConfiguration configuration, string adminUser, string adminPassword)
string Name
Gets the database name, as configured in the parent context.
IDatabase GetDatabase(string databaseName)
Represents the origin of system events, providing a mechanism to fill the metadata before dispatching...
bool DatabaseExists(string databaseName)