public static Module AddExistingGlobalModule(GlobalModule globalModule, ModulesSection section) { if (globalModule == null) { throw new ArgumentNullException("globalModule"); } ModuleCollection collection = section.Modules; GlobalModulesCollection globalCollection = GetGlobalModulesCollection(); GlobalModule element = null; if (!IsGlobalModule(globalModule.Name, globalCollection, out element)) { throw new Exception(ModulesErrors.ModuleNotPresentInGlobalModulesError); } Module module = null; if (ExistsModule(globalModule.Name, collection, out module)) { throw new Exception(ModulesErrors.ModuleAlreadyPresentError); } try { module = collection.Add(globalModule.Name); } catch (FileLoadException e) { throw new LockedException(section.SectionPath, e); } catch (DirectoryNotFoundException e) { throw new ConfigScopeNotFoundException(e); } if (!String.IsNullOrEmpty(element.PreCondition)) { module.PreCondition = element.PreCondition; } return(module); }
public static void AddManagedModule(Module module, ModulesSection section) { if (module == null) { throw new ArgumentNullException("module"); } ModuleCollection serverCollection = section.Modules; GlobalModulesCollection globalCollection = GetGlobalModulesCollection(); GlobalModule element = null; if (IsGlobalModule(module.Name, globalCollection, out element)) { throw new ApiArgumentException("Module already exists", "name"); } Module newModule = null; if (ExistsModule(module.Name, serverCollection, out newModule)) { throw new ApiArgumentException("Module already exists", "name"); } try { newModule = serverCollection.Add(module.Name, module.Type); } catch (FileLoadException e) { throw new LockedException(section.SectionPath, e); } catch (DirectoryNotFoundException e) { throw new ConfigScopeNotFoundException(e); } if (!String.IsNullOrEmpty(module.PreCondition)) { newModule.PreCondition = module.PreCondition; } }