protected override void AfterLoadInternal(Stack <ObjectModel> objectModels) { base.AfterLoadInternal(objectModels); MarkupObjectModel mom = objectModels.Pop() as MarkupObjectModel; MochaTenantDefinitionObjectModel tenants = objectModels.Pop() as MochaTenantDefinitionObjectModel; MarkupTagElement tagTenants = mom.FindElementUsingSchema(XMLSchemas.Mocha, "tenants") as MarkupTagElement; if (tagTenants == null) { throw new InvalidDataFormatException(); } foreach (MarkupTagElement tagTenant in tagTenants.Elements.OfType <MarkupTagElement>()) { if (!(tagTenant.Name == "tenant" && tagTenant.XMLSchema == XMLSchemas.Mocha)) { continue; } Tenant tenant = new Tenant(); tenant.Name = tagTenant.Attributes["name"]?.Value; MarkupTagElement tagLibraryReferences = tagTenant.FindElementUsingSchema(XMLSchemas.Mocha, "libraryReferences") as MarkupTagElement; if (tagLibraryReferences != null) { foreach (MarkupTagElement tagLibraryReference in tagLibraryReferences.Elements.OfType <MarkupTagElement>()) { if (tagLibraryReference.Name == "libraryReference" && tagLibraryReference.XMLSchema == XMLSchemas.Mocha) { LibraryReference lref = new LibraryReference(); lref.Path = tagLibraryReference.Attributes["path"]?.Value; tenant.LibraryReferences.Add(lref); } } } tenants.Tenants.Add(tenant); } }
public static void InitializeTenants(this Oms oms, string path) { TenantHandle defaultTenant = oms.DefaultTenant; string[] files = { path }; if (System.IO.Directory.Exists(path)) { files = System.IO.Directory.GetFiles(path, "tenant.xml", System.IO.SearchOption.AllDirectories); } foreach (string file in files) { MochaTenantDefinitionObjectModel mcl1 = new MochaTenantDefinitionObjectModel(); Document.Load(mcl1, tenantdf, new FileAccessor(file, false, false, true)); foreach (Tenant tenant in mcl1.Tenants) { oms.DefaultTenant = oms.CreateTenant(tenant.Name); string[] libraryPathList = new string[tenant.LibraryReferences.Count]; for (int i = 0; i < tenant.LibraryReferences.Count; i++) { string libraryPath = tenant.LibraryReferences[i].Path.ReplaceVariables(new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("MochaRoot", System.IO.Path.Combine(new string[] { System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "System" })) }); libraryPathList[i] = libraryPath; } oms.Initialize(libraryPathList); Console.WriteLine("[mocha debug]: initialized tenant `{0}`", tenant.Name); } } oms.DefaultTenant = defaultTenant; oms.PendingTransactions.Clear(); }