Exemplo n.º 1
0
        async Task <IEnumerable <ShellModule> > AddAndGetFeaturesAsync(IEnumerable <ShellModule> modulesToAdd)
        {
            // Ensure we have a distinct list of features to save
            var distinctDictionary = new ConcurrentDictionary <string, ShellModule>();

            foreach (var module in modulesToAdd)
            {
                if (!distinctDictionary.ContainsKey(module.ModuleId))
                {
                    distinctDictionary.TryAdd(module.ModuleId, module);
                }
            }

            // Distinct list of features to add
            var featuresToAdd = distinctDictionary.Values.ToList();

            // Get all currently registered features
            var currentFeatures = await _shellFeatureStore.SelectFeatures();

            // Convert to list
            var currentFeaturesList = currentFeatures.ToList();

            // Delete any feature not in our current list of features to add
            foreach (var feature in currentFeaturesList)
            {
                if (featuresToAdd.FirstOrDefault(f => f.ModuleId == feature.ModuleId) == null)
                {
                    await _shellFeatureStore.DeleteAsync(feature);
                }
            }

            // Add any new features into our features table
            var output = new List <ShellModule>();

            foreach (var feature in featuresToAdd)
            {
                // add or update feature
                var existingFeature = currentFeaturesList.FirstOrDefault(f => f.ModuleId == feature.ModuleId)
                                      ?? new ShellFeature()
                {
                    ModuleId        = feature.ModuleId,
                    Version         = feature.Version,
                    FeatureSettings = new FeatureSettings()
                };

                var newOrUpdatedFeature = await _shellFeatureStore.CreateAsync(existingFeature);

                if (newOrUpdatedFeature != null)
                {
                    output.Add(new ShellModule(newOrUpdatedFeature));
                }
            }

            return(output);
        }
Exemplo n.º 2
0
        async Task InitializeDefaultFeatureSettings(IFeatureEventContext context)
        {
            var features = await _shellFeatureStore.SelectFeatures();

            var feature = features.FirstOrDefault(f => f.ModuleId.Equals(context.Feature.ModuleId, StringComparison.OrdinalIgnoreCase));

            if (feature != null)
            {
                feature.FeatureSettings = new FeatureSettings()
                {
                    Title       = "Search",
                    Description = "Search Help & Support",
                    IconCss     = "fal fa-search"
                };

                // Persist changes
                await _shellFeatureStore.UpdateAsync(feature);
            }

            // Apply default permissions to default roles for new feature
            await _defaultRolesManager.UpdateDefaultRolesAsync(new Permissions());
        }
Exemplo n.º 3
0
        public override async Task InstalledAsync(IFeatureEventContext context)
        {
            // Update default feature settings
            var features = await _shellFeatureStore.SelectFeatures();

            var feature = features.FirstOrDefault(f => f.ModuleId == base.ModuleId);

            if (feature != null)
            {
                feature.FeatureSettings = new FeatureSettings()
                {
                    Title       = "Articles",
                    Description = ""
                };

                // Persist changes
                await _shellFeatureStore.UpdateAsync(feature);
            }

            // Apply default permissions to default roles for new feature
            await _defaultRolesManager.UpdateDefaultRolesAsync(new Permissions());
        }
Exemplo n.º 4
0
        public async Task <ICommandResultBase> InitialMigrationsAsync()
        {
            // Our result
            var output = new CommandResultBase();

            // Get all installed features
            var features = await _shellFeatureStore.SelectFeatures();

            // We need features to upgrade
            if (features == null)
            {
                return(output.Failed("No features could be found within the shell features store."));
            }

            // Attempt to update each found feature and compile any errors
            var errors = new List <CommandError>();

            foreach (var feature in features)
            {
                var result = await _shellFeatureUpdater.UpdateAsync(feature.ModuleId);

                if (result.Errors.Any())
                {
                    errors.AddRange(result.Errors);
                }
            }

            // Did any feature upgrade encounter errors?
            if (errors.Count > 0)
            {
                return(output.Failed(errors.ToArray()));
            }

            // Return success
            return(output.Success());
        }
Exemplo n.º 5
0
        public async Task <IShellFeature> GetFeatureByIdAsync(string moduleId)
        {
            var features = await _shellFeatureStore.SelectFeatures();

            return(features?.FirstOrDefault(f => f.ModuleId.Equals(moduleId, StringComparison.OrdinalIgnoreCase)));
        }