예제 #1
0
        public async Task <IHtmlContent> InvokeAsync(ViewDisplayContext displayContext)
        {
            // Apply view & model alterations
            if (displayContext.ViewAdapterResults != null)
            {
                foreach (var viewAdapterResult in displayContext.ViewAdapterResults)
                {
                    // Apply view alterations
                    var viewAlterations = viewAdapterResult.ViewAlterations;
                    if (viewAlterations.Count > 0)
                    {
                        foreach (var alteration in viewAlterations)
                        {
                            displayContext.ViewDescriptor.View.ViewName = alteration;
                        }
                    }

                    // Apply model alterations
                    var modelAlterations = viewAdapterResult.ModelAlterations;
                    if (modelAlterations.Count > 0)
                    {
                        foreach (var alteration in modelAlterations)
                        {
                            var model = await alteration(displayContext.ViewDescriptor.View.Model);

                            if (model != null)
                            {
                                displayContext.ViewDescriptor.View.Model = model;
                            }
                        }
                    }
                }
            }

            // Add descriptor
            var descriptor = _viewDescriptors.Add(displayContext.ViewDescriptor);

            // Invoke view
            var htmlContent = await _viewInvoker
                              .Contextualize(displayContext.ViewContext)
                              .InvokeAsync(descriptor.View);

            // Apply output alterations
            if (displayContext.ViewAdapterResults != null)
            {
                foreach (var viewAdapterResult in displayContext.ViewAdapterResults)
                {
                    var alterations = viewAdapterResult.OutputAlterations;
                    if (alterations.Count > 0)
                    {
                        foreach (var alteration in alterations)
                        {
                            htmlContent = alteration(htmlContent);
                        }
                    }
                }
            }

            return(htmlContent);
        }
예제 #2
0
파일: ViewFactory.cs 프로젝트: turenc/Plato
        public async Task <IHtmlContent> InvokeAsync(ViewDisplayContext displayContext)
        {
            // Contextualize view invoker
            _viewInvoker.Contextualize(displayContext);

            // Apply view & model alterations
            if (displayContext.ViewAdaptorResults != null)
            {
                foreach (var viewAdapterResult in displayContext.ViewAdaptorResults)
                {
                    var updatedView = displayContext.ViewDescriptor.View;

                    // Apply view alterations
                    var viewAlterations = viewAdapterResult.ViewAlterations;
                    if (viewAlterations.Count > 0)
                    {
                        foreach (var alteration in viewAlterations)
                        {
                            updatedView.ViewName = alteration;
                        }
                    }

                    // Apply model alterations
                    var modelAlterations = viewAdapterResult.ModelAlterations;
                    if (modelAlterations.Count > 0)
                    {
                        foreach (var alteration in modelAlterations)
                        {
                            updatedView.Model = alteration(updatedView.Model);
                        }
                    }

                    displayContext.ViewDescriptor.View = updatedView;
                }
            }

            // Invoke generic view
            var htmlContent = await _viewInvoker.InvokeAsync(displayContext.ViewDescriptor.View);

            // Apply adapter output alterations
            if (displayContext.ViewAdaptorResults != null)
            {
                foreach (var viewAdapterResult in displayContext.ViewAdaptorResults)
                {
                    var alterations = viewAdapterResult.OutputAlterations;
                    if (alterations.Count > 0)
                    {
                        foreach (var alteration in alterations)
                        {
                            htmlContent = alteration(htmlContent);
                        }
                    }
                }
            }

            return(htmlContent);
        }
예제 #3
0
파일: ViewInvoker.cs 프로젝트: turenc/Plato
        // Implementation

        public void Contextualize(ViewDisplayContext context)
        {
            ViewContext = context.ViewContext;
        }