Example #1
0
        public void UpdateModulePriority(Module module, ModulePriorityCategory category, int priority)
        {
            if (module.PriorityCategory == category && module.Priority == priority)
            {
                return;
            }

            List <Module> modules = _pluginService.GetPluginsOfType <Module>().Where(m => m.PriorityCategory == category).OrderBy(m => m.Priority).ToList();

            if (modules.Contains(module))
            {
                modules.Remove(module);
            }

            priority = Math.Min(modules.Count, Math.Max(0, priority));
            modules.Insert(priority, module);

            module.PriorityCategory = category;
            for (int index = 0; index < modules.Count; index++)
            {
                Module categoryModule = modules[index];
                categoryModule.Priority = index;

                // Don't save modules whose priority hasn't been initialized yet
                if (categoryModule == module || categoryModule.Entity != null)
                {
                    categoryModule.ApplyToEntity();
                    _moduleRepository.Save(categoryModule.Entity);
                }
            }
        }
Example #2
0
        private void InitialiseOrApplyPriority(Module module)
        {
            ModulePriorityCategory category = module.DefaultPriorityCategory;
            int priority = 1;

            module.Entity = _moduleRepository.GetByPluginGuid(module.PluginInfo.Guid);
            if (module.Entity != null)
            {
                category = (ModulePriorityCategory)module.Entity.PriorityCategory;
                priority = module.Entity.Priority;
            }

            UpdateModulePriority(module, category, priority);
        }