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 void Discover(ShapeTableBuilder builder)
 {
     builder.Describe("ProductAttributesAdminListItem")
     .OnDisplaying(displaying => {
         displaying.ShapeMetadata.Alternates.Add("ProductAttributesLocalizationAdminListItem");
     });
 }
        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("Parts_MenuWidget").OnDisplaying(context =>
            {
                var contentItem    = (ContentItem)context.Shape.ContentItem;
                var widgetPart     = contentItem.As <WidgetPart>();
                var menuWidgetPart = contentItem.As <MenuWidgetPart>();
                var menuShape      = context.Shape.Menu;
                var widgetName     = widgetPart.Name.ToSafeName();
                var menu           = mMenuService.Value.GetMenu(menuWidgetPart.MenuContentItemId);
                var menuName       = menu.As <TitlePart>().Title.ToSafeName();
                var zoneName       = widgetPart.Zone;

                if (!String.IsNullOrWhiteSpace(widgetName))
                {
                    context.ShapeMetadata.Alternates.Add($"Parts_MenuWidget__WidgetName__{widgetName}");
                }

                context.ShapeMetadata.Alternates.Add($"Parts_MenuWidget__MenuName__{menuName}");
                context.ShapeMetadata.Alternates.Add($"Parts_MenuWidget__MenuLevel__{menuWidgetPart.StartLevel}");
                context.ShapeMetadata.Alternates.Add($"Parts_MenuWidget__MenuName__{menuName}__MenuLevel{menuWidgetPart.StartLevel}");
                context.ShapeMetadata.Alternates.Add($"Parts_MenuWidget__Zone__{zoneName}");
                context.ShapeMetadata.Alternates.Add($"Parts_MenuWidget__Zone__{zoneName}__MenuName__{menuName}");

                menuShape.MenuWidget   = contentItem;
                menuShape.SafeMenuName = menuName;
            });

            builder.Describe("Menu").OnDisplaying(ConfigureMenuShape);
            builder.Describe("Breadcrumb").OnDisplaying(ConfigureMenuShape);
        }
 public void Discover(ShapeTableBuilder builder)
 {
     builder.Describe("Content")
     .OnDisplaying(displaying => {
         displaying.ShapeMetadata.Wrappers.Add("Wrapper__Cw");
     });
 }
Example #5
0
        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("Post_Body_Editor")
            .OnDisplaying(displaying => {
                string flavor = displaying.Shape.EditorFlavor;
                displaying.ShapeMetadata.Alternates.Add("Post_Body_Editor__" + flavor);
            });

            // We support multiple forum types, but need to be able to skin forum admin shapes, so add alternates for any content type that has a ForumPart.
            builder.Describe("Content").OnDisplaying(displaying => {
                var content = (ContentItem)displaying.Shape.ContentItem;

                if (content.Parts.All(x => x.PartDefinition.Name != typeof(ForumPart).Name))
                {
                    return;
                }

                var displayType = !String.IsNullOrWhiteSpace(displaying.ShapeMetadata.DisplayType) ? displaying.ShapeMetadata.DisplayType : "Detail";
                var alternates  = new[] {
                    string.Format("Content__{0}", content.ContentType),
                    string.Format("Content__{0}_{1}", content.ContentType, displayType),
                };

                foreach (var alternate in alternates.Where(alternate => !displaying.ShapeMetadata.Alternates.Contains(alternate)))
                {
                    displaying.ShapeMetadata.Alternates.Add(alternate);
                }
            });
        }
        private void ProcessPlacementFile(ShapeTableBuilder builder, IFeatureInfo featureDescriptor, PlacementFile placementFile)
        {
            foreach (var entry in placementFile)
            {
                var shapeType = entry.Key;
                var matches   = entry.Value;


                foreach (var filter in entry.Value)
                {
                    var placement = new PlacementInfo();
                    placement.Location = filter.Location;
                    if (filter.Alternates?.Length > 0)
                    {
                        placement.Alternates = new AlternatesCollection(filter.Alternates);
                    }

                    if (filter.Wrappers?.Length > 0)
                    {
                        placement.Wrappers = new AlternatesCollection(filter.Wrappers);
                    }

                    placement.ShapeType = filter.ShapeType;

                    builder.Describe(shapeType)
                    .From(featureDescriptor)
                    .Placement(ctx => CheckFilter(ctx, filter), placement);
                }
            }
        }
Example #7
0
        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("Widget")
            .Configure(descriptor => {
                // todo: have "alternates" for chrome
                descriptor.Wrappers.Add("Widget_Wrapper");
                descriptor.Wrappers.Add("Widget_ControlWrapper");
            })
            .OnCreated(created => {
                var widget = created.Shape;
                widget.Child.Add(created.New.PlaceChildContent(Source: widget));
            })
            .OnDisplaying(displaying => {
                var widget = displaying.Shape;
                widget.Classes.Add("widget");

                ContentItem contentItem = displaying.Shape.ContentItem;
                if (contentItem != null)
                {
                    widget.Classes.Add("widget-" + contentItem.ContentType.HtmlClassify());

                    var zoneName = contentItem.As <WidgetPart>().Zone;

                    // Widget__[ZoneName] e.g. Widget-SideBar
                    displaying.ShapeMetadata.Alternates.Add("Widget__" + zoneName);

                    // Widget__[ContentType] e.g. Widget-BlogArchive
                    displaying.ShapeMetadata.Alternates.Add("Widget__" + contentItem.ContentType);
                }
            });
        }
Example #8
0
        public void TemplateResolutionWorks()
        {
            AddEnabledFeature("Alpha");

            _testViewEngine.Add("~/Modules/Alpha/Styles/AlphaShape.css", null);
            _testViewEngine.Add("~/Modules/Alpha/Styles/alpha-shape.css", null);
            var strategy = _container.Resolve <IShapeTableProvider>();

            var builder = new ShapeTableBuilder(null);

            strategy.Discover(builder);
            var alterations = builder.BuildAlterations();

            Assert.That(alterations.Any(alteration => alteration.ShapeType == "Style"));

            var descriptor = new ShapeDescriptor {
                ShapeType = "Style"
            };

            alterations.Aggregate(descriptor, (d, alteration) => {
                alteration.Alter(d);
                return(d);
            });

            var keys = descriptor.Bindings.Select(b => b.Key);

            Assert.That(keys.Count() == keys.Select(k => k.ToLowerInvariant()).Distinct().Count(), "Descriptors should never vary by case only.");
        }
Example #9
0
        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("Content")
            .OnDisplaying(displaying =>
            {
                if (AdminFilter.IsApplied(new RequestContext(_workContext.GetContext().HttpContext, new RouteData())))
                {
                    return;
                }

                if (displaying.ShapeMetadata.DisplayType != "Detail")
                {
                    return;
                }

                ContentItem contentItem = displaying.Shape.ContentItem;
                if (contentItem != null)
                {
                    var wavePart = contentItem.As <WavePart>();

                    if (wavePart == null)
                    {
                        return;
                    }

                    displaying.ShapeMetadata.Wrappers.Add("Wave_Wrapper");
                }
            });
        }
Example #10
0
 public void Discover(ShapeTableBuilder builder)
 {
     builder.Describe("Widget")
     .Configure(descriptor => {
         descriptor.Wrappers.Add("Widget_ControlWrapper");
     });
 }
Example #11
0
        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("Content")
            .OnCreated(created => {
                var content = created.Shape;
                content.Child.Add(created.New.PlaceChildContent(Source: content));
            })
            .OnDisplaying(displaying => {
                ContentItem contentItem = displaying.Shape.ContentItem;
                if (contentItem != null)
                {
                    // Alternates in order of specificity.
                    // Display type > content type > specific content > display type for a content type > display type for specific content
                    // BasicShapeTemplateHarvester.Adjust will then adjust the template name

                    // Content__[DisplayType] e.g. Content-Summary
                    displaying.ShapeMetadata.Alternates.Add("Content_" + EncodeAlternateElement(displaying.ShapeMetadata.DisplayType));

                    // Content__[ContentType] e.g. Content-BlogPost,
                    displaying.ShapeMetadata.Alternates.Add("Content__" + EncodeAlternateElement(contentItem.ContentType));

                    // Content__[Id] e.g. Content-42,
                    displaying.ShapeMetadata.Alternates.Add("Content__" + contentItem.Id);

                    // Content_[DisplayType]__[ContentType] e.g. Content-BlogPost.Summary
                    displaying.ShapeMetadata.Alternates.Add("Content_" + displaying.ShapeMetadata.DisplayType + "__" + EncodeAlternateElement(contentItem.ContentType));

                    // Content_[DisplayType]__[Id] e.g. Content-42.Summary
                    displaying.ShapeMetadata.Alternates.Add("Content_" + displaying.ShapeMetadata.DisplayType + "__" + contentItem.Id);
                }
            });
        }
Example #12
0
        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("Parts_Comments")
            .OnDisplaying(shapeDisplayingContext =>
            {
                var settings = this.orchardServices.WorkContext.CurrentSite.As <DisqusSettingsPart>();
                shapeDisplayingContext.Shape.DisqusSettings = settings;
                shapeDisplayingContext.Shape.DisqusUniqueId = GetUniqueIdentifier(shapeDisplayingContext.Shape.ContentPart.ContentItem);
                shapeDisplayingContext.ShapeMetadata.Wrappers.Add("CommentsWrapper");
            });

            builder.Describe("Parts_Comments_Count")
            .OnDisplaying(shapeDisplayingContext =>
            {
                var settings = this.orchardServices.WorkContext.CurrentSite.As <DisqusSettingsPart>();
                shapeDisplayingContext.Shape.DisqusSettings = settings;
                shapeDisplayingContext.Shape.DisqusUniqueId = GetUniqueIdentifier(shapeDisplayingContext.Shape.ContentPart.ContentItem);
                shapeDisplayingContext.ShapeMetadata.Wrappers.Add("CountWrapper");
            });

            builder.Describe("Parts_Blogs_BlogPost_List")
            .OnDisplaying(shapeDisplayingContext =>
            {
                var settings = this.orchardServices.WorkContext.CurrentSite.As <DisqusSettingsPart>();
                shapeDisplayingContext.Shape.DisqusSettings = settings;
                shapeDisplayingContext.ShapeMetadata.Wrappers.Add("ListWrapper");
            });
        }
        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("HeadScripts")
            .OnDisplaying(shapeDisplayingContext =>
            {
                if (!_imagesLoadedService.GetAutoEnable())
                {
                    return;
                }
                if (!_imagesLoadedService.GetAutoEnableAdmin())
                {
                    var request = _workContext.Value.HttpContext.Request;
                    if (AdminFilter.IsApplied(request.RequestContext))
                    {
                        return;
                    }
                }

                var resourceManager = _workContext.Value.Resolve <IResourceManager>();
                var scripts         = resourceManager.GetRequiredResources("script");


                string includejs     = "imagesLoaded";
                var currentHighlight = scripts
                                       .Where(l => l.Name == includejs)
                                       .FirstOrDefault();

                if (currentHighlight == null)
                {
                    resourceManager.Require("script", includejs).AtFoot();
                }
            });
        }
Example #14
0
 public void Discover(ShapeTableBuilder builder)
 {
     builder.Describe("Price")
     .OnDisplaying(displaying => {
         displaying.ShapeMetadata.Alternates.Add("Parts_" + displaying.ShapeMetadata.DisplayType);
     });
 }
Example #15
0
        static IEnumerable <ShapeAlteration> GetAlterationBuilders(IShapeTableProvider strategy)
        {
            var builder = new ShapeTableBuilder(null);

            strategy.Discover(builder);
            return(builder.BuildAlterations());
        }
Example #16
0
        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("LogOn")
            .OnDisplaying(displaying => {
                var clientsData = _openAuthAuthenticationClients
                                  .Select(client => _orchardOpenAuthClientProvider.GetClientData(client.ProviderName))
                                  .Where(x => x != null && x.IsWebSiteLoginEnabled)
                                  .ToList();
                var shape    = displaying.Shape;
                var metadata = displaying.ShapeMetadata;

                shape.ClientsData = clientsData;

                metadata.Type = "OpenAuthLogOn";
            });

            builder.Describe("Register")
            .OnDisplaying(displaying => {
                var clientsData = _openAuthAuthenticationClients
                                  .Select(client => _orchardOpenAuthClientProvider.GetClientData(client.ProviderName))
                                  .Where(x => x != null && x.IsWebSiteLoginEnabled)
                                  .ToList();

                var shape    = displaying.Shape;
                var metadata = displaying.ShapeMetadata;

                shape.ClientsData = clientsData;

                metadata.Type = "OpenAuthRegister";
            });
        }
Example #17
0
        public void Discover(ShapeTableBuilder builder)
        {
            var shapeAttributeOccurrences = new List <ShapeAttributeOccurrence>();

            foreach (var shapeProvider in _shapeProviders)
            {
                var serviceType = shapeProvider.GetType();

                foreach (var method in serviceType.GetMethods())
                {
                    var customAttributes = method.GetCustomAttributes(typeof(ShapeAttribute), false).OfType <ShapeAttribute>();
                    foreach (var customAttribute in customAttributes)
                    {
                        shapeAttributeOccurrences.Add(new ShapeAttributeOccurrence(customAttribute, method, serviceType));
                    }
                }
            }

            foreach (var iter in shapeAttributeOccurrences)
            {
                var occurrence = iter;
                var shapeType  = occurrence.ShapeAttribute.ShapeType ?? occurrence.MethodInfo.Name;
                builder.Describe(shapeType)
                .From(_typeFeatureProvider.GetFeatureForDependency(occurrence.ServiceType))
                .BoundAs(
                    occurrence.MethodInfo.DeclaringType.FullName + "::" + occurrence.MethodInfo.Name,
                    CreateDelegate(occurrence));
            }
        }
Example #18
0
        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("Layout")
            .OnDisplaying(displaying =>
            {
                IShape layout   = displaying.Shape;
                var httpContext = _httpContextAccessor.Current();
                var routeValues = httpContext.Request.RequestContext.RouteData.Values;
                var controller  = (string)routeValues["controller"];
                if (controller == "SystemAdmin")
                {
                    layout.Metadata.Alternates.Add("Layout__" + controller);
                }
            });

            builder.Describe("Menu")
            .OnDisplaying(displaying =>
            {
                IShape layout   = displaying.Shape;
                var httpContext = _httpContextAccessor.Current();
                var routeValues = httpContext.Request.RequestContext.RouteData.Values;
                var controller  = (string)routeValues["controller"];
                if (controller == "SystemAdmin")
                {
                    layout.Metadata.Alternates.Add("Menu__" + controller);
                }
            });
        }
Example #19
0
        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("HeadLinks")
            .OnDisplaying(shapeDisplayingContext => {
                var faviconUrl = _faviconService.GetFaviconUrl();

                if (!string.IsNullOrWhiteSpace(faviconUrl))
                {
                    // Get the current favicon from head
                    var resourceManager = _wca.GetContext().Resolve <IResourceManager>();
                    var links           = resourceManager.GetRegisteredLinks();
                    var currentFavicon  = links.FirstOrDefault(l => l.Rel == "shortcut icon" && l.Type == "image/x-icon");

                    // Modify if found
                    if (currentFavicon != default(LinkEntry))
                    {
                        currentFavicon.Href = faviconUrl;
                    }
                    else
                    {
                        // Add the new one
                        resourceManager.RegisterLink(new LinkEntry {
                            Type = "image/x-icon",
                            Rel  = "shortcut icon",
                            Href = faviconUrl
                        });
                    }
                }
            });
        }
 private void ProcessFeatureDescriptor(ShapeTableBuilder builder, FeatureDescriptor featureDescriptor) {
     var virtualPath = featureDescriptor.Extension.Location + "/" + featureDescriptor.Extension.Id + "/Placement.info";
     var placementFile = _placementFileParser.Parse(virtualPath);
     if (placementFile != null) {
         ProcessPlacementFile(builder, featureDescriptor, placementFile);
     }
 }
Example #21
0
 public void Discover(ShapeTableBuilder builder)
 {
     foreach (var featureDescriptor in _featureManager.GetEnabledFeaturesAsync().Result)
     {
         ProcessFeatureDescriptor(builder, featureDescriptor);
     }
 }
Example #22
0
        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("Media")
            .OnDisplaying(displaying => {
                ContentItem contentItem = displaying.Shape.ContentItem;
                if (contentItem != null)
                {
                    // Alternates in order of specificity.
                    // Display type > content type > specific content > display type for a content type > display type for specific content
                    // BasicShapeTemplateHarvester.Adjust will then adjust the template name

                    // Media__[DisplayType] e.g. Media-Summary
                    displaying.ShapeMetadata.Alternates.Add("Media_" + EncodeAlternateElement(displaying.ShapeMetadata.DisplayType));

                    // Media__[ContentType] e.g. Media-BlogPost,
                    displaying.ShapeMetadata.Alternates.Add("Media__" + EncodeAlternateElement(contentItem.ContentType));

                    // Media__[Id] e.g. Media-42,
                    displaying.ShapeMetadata.Alternates.Add("Media__" + contentItem.Id);

                    // Media_[DisplayType]__[ContentType] e.g. Media-Image.Summary
                    displaying.ShapeMetadata.Alternates.Add("Media_" + displaying.ShapeMetadata.DisplayType + "__" + EncodeAlternateElement(contentItem.ContentType));

                    // Media_[DisplayType]__[Id] e.g. Media-42.Summary
                    displaying.ShapeMetadata.Alternates.Add("Media_" + displaying.ShapeMetadata.DisplayType + "__" + contentItem.Id);
                }
            });
        }
        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("RuleBasedMenuItem")
            .OnDisplaying(displaying =>
            {
                dynamic menuItem = displaying.Shape;
                int level        = menuItem.Level;

                ContentItem menuContentItem = menuItem.ContentItem;

                var encodedContentType   = EncodeAlternateElement(menuContentItem.ContentItem.ContentType);
                var encodedContentItemId = EncodeAlternateElement(menuContentItem.ContentItem.ContentItemId);

                menuItem.Metadata.Alternates.Add("RuleBasedMenuItem__level__" + level);

                // RuleBasedMenuItem__[ContentType] e.g. MenuItemLink-HtmlMenuItem
                // RuleBasedMenuItem__[ContentType]__level__[level] e.g. MenuItemLink-HtmlMenuItem-level-2
                menuItem.Metadata.Alternates.Add("RuleBasedMenuItem__" + encodedContentType);
                menuItem.Metadata.Alternates.Add("RuleBasedMenuItem__" + encodedContentType + "__level__" + level);

                // RuleBasedMenuItem__[MenuName] e.g. MenuItemLink-Main-Menu
                // RuleBasedMenuItem__[MenuName]__level__[level] e.g. MenuItemLink-Main-Menu-level-2
                menuItem.Metadata.Alternates.Add("RuleBasedMenuItem__" + encodedContentItemId);
                menuItem.Metadata.Alternates.Add("RuleBasedMenuItem__" + encodedContentItemId + "__level__" + level);

                // RuleBasedMenuItem__[MenuName]__[ContentType] e.g. MenuItemLink-Main-Menu-HtmlMenuItem
                // RuleBasedMenuItem__[MenuName]__[ContentType] e.g. MenuItemLink-Main-Menu-HtmlMenuItem-level-2
                menuItem.Metadata.Alternates.Add("RuleBasedMenuItem__" + encodedContentItemId + "__" + encodedContentType);
                menuItem.Metadata.Alternates.Add("RuleBasedMenuItem__" + encodedContentItemId + "__" + encodedContentType + "__level__" + level);
            });
        }
Example #24
0
        private void ProcessPlacementFile(ShapeTableBuilder builder, FeatureDescriptor featureDescriptor, PlacementFile placementFile)
        {
            var feature = new Feature {
                Descriptor = featureDescriptor
            };

            foreach (var entry in placementFile)
            {
                var shapeType = entry.Key;
                var matches   = entry.Value;


                foreach (var filter in entry.Value)
                {
                    var placement = new PlacementInfo();
                    placement.Location   = filter.Location;
                    placement.Alternates = filter.Alternates;
                    placement.Wrappers   = filter.Wrappers;
                    placement.ShapeType  = filter.ShapeType;

                    builder.Describe(shapeType)
                    .From(feature)
                    .Placement(ctx => CheckFilter(ctx, filter), placement);
                }
            }
        }
        public void Discover(ShapeTableBuilder builder)
        {
            foreach (var featureDescriptor in _featureManager.GetEnabledFeaturesAsync().Result)
            {
                ProcessFeatureDescriptor(builder, featureDescriptor);
            }

        }
Example #26
0
 public void Discover(ShapeTableBuilder builder)
 {
     builder.Describe("HeadScripts")
     .OnCreated(created =>
     {
         orchardServices.Value.WorkContext.Layout.Head.Add(created.New.BeforeHeadScriptsShape());
     });
 }
Example #27
0
 public void Discover(ShapeTableBuilder builder)
 {
     builder.Describe("LogOn")
     .OnDisplaying(displaying =>
     {
         displaying.ShapeMetadata.Type = "SkautIsLogOn";
     });
 }
Example #28
0
 public void Discover(ShapeTableBuilder builder)
 {
     builder.Describe("Body_Editor")
     .OnDisplaying(displaying => {
         string flavor = displaying.Shape.EditorFlavor;
         displaying.ShapeMetadata.Alternates.Add("Body_Editor__" + flavor);
     });
 }
Example #29
0
        public void Discover(ShapeTableBuilder builder)
        {
            string alternateName = "List__Bootstrap__ListGroup";

            AddAlternateShape_OnFrontEnd(builder, alternateName, "List");
            AddAlternateShape_OnFrontEnd(builder, alternateName, "Parts_Blogs_BlogPost_List");
            AddAlternateShape_OnFrontEnd(builder, alternateName, "Parts_Blogs_RecentBlogPosts");
        }
Example #30
0
 public void Discover(ShapeTableBuilder builder)
 {
     builder.Describe("OptionSet")
     .OnDisplaying(displaying => {
         var shape = displaying.Shape;
         shape.Classes.Add("option-set");
     });
 }
Example #31
0
 public void Discover(ShapeTableBuilder builder)
 {
     builder.Describe("Content_Edit")
     .OnDisplaying(displaying => {
         var shape = displaying.Shape;
         shape.Metadata.Alternates.Add("Content_Edit__Default");
     });
 }
Example #32
0
        public void Discover(ShapeTableBuilder builder)
        {
            var enabledFeatures = _shellFeaturesManager.GetEnabledFeaturesAsync().Result;

            foreach (var featureDescriptor in enabledFeatures)
            {
                ProcessFeatureDescriptor(builder, featureDescriptor);
            }
        }
 public void Discover(ShapeTableBuilder builder)
 {
     builder.Describe("Content").OnDisplaying(displaying => {
         if (!displaying.ShapeMetadata.DisplayType.Contains("Admin"))
         {
             displaying.ShapeMetadata.Wrappers.Add("Content_ControlWrapper");
         }
     });
 }
Example #34
0
 public void Discover(ShapeTableBuilder builder)
 {
     builder.Describe("Parts_ProjectionPart")
             .OnDisplaying(displaying => {
                 var shape = displaying.Shape;
                 if (shape.List.Items.Count == 0) {
                     shape.Metadata.Alternates.Add("Parts_ProjectionPart__Empty");
                 }
             });
 }
 public void Discover(ShapeTableBuilder builder) {
     foreach (var iter in _shapeAttributeOccurrences) {
         var occurrence = iter;
         var shapeType = occurrence.ShapeAttribute.ShapeType ?? occurrence.MethodInfo.Name;
         builder.Describe(shapeType)
             .From(occurrence.Feature)
             .BoundAs(
                 occurrence.MethodInfo.DeclaringType.FullName + "::" + occurrence.MethodInfo.Name,
                 descriptor => CreateDelegate(occurrence, descriptor));
     }
 }
        public void Discover(ShapeTableBuilder builder)
        {
            var availableFeatures = _extensionManager.AvailableFeatures();
            var activeFeatures = availableFeatures.Where(fd => FeatureIsTheme(fd) || FeatureIsEnabled(fd));
            var activeExtensions = Once(activeFeatures);

            foreach (var featureDescriptor in activeExtensions.SelectMany(extensionDescriptor => extensionDescriptor.Descriptor.Features.Where(fd => fd.Id == fd.Extension.Id)))
            {
                ProcessFeatureDescriptor(builder, featureDescriptor);
            }
        }
        private void ProcessFeatureDescriptor(ShapeTableBuilder builder, FeatureDescriptor featureDescriptor)
        {
            var virtualPath = _fileSystem
                .GetExtensionFileProvider(featureDescriptor.Extension, _logger)
                .GetFileInfo("Placement.info");

            var placementFile = _placementFileParser.Parse(virtualPath);
            if (placementFile != null)
            {
                ProcessPlacementFile(builder, featureDescriptor, placementFile);
            }
        }
        public void Discover(ShapeTableBuilder builder)
        {
            var availableFeatures = _extensionManager.AvailableFeatures();
            var activeFeatures = availableFeatures.Where(FeatureIsEnabled);
            var activeExtensions = Once(activeFeatures);

            var hits = activeExtensions.SelectMany(extensionDescriptor =>
            {
                var basePath = Path.Combine(extensionDescriptor.Location, extensionDescriptor.Id).Replace(Path.DirectorySeparatorChar, '/');
                var virtualPath = Path.Combine(basePath, GetFolder()).Replace(Path.DirectorySeparatorChar, '/');
                var shapes = _virtualPathProvider.ListFiles(virtualPath)
                    .Select(Path.GetFileName)
                    .Where(fileName => string.Equals(Path.GetExtension(fileName), GetFileExtension(), StringComparison.OrdinalIgnoreCase))
                    .Select(cssFileName => new
                    {
                        fileName = Path.GetFileNameWithoutExtension(cssFileName),
                        fileVirtualPath = Path.Combine(virtualPath, cssFileName).Replace(Path.DirectorySeparatorChar, '/'),
                        shapeType = GetShapePrefix() + GetAlternateShapeNameFromFileName(cssFileName),
                        extensionDescriptor
                    });
                return shapes;
            });

            foreach (var iter in hits)
            {
                var hit = iter;
                var featureDescriptors = hit.extensionDescriptor.Descriptor.Features.Where(fd => fd.Id == hit.extensionDescriptor.Id);
                foreach (var featureDescriptor in featureDescriptors)
                {
                    builder.Describe(iter.shapeType)
                        .From(new Feature { Descriptor = featureDescriptor })
                        .BoundAs(
                            hit.fileVirtualPath,
                            shapeDescriptor => displayContext =>
                            {
                                /*var shape = ((dynamic) displayContext.Value);
                                var output = displayContext.ViewContext.Writer;
                                ResourceDefinition resource = shape.Resource;
                                string condition = shape.Condition;
                                Dictionary<string, string> attributes = shape.TagAttributes;
                                ResourceManager.WriteResource(output, resource, hit.fileVirtualPath, condition, attributes);*/
                                return null;
                            });
                }
            }
        }
        private void ProcessFeatureDescriptor(ShapeTableBuilder builder, FeatureDescriptor featureDescriptor)
        {
            var virtualPath = _fileSystem
                .GetExtensionFileProvider(featureDescriptor.Extension, _logger)
                .GetFileInfo("placement.json");

            if (virtualPath.Exists)
            {
                using (var stream = virtualPath.CreateReadStream())
                {
                    using (var reader = new StreamReader(stream))
                    {
                        using (var jtr = new JsonTextReader(reader))
                        {
                            JsonSerializer serializer = new JsonSerializer();
                            var placementFile = serializer.Deserialize<PlacementFile>(jtr);
                            ProcessPlacementFile(builder, featureDescriptor, placementFile);
                        }
                    }
                }
            }
        }
        private void ProcessPlacementFile(ShapeTableBuilder builder, FeatureDescriptor featureDescriptor, PlacementFile placementFile)
        {
            var feature = new Feature { Descriptor = featureDescriptor };

            foreach (var entry in placementFile)
            {
                var shapeType = entry.Key;
                var matches = entry.Value;


                foreach (var filter in entry.Value)
                {
                    var placement = new PlacementInfo();
                    placement.Location = filter.Location;
                    placement.Alternates = filter.Alternates;
                    placement.Wrappers = filter.Wrappers;
                    placement.ShapeType = filter.ShapeType;

                    builder.Describe(shapeType)
                        .From(feature)
                        .Placement(ctx => CheckFilter(ctx, filter), placement);
                }
            }
        }
        public void Discover(ShapeTableBuilder builder)
        {
            Logger.Information("开始发现形状");

            var harvesterInfos = _harvesters.Select(harvester => new { harvester, subPaths = harvester.SubPaths() });

            var availableFeatures = _extensionManager.AvailableFeatures();
            var activeFeatures = availableFeatures.Where(FeatureIsEnabled);
            var activeExtensions = Once(activeFeatures);

            var hits = _parallelCacheContext.RunInParallel(activeExtensions, extensionDescriptor =>
            {
                Logger.Information("开始发现候选视图文件名称");
                var pathContexts = harvesterInfos.SelectMany(harvesterInfo => harvesterInfo.subPaths.Select(subPath =>
                {
                    var basePath = Path.Combine(extensionDescriptor.Location, extensionDescriptor.Id).Replace(Path.DirectorySeparatorChar, '/');
                    var virtualPath = Path.Combine(basePath, subPath).Replace(Path.DirectorySeparatorChar, '/');
                    var fileNames = _cacheManager.Get(virtualPath, ctx =>
                    {
                        if (!_virtualPathProvider.DirectoryExists(virtualPath))
                            return new string[0];

                        if (!DisableMonitoring)
                        {
                            Logger.Debug("监控虚拟路径 \"{0}\"", virtualPath);
                            ctx.Monitor(_virtualPathMonitor.WhenPathChanges(virtualPath));
                        }

                        return _virtualPathProvider.ListFiles(virtualPath).Select(Path.GetFileName).ToArray();
                    });
                    return new { harvesterInfo.harvester, basePath, subPath, virtualPath, fileNames };
                })).ToList();
                Logger.Information("发现候选视图文件名称完成");

                var fileContexts = pathContexts.SelectMany(pathContext => _shapeTemplateViewEngines.SelectMany(ve =>
                {
                    var fileNames = ve.DetectTemplateFileNames(pathContext.fileNames);
                    return fileNames.Select(
                        fileName => new
                        {
                            fileName = Path.GetFileNameWithoutExtension(fileName),
                            fileVirtualPath = Path.Combine(pathContext.virtualPath, fileName).Replace(Path.DirectorySeparatorChar, '/'),
                            pathContext
                        });
                }));

                var shapeContexts = fileContexts.SelectMany(fileContext =>
                {
                    var harvestShapeInfo = new HarvestShapeInfo
                    {
                        SubPath = fileContext.pathContext.subPath,
                        FileName = fileContext.fileName,
                        TemplateVirtualPath = fileContext.fileVirtualPath
                    };
                    var harvestShapeHits = fileContext.pathContext.harvester.HarvestShape(harvestShapeInfo);
                    return harvestShapeHits.Select(harvestShapeHit => new { harvestShapeInfo, harvestShapeHit, fileContext });
                });

                return shapeContexts.Select(shapeContext => new { extensionDescriptor, shapeContext }).ToList();
            }).SelectMany(hits2 => hits2);

            foreach (var iter in hits)
            {
                //模板总是与模块或主题的同名特征相关联
                var hit = iter;
                var featureDescriptors = iter.extensionDescriptor.Descriptor.Features.Where(fd => fd.Id == hit.extensionDescriptor.Id);
                foreach (var featureDescriptor in featureDescriptors)
                {
                    Logger.Debug("为特性 {2} 绑定 {0} 到形状 [{1}]",
                        hit.shapeContext.harvestShapeInfo.TemplateVirtualPath,
                        iter.shapeContext.harvestShapeHit.ShapeType,
                        featureDescriptor.Id);

                    builder.Describe(iter.shapeContext.harvestShapeHit.ShapeType)
                        .From(new Feature { Descriptor = featureDescriptor })
                        .BoundAs(
                            hit.shapeContext.harvestShapeInfo.TemplateVirtualPath,
                            shapeDescriptor => displayContext => Render(displayContext, hit.shapeContext.harvestShapeInfo));
                }
            }

            Logger.Information("形状发现完成。");
        }
        public void Discover(ShapeTableBuilder builder) {
            Logger.Information("Start discovering shapes");

            var harvesterInfos = _harvesters.Select(harvester => new { harvester, subPaths = harvester.SubPaths() });

            var availableFeatures = _extensionManager.AvailableFeatures();
            var activeFeatures = availableFeatures.Where(FeatureIsEnabled);
            var activeExtensions = Once(activeFeatures);

            var hits = _parallelCacheContext.RunInParallel(activeExtensions, extensionDescriptor => {
                Logger.Information("Start discovering candidate views filenames");
                var pathContexts = harvesterInfos.SelectMany(harvesterInfo => harvesterInfo.subPaths.Select(subPath => {
                    var basePath = Path.Combine(extensionDescriptor.Location, extensionDescriptor.Id).Replace(Path.DirectorySeparatorChar, '/');
                    var virtualPath = Path.Combine(basePath, subPath).Replace(Path.DirectorySeparatorChar, '/');
                    var fileNames = _cacheManager.Get(virtualPath, ctx => {
                        if (!_virtualPathProvider.DirectoryExists(virtualPath))
                            return new List<string>();

                        if (!DisableMonitoring) {
                            Logger.Debug("Monitoring virtual path \"{0}\"", virtualPath);
                            ctx.Monitor(_virtualPathMonitor.WhenPathChanges(virtualPath));
                        }

                        return _virtualPathProvider.ListFiles(virtualPath).Select(Path.GetFileName).ToReadOnlyCollection();
                    });
                    return new { harvesterInfo.harvester, basePath, subPath, virtualPath, fileNames };
                })).ToList();
                Logger.Information("Done discovering candidate views filenames");

                var fileContexts = pathContexts.SelectMany(pathContext => _shapeTemplateViewEngines.SelectMany(ve => {
                    var fileNames = ve.DetectTemplateFileNames(pathContext.fileNames);
                    return fileNames.Select(
                        fileName => new {
                            fileName = Path.GetFileNameWithoutExtension(fileName),
                            fileVirtualPath = Path.Combine(pathContext.virtualPath, fileName).Replace(Path.DirectorySeparatorChar, '/'),
                            pathContext
                        });
                }));

                var shapeContexts = fileContexts.SelectMany(fileContext => {
                    var harvestShapeInfo = new HarvestShapeInfo {
                        SubPath = fileContext.pathContext.subPath,
                        FileName = fileContext.fileName,
                        TemplateVirtualPath = fileContext.fileVirtualPath
                    };
                    var harvestShapeHits = fileContext.pathContext.harvester.HarvestShape(harvestShapeInfo);
                    return harvestShapeHits.Select(harvestShapeHit => new { harvestShapeInfo, harvestShapeHit, fileContext });
                });

                return shapeContexts.Select(shapeContext => new { extensionDescriptor, shapeContext }).ToList();
            }).SelectMany(hits2 => hits2);


            foreach (var iter in hits) {
                // templates are always associated with the namesake feature of module or theme
                var hit = iter;
                var featureDescriptors = iter.extensionDescriptor.Features.Where(fd => fd.Id == hit.extensionDescriptor.Id);
                foreach (var featureDescriptor in featureDescriptors) {                    
                    Logger.Debug("Binding {0} as shape [{1}] for feature {2}", 
                        hit.shapeContext.harvestShapeInfo.TemplateVirtualPath,
                        iter.shapeContext.harvestShapeHit.ShapeType,
                        featureDescriptor.Id);

                    builder.Describe(iter.shapeContext.harvestShapeHit.ShapeType)
                        .From(new Feature { Descriptor = featureDescriptor })
                        .BoundAs(
                            hit.shapeContext.harvestShapeInfo.TemplateVirtualPath,
                            shapeDescriptor => displayContext => Render(shapeDescriptor, displayContext, hit.shapeContext.harvestShapeInfo, hit.shapeContext.harvestShapeHit));
                }
            }

            Logger.Information("Done discovering shapes");
        }
        public void Discover(ShapeTableBuilder builder)
        {
            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Start discovering shapes");
            }

            var harvesterInfos = _harvesters
                .Select(harvester => new { harvester, subPaths = harvester.SubPaths() })
                .ToList();

            var activeFeatures = _featureManager.GetEnabledFeaturesAsync().Result.ToList();
            var activeExtensions = Once(activeFeatures).ToList();

            var matcher = new Matcher();
            foreach (var extension in _shapeTemplateViewEngines.SelectMany(x => x.TemplateFileExtensions))
            {
                matcher.AddInclude(string.Format("*.{0}", extension));
            }

            var hits = activeExtensions.Select(extensionDescriptor =>
            {
                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("Start discovering candidate views filenames");
                }

                var pathContexts = harvesterInfos.SelectMany(harvesterInfo => harvesterInfo.subPaths.Select(subPath =>
                {
                    var basePath = _fileSystem.Combine(extensionDescriptor.Location, extensionDescriptor.Id);
                    var virtualPath = _fileSystem.Combine(basePath, subPath);
                    var files = _fileSystem.ListFiles(virtualPath, matcher).ToReadOnlyCollection();

                    return new { harvesterInfo.harvester, basePath, subPath, virtualPath, files };
                })).ToList();

                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("Done discovering candidate views filenames");
                }
                var fileContexts = pathContexts.SelectMany(pathContext => _shapeTemplateViewEngines.SelectMany(ve =>
                {
                    return pathContext.files.Select(
                        file => new
                        {
                            fileName = Path.GetFileNameWithoutExtension(file.Name),
                            fileVirtualPath = "~/" + _fileSystem.Combine(pathContext.virtualPath, file.Name),
                            pathContext
                        });
                }));

                var shapeContexts = fileContexts.SelectMany(fileContext =>
                {
                    var harvestShapeInfo = new HarvestShapeInfo
                    {
                        SubPath = fileContext.pathContext.subPath,
                        FileName = fileContext.fileName,
                        TemplateVirtualPath = fileContext.fileVirtualPath
                    };
                    var harvestShapeHits = fileContext.pathContext.harvester.HarvestShape(harvestShapeInfo);
                    return harvestShapeHits.Select(harvestShapeHit => new { harvestShapeInfo, harvestShapeHit, fileContext });
                });

                return shapeContexts.Select(shapeContext => new { extensionDescriptor, shapeContext }).ToList();
            }).SelectMany(hits2 => hits2);


            foreach (var iter in hits)
            {
                // templates are always associated with the namesake feature of module or theme
                var hit = iter;
                var featureDescriptors = iter.extensionDescriptor.Features.Where(fd => fd.Id == hit.extensionDescriptor.Id);
                foreach (var featureDescriptor in featureDescriptors)
                {
                    if (_logger.IsEnabled(LogLevel.Debug))
                    {
                        _logger.LogDebug("Binding {0} as shape [{1}] for feature {2}",
                        hit.shapeContext.harvestShapeInfo.TemplateVirtualPath,
                        iter.shapeContext.harvestShapeHit.ShapeType,
                        featureDescriptor.Id);
                    }
                    builder.Describe(iter.shapeContext.harvestShapeHit.ShapeType)
                        .From(new Feature { Descriptor = featureDescriptor })
                        .BoundAs(
                            hit.shapeContext.harvestShapeInfo.TemplateVirtualPath,
                            shapeDescriptor => displayContext => RenderAsync(shapeDescriptor, displayContext, hit.shapeContext.harvestShapeInfo, hit.shapeContext.harvestShapeHit));
                }
            }

            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Done discovering shapes");
            }
        }