Beispiel #1
0
 void IFeatureEventHandler.Installing(IFeatureInfo feature)
 {
 }
Beispiel #2
0
 public void TryAdd(Type type, IFeatureInfo feature)
 {
     dummyVar0 = this._features.TryAdd(type, feature);
     return;
 }
Beispiel #3
0
 Task IFeatureEventHandler.DisablingAsync(IFeatureInfo feature)
 {
     return(Task.CompletedTask);
 }
Beispiel #4
0
 public virtual void Built(IFeatureInfo featureInfo)
 {
 }
 public Task <FeatureEntry> LoadFeatureAsync(IFeatureInfo feature)
 {
     return(Task.FromResult((FeatureEntry) new NonCompiledFeatureEntry(feature)));
 }
Beispiel #6
0
 Task IFeatureEventHandler.UninstalledAsync(IFeatureInfo feature) => Task.CompletedTask;
 private int GetPriority(IFeatureInfo feature)
 {
     return(_extensionPriorityStrategies.Sum(s => s.GetPriority(feature)));
 }
 public ShapeAlterationBuilder From(IFeatureInfo feature)
 {
     _feature = feature;
     return(this);
 }
 public void NotifyFeatureStart(IFeatureInfo feature)
 {
     _notifier.NotifyFeatureStart(feature);
 }
Beispiel #10
0
 void IFeatureEventHandler.Uninstalled(IFeatureInfo feature)
 {
 }
Beispiel #11
0
        public async Task AddDefaultRolesForFeatureAsync(IFeatureInfo feature)
        {
            // when another module is being enabled, locate matching permission providers
            var providersForEnabledModule = _permissionProviders
                                            .Where(x => _typeFeatureProvider.GetFeatureForDependency(x.GetType()).Id == feature.Id);

            if (Logger.IsEnabled(LogLevel.Debug))
            {
                if (providersForEnabledModule.Any())
                {
                    Logger.LogDebug($"Configuring default roles for module {feature.Id}");
                }
                else
                {
                    Logger.LogDebug($"No default roles for module {feature.Id}");
                }
            }

            foreach (var permissionProvider in providersForEnabledModule)
            {
                // get and iterate stereotypical groups of permissions
                var stereotypes = permissionProvider.GetDefaultStereotypes();
                foreach (var stereotype in stereotypes)
                {
                    // turn those stereotypes into roles
                    var role = await _roleManager.FindByNameAsync(stereotype.Name);

                    if (role == null)
                    {
                        if (Logger.IsEnabled(LogLevel.Information))
                        {
                            Logger.LogInformation($"Defining new role {stereotype.Name} for permission stereotype");
                        }

                        role = new Role {
                            RoleName = stereotype.Name
                        };
                        await _roleManager.CreateAsync(role);
                    }

                    // and merge the stereotypical permissions into that role
                    var stereotypePermissionNames = (stereotype.Permissions ?? Enumerable.Empty <Permission>()).Select(x => x.Name);
                    var currentPermissionNames    = role.RoleClaims.Where(x => x.ClaimType == Permission.ClaimType).Select(x => x.ClaimValue);

                    var distinctPermissionNames = currentPermissionNames
                                                  .Union(stereotypePermissionNames)
                                                  .Distinct();

                    // update role if set of permissions has increased
                    var additionalPermissionNames = distinctPermissionNames.Except(currentPermissionNames);

                    if (additionalPermissionNames.Any())
                    {
                        foreach (var permissionName in additionalPermissionNames)
                        {
                            if (Logger.IsEnabled(LogLevel.Debug))
                            {
                                Logger.LogInformation("Default role {0} granted permission {1}", stereotype.Name, permissionName);
                            }

                            await _roleManager.AddClaimAsync(role, new Claim(Permission.ClaimType, permissionName));
                        }
                    }
                }
            }
        }
Beispiel #12
0
 void IFeatureEventHandler.Disabled(IFeatureInfo feature)
 {
 }
Beispiel #13
0
 void IFeatureEventHandler.Enabling(IFeatureInfo feature)
 {
 }
Beispiel #14
0
 void IFeatureEventHandler.Installed(IFeatureInfo feature)
 {
     AddDefaultRolesForFeatureAsync(feature).Wait();
 }
Beispiel #15
0
 Task IFeatureEventHandler.EnabledAsync(IFeatureInfo feature) => SetMediaTokenSettingsAsync(feature);
 public int GetPriority(IFeatureInfo feature)
 {
     return(feature.Priority);
 }
Beispiel #17
0
 Task IFeatureEventHandler.DisabledAsync(IFeatureInfo feature) => Task.CompletedTask;
 /// <summary>
 /// Initializes a new instance of the <see cref="FoundFeatureInfo"/> class.
 /// </summary>
 /// <param name="commandHandlerInfo">The FTP command handler information.</param>
 /// <param name="featureInfo">The feature information.</param>
 public FoundFeatureInfo(IFtpCommandHandlerInformation commandHandlerInfo, IFeatureInfo featureInfo)
 {
     IsCommandHandler    = true;
     _commandHandlerInfo = commandHandlerInfo;
     FeatureInfo         = featureInfo;
 }
 private bool HasDependency(IFeatureInfo f1, IFeatureInfo f2)
 {
     return(_extensionDependencyStrategies.Any(s => s.HasDependency(f1, f2)));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FoundFeatureInfo"/> class.
 /// </summary>
 /// <param name="extensionInfo">The FTP command handler extension information.</param>
 /// <param name="featureInfo">The feature information.</param>
 public FoundFeatureInfo(IFtpCommandHandlerExtensionInformation extensionInfo, IFeatureInfo featureInfo)
 {
     IsExtension    = true;
     _extensionInfo = extensionInfo;
     FeatureInfo    = featureInfo;
 }
Beispiel #21
0
 public bool HasDependency(IFeatureInfo observer, IFeatureInfo subject)
 {
     return(observer.Dependencies.Contains(subject.Id));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FoundFeatureInfo"/> class.
 /// </summary>
 /// <param name="authMechanism">The authentication mechanism.</param>
 /// <param name="featureInfo">The feature information.</param>
 public FoundFeatureInfo(IAuthenticationMechanism authMechanism, IFeatureInfo featureInfo)
 {
     IsAuthenticationMechanism = true;
     _authenticationMechanism  = authMechanism;
     FeatureInfo = featureInfo;
 }
        /// <summary>
        /// Disables a feature.
        /// </summary>
        /// <param name="featureId">The ID of the feature to be enabled.</param>
        /// <param name="force">Boolean parameter indicating if the feature should enable it's dependencies if required or fail otherwise.</param>
        /// <returns>An enumeration of the disabled features.</returns>
        private IEnumerable <IFeatureInfo> GetFeaturesToDisable(ShellDescriptor shellDescriptor, IFeatureInfo featureInfo, bool force)
        {
            var enabledFeatures = _extensionManager.GetEnabledFeatures(shellDescriptor).ToArray();

            var affectedFeatures = _extensionManager
                                   .GetDependentFeatures(featureInfo.Id, enabledFeatures)
                                   .ToList();

            if (affectedFeatures.Count > 1 && !force)
            {
                if (_logger.IsEnabled(LogLevel.Warning))
                {
                    _logger.LogWarning("Additional features need to be disabled.");
                }
                if (FeatureDependencyNotification != null)
                {
                    FeatureDependencyNotification("If {0} is disabled, then you'll also need to disable {1}.", featureInfo, affectedFeatures.Where(f => f.Id != featureInfo.Id));
                }
            }

            return(affectedFeatures);
        }
Beispiel #24
0
        /// <summary>
        /// Disables a feature.
        /// </summary>
        /// <param name="featureId">The ID of the feature to be enabled.</param>
        /// <param name="force">Boolean parameter indicating if the feature should enable it's dependencies if required or fail otherwise.</param>
        /// <returns>An enumeration of the disabled features.</returns>
        private async Task <IEnumerable <IFeatureInfo> > DisableFeatureAsync(ShellDescriptor shellDescriptor, IFeatureInfo featureInfo, bool force)
        {
            IEnumerable <string> affectedFeatures =
                await GetDependentFeaturesAsync(shellDescriptor, featureInfo.Id);

            var featuresToDisable = _extensionManager
                                    .GetExtensions()
                                    .Features
                                    .Where(x => affectedFeatures.Contains(x.Id))
                                    .ToList();

            if (featuresToDisable.Count > 1 && !force)
            {
                if (_logger.IsEnabled(LogLevel.Warning))
                {
                    _logger.LogWarning("Additional features need to be disabled.");
                }
                if (FeatureDependencyNotification != null)
                {
                    FeatureDependencyNotification("If {0} is disabled, then you'll also need to disable {1}.", featureInfo, featuresToDisable.Where(f => f.Id != featureInfo.Id));
                }
            }

            return(featuresToDisable);
        }
 public bool DependencyOn(IFeatureInfo feature)
 {
     return(false);
 }
        public ShapeTable GetShapeTable(string themeId)
        {
            var cacheKey = $"ShapeTable:{themeId}";

            ShapeTable shapeTable;

            if (!_memoryCache.TryGetValue(cacheKey, out shapeTable))
            {
                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("Start building shape table");
                }
                IList <IReadOnlyList <ShapeAlteration> > alterationSets = new List <IReadOnlyList <ShapeAlteration> >();
                foreach (var bindingStrategy in _bindingStrategies)
                {
                    IFeatureInfo strategyDefaultFeature =
                        _typeFeatureProvider.GetFeatureForDependency(bindingStrategy.GetType());

                    var builder = new ShapeTableBuilder(strategyDefaultFeature);

                    bindingStrategy.Discover(builder);

                    var builtAlterations = builder.BuildAlterations().ToReadOnlyCollection();
                    if (builtAlterations.Any())
                    {
                        alterationSets.Add(builtAlterations);
                    }
                }

                var alterations = alterationSets
                                  .SelectMany(shapeAlterations => shapeAlterations)
                                  .Where(alteration => IsModuleOrRequestedTheme(alteration, themeId))
                                  .OrderByDependenciesAndPriorities(AlterationHasDependency, GetPriority)
                                  .ToList();

                var descriptors = alterations.GroupBy(alteration => alteration.ShapeType, StringComparer.OrdinalIgnoreCase)
                                  .Select(group => group.Aggregate(
                                              new ShapeDescriptor {
                    ShapeType = group.Key
                },
                                              (descriptor, alteration) =>
                {
                    alteration.Alter(descriptor);
                    return(descriptor);
                })).ToList();

                foreach (var descriptor in descriptors)
                {
                    foreach (var alteration in alterations.Where(a => a.ShapeType == descriptor.ShapeType).ToList())
                    {
                        var local = new ShapeDescriptor {
                            ShapeType = descriptor.ShapeType
                        };
                        alteration.Alter(local);
                        descriptor.BindingSources.Add(local.BindingSource);
                    }
                }

                shapeTable = new ShapeTable
                {
                    Descriptors = descriptors.ToDictionary(sd => sd.ShapeType, StringComparer.OrdinalIgnoreCase),
                    Bindings    = descriptors.SelectMany(sd => sd.Bindings).ToDictionary(kv => kv.Key, kv => kv.Value, StringComparer.OrdinalIgnoreCase),
                };

                //await _eventBus.NotifyAsync<IShapeTableEventHandler>(x => x.ShapeTableCreated(result));

                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("Done building shape table");
                }

                _memoryCache.Set(cacheKey, shapeTable, new MemoryCacheEntryOptions {
                    Priority = CacheItemPriority.NeverRemove
                });
            }

            return(shapeTable);
        }
Beispiel #27
0
 Task IFeatureEventHandler.InstalledAsync(IFeatureInfo feature)
 {
     return(Task.CompletedTask);
 }
Beispiel #28
0
 Task IFeatureEventHandler.EnablingAsync(IFeatureInfo feature) => Task.CompletedTask;
Beispiel #29
0
 Task IFeatureEventHandler.UninstallingAsync(IFeatureInfo feature)
 {
     return(Task.CompletedTask);
 }
        public ShapeTable GetShapeTable(string themeId)
        {
            var cacheKey = $"ShapeTable:{themeId}";

            ShapeTable shapeTable;

            if (!_memoryCache.TryGetValue(cacheKey, out shapeTable))
            {
                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("Start building shape table");
                }

                var excludedFeatures = _shapeDescriptors.Count == 0 ? new List <string>() :
                                       _shapeDescriptors.Select(kv => kv.Value.Feature.Id).Distinct().ToList();

                foreach (var bindingStrategy in _bindingStrategies)
                {
                    IFeatureInfo strategyFeature = _typeFeatureProvider.GetFeatureForDependency(bindingStrategy.GetType());

                    if (!(bindingStrategy is IShapeTableHarvester) && excludedFeatures.Contains(strategyFeature.Id))
                    {
                        continue;
                    }

                    var builder = new ShapeTableBuilder(strategyFeature, excludedFeatures);
                    bindingStrategy.Discover(builder);
                    var builtAlterations = builder.BuildAlterations();

                    BuildDescriptors(bindingStrategy, builtAlterations);
                }

                var enabledAndOrderedFeatureIds = _shellFeaturesManager
                                                  .GetEnabledFeaturesAsync()
                                                  .GetAwaiter()
                                                  .GetResult()
                                                  .Select(f => f.Id)
                                                  .ToList();

                // let the application acting as a super theme for shapes rendering.
                if (enabledAndOrderedFeatureIds.Remove(_hostingEnvironment.ApplicationName))
                {
                    enabledAndOrderedFeatureIds.Add(_hostingEnvironment.ApplicationName);
                }

                var descriptors = _shapeDescriptors
                                  .Where(sd => enabledAndOrderedFeatureIds.Contains(sd.Value.Feature.Id))
                                  .Where(sd => IsModuleOrRequestedTheme(sd.Value.Feature, themeId))
                                  .OrderBy(sd => enabledAndOrderedFeatureIds.IndexOf(sd.Value.Feature.Id))
                                  .GroupBy(sd => sd.Value.ShapeType, StringComparer.OrdinalIgnoreCase)
                                  .Select(group => new ShapeDescriptorIndex
                                          (
                                              shapeType: group.Key,
                                              alterationKeys: group.Select(kv => kv.Key),
                                              descriptors: _shapeDescriptors
                                          ));

                shapeTable = new ShapeTable
                {
                    Descriptors = descriptors.Cast <ShapeDescriptor>().ToDictionary(sd => sd.ShapeType, StringComparer.OrdinalIgnoreCase),
                    Bindings    = descriptors.SelectMany(sd => sd.Bindings).ToDictionary(kv => kv.Key, kv => kv.Value, StringComparer.OrdinalIgnoreCase)
                };

                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("Done building shape table");
                }

                _memoryCache.Set(cacheKey, shapeTable, new MemoryCacheEntryOptions {
                    Priority = CacheItemPriority.NeverRemove
                });
            }

            return(shapeTable);
        }