예제 #1
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);
        }
예제 #2
0
        public static GlobalModule CreateGlobalModule(dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            string name  = DynamicHelper.Value(model.name);
            string image = DynamicHelper.Value(model.image);

            if (string.IsNullOrEmpty(name))
            {
                throw new ApiArgumentException("name");
            }
            if (string.IsNullOrEmpty(image))
            {
                throw new ApiArgumentException("image");
            }
            if (!File.Exists(System.Environment.ExpandEnvironmentVariables(image)))
            {
                throw new NotFoundException("image");
            }

            var globalCollection = GetGlobalModulesCollection();

            GlobalModule globalModule = globalCollection.CreateElement();

            globalModule.Name         = name;
            globalModule.Image        = image;
            globalModule.PreCondition = DynamicHelper.Value(model.precondition) ?? globalModule.PreCondition;

            // This sets the correct bitness precondition
            string preCondition = globalModule.PreCondition;

            BitnessUtility.AppendBitnessPreCondition(ref preCondition, globalModule.Image);
            globalModule.PreCondition = preCondition;

            return(globalModule);
        }