Exemple #1
0
        public WidgetProvider(
            IRazorViewEngine viewEngine,
            IRazorPageActivator pageActivator,
            ITempDataProvider tempDataProvider,
            IServiceProvider serviceProvider,
            IModelMetadataProvider modelMetadataProvider,
            IHttpContextAccessor httpContextAccessor,
            IViewComponentHelper componentHelper,
            IEnumerable <IWidgetNamedModelProvider> namedModelProviders,
            IContextAccessor <SiteContext> siteContextAccessor,
            IContextAccessor <UserContext> userContextAccessor,
            PluginContext pluginContext
            )
        {
            _viewEngine            = viewEngine;
            _pageActivator         = pageActivator;
            _tempDataProvider      = tempDataProvider;
            _serviceProvider       = serviceProvider;
            _modelMetadataProvider = modelMetadataProvider;
            _componentHelper       = componentHelper as DefaultViewComponentHelper;
            _httpContextAccessor   = httpContextAccessor;
            _siteContextAccessor   = siteContextAccessor;
            _userContextAccessor   = userContextAccessor;
            _pluginContext         = pluginContext;

            _namedModelProviders = namedModelProviders;

            Widgets = pluginContext.GetData <WidgetConfig>();
        }
Exemple #2
0
 public ContentPageTagHelper
 (
     IViewComponentHelper componentHelper,
     ContentManager contentManager
 )
 {
     _componentHelper = componentHelper as DefaultViewComponentHelper;
     _contentManager  = contentManager;
 }
 public RocketViewComponentHelper(
     DefaultViewComponentHelper defaultViewComponentHelper,
     IOptions <RocketWidgetOptions> widgetOptions,
     IPageWidgetManager pageWidgetManager)
 {
     DefaultViewComponentHelper = defaultViewComponentHelper;
     PageWidgetManager          = pageWidgetManager;
     Options = widgetOptions.Value;
 }
 public ContentEmbeddedTagHelper(
     IViewComponentHelper componentHelper,
     SiteContext siteContext,
     ConnectDbContext connectDb
     )
 {
     _componentHelper = componentHelper as DefaultViewComponentHelper;
     _siteContext     = siteContext;
     _connectDb       = connectDb;
 }
    public void GetArgumentDictionary_SupportsNullArguments()
    {
        // Arrange
        var helper     = CreateHelper();
        var descriptor = CreateDescriptorForType(typeof(ViewComponentSingleParam));

        // Act
        var argumentDictionary = DefaultViewComponentHelper.GetArgumentDictionary(descriptor, null);

        // Assert
        Assert.Equal(0, argumentDictionary.Count);
        Assert.IsType <Dictionary <string, object> >(argumentDictionary);
    }
    public void GetArgumentDictionary_SingleParameter_DoesNotNeedAnonymouslyTypedArguments()
    {
        // Arrange
        var helper     = CreateHelper();
        var descriptor = CreateDescriptorForType(typeof(ViewComponentSingleParam));

        // Act
        var argumentDictionary = DefaultViewComponentHelper.GetArgumentDictionary(descriptor, 0);

        // Assert
        Assert.Collection(argumentDictionary,
                          item =>
        {
            Assert.Equal("a", item.Key);
            Assert.IsType <int>(item.Value);
            Assert.Equal(0, item.Value);
        });
    }
    public void GetArgumentDictionary_SingleObjectParameter_DoesNotNeedAnonymouslyTypedArguments()
    {
        // Arrange
        var helper        = CreateHelper();
        var descriptor    = CreateDescriptorForType(typeof(ViewComponentObjectParam));
        var expectedValue = new object();

        // Act
        var argumentDictionary = DefaultViewComponentHelper.GetArgumentDictionary(descriptor, expectedValue);

        // Assert
        Assert.Collection(argumentDictionary,
                          item =>
        {
            Assert.Equal("o", item.Key);
            Assert.IsType <object>(item.Value);
            Assert.Same(expectedValue, item.Value);
        });
    }
        /// <summary>
        /// Render component to string
        /// </summary>
        /// <param name="componentName">Component name</param>
        /// <param name="arguments">Arguments</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the result
        /// </returns>
        protected virtual async Task <string> RenderViewComponentToStringAsync(string componentName, object arguments = null)
        {
            var helper = new DefaultViewComponentHelper(
                EngineContext.Current.Resolve <IViewComponentDescriptorCollectionProvider>(),
                HtmlEncoder.Default,
                EngineContext.Current.Resolve <IViewComponentSelector>(),
                EngineContext.Current.Resolve <IViewComponentInvokerFactory>(),
                EngineContext.Current.Resolve <IViewBufferScope>());

            using var writer = new StringWriter();
            var context = new ViewContext(ControllerContext, NullView.Instance, ViewData, TempData, writer, new HtmlHelperOptions());

            helper.Contextualize(context);
            var result = await helper.InvokeAsync(componentName, arguments);

            result.WriteTo(writer, HtmlEncoder.Default);
            await writer.FlushAsync();

            return(writer.ToString());
        }
    public async Task <string> RenderViewComponent(string viewComponent, object args)
    {
        var sp = HttpContext.RequestServices;

        var helper = new DefaultViewComponentHelper(
            sp.GetRequiredService <IViewComponentDescriptorCollectionProvider>(),
            HtmlEncoder.Default,
            sp.GetRequiredService <IViewComponentSelector>(),
            sp.GetRequiredService <IViewComponentInvokerFactory>(),
            sp.GetRequiredService <IViewBufferScope>());

        using (var writer = new StringWriter()) {
            var context = new ViewContext(ControllerContext, NullView.Instance, ViewData, TempData, writer, new HtmlHelperOptions());
            helper.Contextualize(context);
            var result = await helper.InvokeAsync(viewComponent, args);

            result.WriteTo(writer, HtmlEncoder.Default);
            await writer.FlushAsync();

            return(writer.ToString());
        }
    }
    public void GetArgumentDictionary_SingleParameter_AcceptsDictionaryType()
    {
        // Arrange
        var helper     = CreateHelper();
        var descriptor = CreateDescriptorForType(typeof(ViewComponentSingleParam));
        var arguments  = new Dictionary <string, object>
        {
            { "a", 10 }
        };

        // Act
        var argumentDictionary = DefaultViewComponentHelper.GetArgumentDictionary(descriptor, arguments);

        // Assert
        Assert.Collection(argumentDictionary,
                          item =>
        {
            Assert.Equal("a", item.Key);
            Assert.IsType <int>(item.Value);
            Assert.Equal(10, item.Value);
        });
    }
Exemple #11
0
        public static async Task <string> RenderViewComponentAsync(this Controller controller, string nombreComponent, object parametros = null)
        {
            var servicesProvider = controller.HttpContext.RequestServices;
            var helper           = new DefaultViewComponentHelper(
                servicesProvider.GetRequiredService <IViewComponentDescriptorCollectionProvider>(),
                HtmlEncoder.Default,
                servicesProvider.GetRequiredService <IViewComponentSelector>(),
                servicesProvider.GetRequiredService <IViewComponentInvokerFactory>(),
                servicesProvider.GetRequiredService <IViewBufferScope>());

            using (var writer = new StringWriter())
            {
                var context = new ViewContext(controller.ControllerContext, NullView.Instance, controller.ViewData, controller.TempData, writer, new HtmlHelperOptions());
                helper.Contextualize(context);
                var result = await helper.InvokeAsync(nombreComponent, parametros);

                result.WriteTo(writer, HtmlEncoder.Default);
                await writer.FlushAsync();

                return(writer.ToString());
            }
        }
    public void GetArgumentDictionary_MultipleParameters_NeedsAnonymouslyTypedArguments()
    {
        // Arrange
        var helper     = CreateHelper();
        var descriptor = CreateDescriptorForType(typeof(ViewComponentMultipleParam));

        // Act
        var argumentDictionary = DefaultViewComponentHelper.GetArgumentDictionary(descriptor, new { a = 0, b = "foo" });

        // Assert
        Assert.Collection(argumentDictionary,
                          item1 =>
        {
            Assert.Equal("a", item1.Key);
            Assert.IsType <int>(item1.Value);
            Assert.Equal(0, item1.Value);
        },
                          item2 =>
        {
            Assert.Equal("b", item2.Key);
            Assert.IsType <string>(item2.Value);
            Assert.Equal("foo", item2.Value);
        });
    }
Exemple #13
0
 public ContentZoneTagHelper(IViewComponentHelper componentHelper, SiteContext siteContext)
 {
     _componentHelper = componentHelper as DefaultViewComponentHelper;
     _siteContext     = siteContext;
 }
 public ContainerViewComponent(ILayoutManager layoutManager, IViewComponentHelper componentHelper)
 {
     this._layoutManager   = layoutManager;
     this._componentHelper = componentHelper as DefaultViewComponentHelper;
 }
Exemple #15
0
 public ComponentTagHelper(IViewComponentHelper componentHelper)
 {
     _componentHelper = componentHelper as DefaultViewComponentHelper;
     ComponentArgs    = new Dictionary <string, object>();
 }
 public RenderChildComponentsDataTagHelper(IViewComponentHelper componentHelper)
 {
     _componentHelper = componentHelper as DefaultViewComponentHelper;
 }
 public ContentPageToolbarTagHelper(IViewComponentHelper componentHelper)
 {
     _componentHelper = componentHelper as DefaultViewComponentHelper;
 }
Exemple #18
0
 public PoweredByTagHelper(IViewComponentHelper componentHelper)
 {
     _componentHelper = componentHelper as DefaultViewComponentHelper;
 }
Exemple #19
0
 public UserToolsTagHelper(IViewComponentHelper componentHelper, SiteContext siteContext)
 {
     _componentHelper = componentHelper as DefaultViewComponentHelper;
 }
Exemple #20
0
 public ComponentTagHelper(IViewComponentHelper componentHelper)
 {
     _componentHelper = componentHelper as DefaultViewComponentHelper;
 }
Exemple #21
0
 public SearchInputTagHelper(IViewComponentHelper componentHelper)
 {
     _componentHelper = componentHelper as DefaultViewComponentHelper;
 }