public static void DeleteModule(string moduleName, Site site, string path, string configPath = null) { if (moduleName == null) { throw new ArgumentNullException("moduleName"); } ModulesSection section = GetModulesSection(site, path, configPath); ModuleCollection collection = section.Modules; Module module = null; if (!ExistsModule(moduleName, collection, out module)) { return; } if (ModuleIsLocked(module) && site != null) { // Can't delete the module if it is locked // Unless the scope is at server level throw new InvalidOperationException("Lock violation"); } try { collection.Remove(moduleName); } catch (FileLoadException e) { throw new LockedException(section.SectionPath, e); } catch (DirectoryNotFoundException e) { throw new ConfigScopeNotFoundException(e); } }
public static void AddGlobalModule(GlobalModule module) { if (module == null) { throw new ArgumentNullException("nativeModule"); } // NOTE: Can add a new native module only when configuring the server scope // and NOT in the location mode // Native modules can only be added at the server level ModuleCollection serverCollection = GetModulesCollection(null, null); GlobalModulesCollection globalCollection = GetGlobalModulesCollection(); GlobalModule element = null; if (IsGlobalModule(module.Name, globalCollection, out element)) { throw new AlreadyExistsException("module.name"); } Module action = null; if (ExistsModule(module.Name, serverCollection, out action)) { throw new AlreadyExistsException("module.name"); } // Add to global modules element = globalCollection.Add(module); // NOTE: When we add a new native module we do not add it to the server modules // list. }
public static void MoveModuleUp(string moduleName, Site site, string path) { if (String.IsNullOrEmpty(moduleName)) { throw new ArgumentNullException("moduleName"); } EnableOrdering(site, path); ModuleCollection serverCollection = GetModulesCollection(site, path); Module action = null; if (!ExistsModule(moduleName, serverCollection, out action)) { throw new Exception(ModulesErrors.ModuleNotPresentError); } int index = serverCollection.IndexOf(action); if (index != 0) { serverCollection.Remove(action); serverCollection.AddCopyAt(index - 1, action); } }
private static bool ExistsModule(string moduleName, ModuleCollection collection, out Module action) { action = collection[moduleName]; if (action != null) { return(true); } return(false); }
private static ModuleCollection GetModulesCollection(Site site, string path, string configPath = null) { ModulesSection section = GetModulesSection(site, path, configPath); ModuleCollection collection = section.Modules; if (collection == null) { throw new Exception(ModulesErrors.ConfigurationError); } return(collection); }
public static GlobalModule UpdateGlobalModule(GlobalModule globalModule, dynamic model) { if (model == null) { throw new ApiArgumentException("model"); } if (globalModule == null) { throw new ArgumentNullException("globalModule"); } Configuration config = ManagementUnit.GetConfiguration(null, null); GlobalModulesCollection globalCollection = GetGlobalModulesCollection(); ModuleCollection serverCollection = GetModulesCollection(null, null); Module action = null; string image = DynamicHelper.Value(model.image); if (image != null) { if (!File.Exists(System.Environment.ExpandEnvironmentVariables(image))) { throw new NotFoundException("image"); } globalModule.Image = image; } string preCondition = globalModule.PreCondition; BitnessUtility.AppendBitnessPreCondition(ref preCondition, image); globalModule.PreCondition = preCondition; // If the global module is present in the server modules list then we // update the precondition of that entry as well. if (ExistsModule(globalModule.Name, serverCollection, out action)) { if (ConfigurationUtility.ShouldPersist(action.PreCondition, globalModule.PreCondition)) { action.PreCondition = globalModule.PreCondition; } } return(globalModule); }
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; } }