public void Uninstalled(Feature feature)
 {
     var featureName = feature.Descriptor.Id;
     if ( _dataMigrationManager.IsFeatureAlreadyInstalled(featureName) ) {
         _dataMigrationManager.Uninstall(featureName);
     }
 }
        public ShapeAlterationBuilder(Feature feature, string shapeType)
        {
            _feature = feature;
            _bindingName = shapeType;
            var delimiterIndex = shapeType.IndexOf("__");

            if (delimiterIndex < 0) {
                _shapeType = shapeType;
            }
            else {
                _shapeType = shapeType.Substring(0, delimiterIndex);
            }
        }
        public void AddDefaultRolesForFeature(Feature feature)
        {
            var featureName = feature.Descriptor.Id;

            // when another module is being enabled, locate matching permission providers
            var providersForEnabledModule = _permissionProviders.Where(x => x.Feature.Descriptor.Id == featureName).ToList();

            if (providersForEnabledModule.Any()) {
                Logger.Debug("Configuring default roles for module {0}", featureName);
            }
            else {
                Logger.Debug("No default roles for module {0}", featureName);
            }

            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 = _roleService.GetRoleByName(stereotype.Name);
                    if (role == null) {
                        Logger.Information("Defining new role {0} for permission stereotype", stereotype.Name);

                        _roleService.CreateRole(stereotype.Name);
                        role = _roleService.GetRoleByName(stereotype.Name);
                    }

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

                    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) {
                            Logger.Information("Default role {0} granted permission {1}", stereotype.Name, permissionName);
                            _roleService.CreatePermissionForRole(role.Name, permissionName);
                        }
                    }
                }
            }
        }
        public void Init()
        {
            var testFeature = new Feature
            {
                Descriptor = new FeatureDescriptor
                {
                    Id = "Testing",
                    Extension = new ExtensionDescriptor
                    {
                        Id = "Testing",
                        ExtensionType = DefaultExtensionTypes.Module,
                    }
                }
            };

            var workContext = new DefaultDisplayManagerTests.TestWorkContext
            {
                CurrentTheme = new ExtensionDescriptor { Id = "Hello" }
            };

            var builder = new ContainerBuilder();
            builder.RegisterModule(new ShapeAttributeBindingModule());
            builder.RegisterType<ShapeAttributeBindingStrategy>().As<IShapeTableProvider>();
            builder.RegisterType<ShapeTableLocator>().As<IShapeTableLocator>();
            builder.RegisterType<DefaultDisplayManager>().As<IDisplayManager>();
            builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
            builder.RegisterType<DisplayHelperFactory>().As<IDisplayHelperFactory>();
            builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
            builder.RegisterType<StubCacheManager>().As<ICacheManager>();
            builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
            builder.RegisterInstance(new DefaultDisplayManagerTests.TestWorkContextAccessor(workContext)).As<IWorkContextAccessor>();
            builder.RegisterInstance(new SimpleShapes()).WithMetadata("Feature", testFeature);
            builder.RegisterInstance(new RouteCollection());
            builder.RegisterAutoMocking(MockBehavior.Loose);

            _container = builder.Build();
            _container.Resolve<Mock<ICoeveryHostContainer>>()
                .Setup(x => x.Resolve<IComponentContext>())
                .Returns(_container);
        }
 protected override void Register([NotNull] ContainerBuilder builder)
 {
     if (builder == null) {
         throw new ArgumentNullException("builder");
     }
     builder.RegisterAutoMocking();
     _testFeature = new Feature {
         Descriptor = new FeatureDescriptor {
             Id = "Testing",
             Extension = new ExtensionDescriptor {
                 Id = "Testing",
                 ExtensionType = DefaultExtensionTypes.Module,
             }
         }
     };
     builder.RegisterType<ShapeAttributeBindingStrategy>().As<IShapeTableProvider>();
     builder.RegisterInstance(new TestProvider()).WithMetadata("Feature", _testFeature);
     builder.RegisterInstance(new RouteCollection());
     builder.RegisterModule(new ShapeAttributeBindingModule());
 }
 void IFeatureEventHandler.Uninstalling(Feature feature)
 {
 }
 void IFeatureEventHandler.Installing(Feature feature)
 {
     AddDefaultRolesForFeature(feature);
 }
 void IFeatureEventHandler.Installed(Feature feature)
 {
 }
 void IFeatureEventHandler.Enabling(Feature feature)
 {
 }
 void IFeatureEventHandler.Enabled(Feature feature)
 {
 }
 public void Disabling(Feature feature)
 {
 }
 public ShapeTableBuilder(Feature feature)
 {
     _feature = feature;
 }
 void IFeatureEventHandler.Disabled(Feature feature)
 {
 }
 public void Uninstalling(Feature feature)
 {
 }
 public void Enabled(Feature feature)
 {
 }
 public void Installing(Feature feature)
 {
     var featureName = feature.Descriptor.Id;
     _dataMigrationManager.Update(featureName);
 }
 public void Installed(Feature feature)
 {
 }
 public void Enabling(Feature feature)
 {
 }
        private void ProcessPlacementFile(ShapeTableBuilder builder, FeatureDescriptor featureDescriptor, PlacementFile placementFile)
        {
            var feature = new Feature { Descriptor = featureDescriptor };

            // invert the tree into a list of leaves and the stack
            var entries = DrillDownShapeLocations(placementFile.Nodes, Enumerable.Empty<PlacementMatch>());
            foreach (var entry in entries) {
                var shapeLocation = entry.Item1;
                var matches = entry.Item2;

                string shapeType;
                string differentiator;
                GetShapeType(shapeLocation, out shapeType, out differentiator);

                Func<ShapePlacementContext, bool> predicate = ctx => true;
                if (differentiator != "") {
                    predicate = ctx => (ctx.Differentiator ?? "") == differentiator;
                }

                if (matches.Any()) {
                    predicate =  matches.SelectMany(match => match.Terms).Aggregate(predicate, BuildPredicate);
                }

                var placement = new PlacementInfo();

                var segments = shapeLocation.Location.Split(';').Select(s => s.Trim());
                foreach (var segment in segments) {
                    if (!segment.Contains('=')) {
                        placement.Location = segment;
                    }
                    else {
                        var index = segment.IndexOf('=');
                        var property = segment.Substring(0, index).ToLower();
                        var value = segment.Substring(index + 1);
                        switch (property) {
                            case "shape":
                                placement.ShapeType = value;
                                break;
                            case "alternate":
                                placement.Alternates = new[] { value };
                                break;
                            case "wrapper":
                                placement.Wrappers = new[] { value };
                                break;
                        }
                    }
                }

                builder.Describe(shapeType)
                    .From(feature)
                    .Placement(ctx => {
                                   var hit = predicate(ctx);
                                   // generate 'debugging' information to trace which file originated the actual location
                                    if (hit) {
                                       var virtualPath = featureDescriptor.Extension.Location + "/" + featureDescriptor.Extension.Id + "/Placement.info";
                                       ctx.Source = virtualPath;
                                   }
                                   return hit;
                               }, placement);
            }
        }
 public ShapeAlterationBuilder From(Feature feature)
 {
     _feature = feature;
     return this;
 }
 public ShapeAlteration(string shapeType, Feature feature, IList<Action<ShapeDescriptor>> configurations)
 {
     _configurations = configurations;
     ShapeType = shapeType;
     Feature = feature;
 }
 public void Disabled(Feature feature)
 {
 }