public ShapeAlterationBuilder BoundAs(string bindingSource, Func <ShapeDescriptor, Func <DisplayContext, Task <IHtmlContent> > > binder)
        {
            // schedule the configuration
            return(Configure(descriptor =>
            {
                Func <DisplayContext, Task <IHtmlContent> > target = null;

                var binding = new ShapeBinding
                {
                    ShapeDescriptor = descriptor,
                    BindingName = _bindingName,
                    BindingSource = bindingSource,
                    BindingAsync = displayContext =>
                    {
                        // when used, first realize the actual target once
                        if (target == null)
                        {
                            target = binder(descriptor);
                        }

                        // and execute the re
                        return target(displayContext);
                    }
                };

                // ShapeDescriptor.Bindings is a case insensitive dictionary
                descriptor.Bindings[_bindingName] = binding;
            }));
        }
        public ShapeAlterationBuilder BoundAs(string bindingSource, Func<ShapeDescriptor, Func<DisplayContext, IHtmlString>> binder) {
            // schedule the configuration
            return Configure(descriptor => {

                Func<DisplayContext, IHtmlString> target = null;

                var binding = new ShapeBinding {
                    ShapeDescriptor = descriptor,
                    BindingName = _bindingName,
                    BindingSource = bindingSource,
                    Binding = displayContext => {

                        // when used, first realize the actual target once
                        if (target == null)
                            target = binder(descriptor);

                        // and execute the re
                        return target(displayContext);
                    }
                };

                // ShapeDescriptor.Bindings is a case insensitive dictionary
                descriptor.Bindings[_bindingName] = binding;

            });
        }
        public ShapeAlterationBuilder BoundAs(string bindingSource, Func <ShapeDescriptor, Func <DisplayContext, IHtmlString> > binder)
        {
            // schedule the configuration
            return(Configure(descriptor => {
                Func <DisplayContext, IHtmlString> target = null;

                var binding = new ShapeBinding {
                    ShapeDescriptor = descriptor,
                    BindingName = _bindingName,
                    BindingSource = bindingSource,
                    Binding = displayContext => {
                        // when used, first realize the actual target once
                        if (target == null)
                        {
                            target = binder(descriptor);
                        }

                        // and execute the re
                        return target(displayContext);
                    }
                };
                var prefix = _bindingType == "Display" ? string.Empty : string.Concat(_bindingType, "@");
                // ShapeDescriptor.Bindings is a case insensitive dictionary
                descriptor.Bindings[prefix + _bindingName] = binding;
            }));
        }
        public bool TryGetDescriptorBinding(string shapeType, out ShapeBinding shapeBinding) {
            shapeBinding = null;

            if (!Enabled)
                return false;

            var currentThemeName = _siteThemeService.GetCurrentThemeName();
            var shapeTable = _shapeTableLocator.Lookup(currentThemeName);
            return shapeTable.Bindings.TryGetValue(shapeType, out shapeBinding);
        }
        public bool TryGetDescriptorBinding(string shapeType, out ShapeBinding shapeBinding) {
            var processors = BuildShapeProcessors();

            TemplateResult templateResult = null;
            if (processors.TryGetValue(shapeType, out templateResult)) {
                shapeBinding = new ShapeBinding {
                    BindingName = "Templates",
                    Binding = ctx => CoerceHtmlString(_templateService.Execute(
                        templateResult.Template, 
                        templateResult.Name,
                        templateResult.Processor, ctx.Value)),
                    ShapeDescriptor = new ShapeDescriptor { ShapeType = shapeType }
                };

                return true;
            }

            shapeBinding = null;
            return false;
        }
예제 #6
0
        private bool TryGetDescriptorBinding(string shapeType, IEnumerable<string> shapeAlternates, ShapeTable shapeTable, out ShapeBinding shapeBinding)
        {
            // shape alternates are optional, fully qualified binding names
            // the earliest added alternates have the lowest priority
            // the descriptor returned is based on the binding that is matched, so it may be an entirely
            // different descriptor if the alternate has a different base name
            foreach (var shapeAlternate in shapeAlternates.Reverse()) {

                foreach (var shapeBindingResolver in _shapeBindingResolvers) {
                    if(shapeBindingResolver.TryGetDescriptorBinding(shapeAlternate, out shapeBinding)) {
                        return true;
                    }
                }

                if (shapeTable.Bindings.TryGetValue(shapeAlternate, out shapeBinding)) {
                    return true;
                }
            }

            // when no alternates match, the shapeType is used to find the longest matching binding
            // the shapetype name can break itself into shorter fallbacks at double-underscore marks
            // so the shapetype itself may contain a longer alternate forms that falls back to a shorter one
            var shapeTypeScan = shapeType;
            for (; ; ) {
                foreach (var shapeBindingResolver in _shapeBindingResolvers) {
                    if (shapeBindingResolver.TryGetDescriptorBinding(shapeTypeScan, out shapeBinding)) {
                        return true;
                    }
                }

                if (shapeTable.Bindings.TryGetValue(shapeTypeScan, out shapeBinding)) {
                    return true;
                }

                var delimiterIndex = shapeTypeScan.LastIndexOf("__");
                if (delimiterIndex < 0) {
                    shapeBinding = null;
                    return false;
                }

                shapeTypeScan = shapeTypeScan.Substring(0, delimiterIndex);
            }
        }
예제 #7
0
 static IHtmlString Process(ShapeBinding shapeBinding, IShape shape, DisplayContext context)
 {
     if (shapeBinding == null || shapeBinding.Binding == null) {
         // todo: create result from all child shapes
         return shape.Metadata.ChildContent ?? new HtmlString("");
     }
     return CoerceHtmlString(shapeBinding.Binding(context));
 }
예제 #8
0
 static async Task<IHtmlContent> ProcessAsync(ShapeBinding shapeBinding, IShape shape, DisplayContext context)
 {
     if (shapeBinding == null || shapeBinding.BindingAsync == null)
     {
         // todo: create result from all child shapes
         return shape.Metadata.ChildContent ?? HtmlString.Empty;
     }
     return CoerceHtmlString(await shapeBinding.BindingAsync(context));
 }