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.
        }
        private static bool IsGlobalModule(string moduleName, GlobalModulesCollection collection,
                                           out GlobalModule element)
        {
            element = null;
            foreach (GlobalModule e in collection)
            {
                if (String.Equals(e.Name, moduleName, StringComparison.Ordinal))
                {
                    element = e;
                    return(true);
                }
            }

            return(false);
        }
        private static GlobalModulesCollection GetGlobalModulesCollection()
        {
            Configuration config = ManagementUnit.GetConfiguration(null, null);

            GlobalModulesSection section =
                (GlobalModulesSection)GetSection(config, ModulesGlobals.GlobalsModulesSectionName, typeof(GlobalModulesSection));

            GlobalModulesCollection collection = section.GlobalModules;

            if (collection == null)
            {
                throw new Exception(ModulesErrors.ConfigurationError);
            }

            return(collection);
        }
Пример #4
0
        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;
            }
        }
        public static void DeleteGlobalModule(GlobalModule module)
        {
            if (String.IsNullOrEmpty(module.Name))
            {
                throw new ArgumentNullException("nativeModule.Name");
            }

            // Native modules can only be configured at the server level
            GlobalModulesCollection globalCollection = GetGlobalModulesCollection();

            GlobalModule element = null;

            if (!IsGlobalModule(module.Name, globalCollection, out element))
            {
                return;
            }

            // If the global module is in the enabled modules collection, remove it from there first
            DeleteModule(module.Name, null, null);

            // Remove the global modules from global modules collection
            globalCollection.Remove(element);
        }