Exemple #1
0
        /// <summary>
        /// Builds the view engine collection by applying the passed path transformations to each view engine.
        /// </summary>
        /// <param name="pathTransformations">The path transformations.</param>
        private static ViewEngineCollection BuildViewEngineCollection(IList <Func <string, string> > pathTransformations)
        {
            var viewEngines = new ViewEngineCollection();

            foreach (var globalEngine in ViewEngines.Engines)
            {
                var vppEngine = globalEngine as VirtualPathProviderViewEngine;
                var newEngine = vppEngine != null?ControllerExtensions.GetViewEngine(vppEngine, pathTransformations) : globalEngine;

                if (newEngine != null)
                {
                    viewEngines.Add(newEngine);
                }
            }

            return(viewEngines);
        }
Exemple #2
0
        private static IEnumerable <string> GetViews(Controller controller, IEnumerable <string> viewLocations, string moduleName = null)
        {
            var viewExtensions = ControllerExtensions.GetViewFileExtensions(controller);
            var widgetName     = controller.RouteData != null ? controller.RouteData.Values["widgetName"] as string : null;

            var assembly  = controller.GetType().Assembly;
            var baseFiles = ControllerExtensions.GetViewsForAssembly(assembly, viewLocations, viewExtensions, moduleName);

            if (!widgetName.IsNullOrEmpty())
            {
                var widgetAssembly = FrontendManager.ControllerFactory.ResolveControllerType(widgetName).Assembly;
                var widgetFiles    = ControllerExtensions.GetViewsForAssembly(widgetAssembly, viewLocations, viewExtensions);
                return(baseFiles.Union(widgetFiles));
            }

            return(baseFiles);
        }
        /// <summary>
        /// Gets an already cached view engine collection from the dictionary or builds a new one.
        /// </summary>
        /// <param name="controller">The controller.</param>
        /// <param name="pathTransformationsFunc">The path transformations function.</param>
        private static ViewEngineCollection GetViewEngineCollection(Controller controller, Func <IList <Func <string, string> > > pathTransformationsFunc)
        {
            var key = ControllerExtensions.GetKey(controller);

            if (!ControllerExtensions.ViewEngineCollections.ContainsKey(key))
            {
                lock (ControllerExtensions.ViewEngineCollections)
                {
                    if (!ControllerExtensions.ViewEngineCollections.ContainsKey(key))
                    {
                        var viewEngineCollection = ControllerExtensions.BuildViewEngineCollection(pathTransformationsFunc());
                        ControllerExtensions.ViewEngineCollections.Add(key, viewEngineCollection);
                    }
                }
            }

            return(ControllerExtensions.ViewEngineCollections[key]);
        }
        /// <summary>
        /// Updates the view engines collection of the given <paramref name="controller"/> by making the engines aware of the controller's container virtual path.
        /// </summary>
        /// <param name="controller">The controller.</param>
        /// <exception cref="System.ArgumentNullException">controller</exception>
        /// <param name="pathTransformations">Transformations that have to be applied to each view engine search path.</param>
        public static void UpdateViewEnginesCollection(this Controller controller, IList <Func <string, string> > pathTransformations)
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }

            var viewEngines = new ViewEngineCollection();

            foreach (var globalEngine in ViewEngines.Engines)
            {
                var vppEngine = globalEngine as VirtualPathProviderViewEngine;
                var newEngine = vppEngine != null?ControllerExtensions.GetViewEngine(vppEngine, controller, pathTransformations) : globalEngine;

                viewEngines.Add(newEngine);
            }
            controller.ViewEngineCollection = viewEngines;
        }
 /// <summary>
 /// Gets the view paths of the given controller.
 /// </summary>
 /// <param name="controller">The controller.</param>
 private static IEnumerable <string> GetViewLocations(Controller controller)
 {
     return(ControllerExtensions.GetControllerViewEngineLocations(controller, v => v.ViewLocationFormats));
 }
        internal static IEnumerable <string> GetPartialViews(this Controller controller, ref Dictionary <string, string> viewFilesMappings, string moduleName)
        {
            var viewLocations = ControllerExtensions.GetPartialViewLocations(controller);

            return(ControllerExtensions.GetViews(controller, viewLocations, ref viewFilesMappings, moduleName));
        }
 /// <summary>
 /// Gets the type of the dynamic content that is inferred for the given controller name.
 /// </summary>
 /// <param name="controllerName">Name of the controller.</param>
 /// <param name="moduleName">The name of the module. If empty or null will search all dynamic modules. Default value is null.</param>
 /// <returns>
 /// The dynamic module type.
 /// </returns>
 public static DynamicModuleType GetDynamicContentType(string controllerName, string moduleName)
 {
     return(ControllerExtensions.FindDynamicContentTypes(controllerName, moduleName).FirstOrDefault());
 }
 /// <summary>
 /// Gets the type of the dynamic content that is inferred for the given controller name.
 /// </summary>
 /// <param name="controllerName">Name of the controller.</param>
 /// <returns>
 /// The dynamic module type.
 /// </returns>
 public static DynamicModuleType GetDynamicContentType(string controllerName)
 {
     return(ControllerExtensions.GetDynamicContentType(controllerName, null));
 }
 /// <summary>
 /// Gets the partial view paths of the given controller.
 /// </summary>
 /// <param name="controller">The controller.</param>
 public static IEnumerable <string> GetPartialViewLocations(this Controller controller)
 {
     return(ControllerExtensions.GetControllerViewEngineLocations(controller, v => v.PartialViewLocationFormats));
 }
        public static IEnumerable <string> GetViews(this Controller controller, IList <string> fullViewPaths, string moduleName)
        {
            var viewLocations = ControllerExtensions.GetViewLocations(controller);

            return(ControllerExtensions.GetViews(controller, viewLocations, moduleName));
        }
 public static IEnumerable <string> GetViews(this Controller controller, IList <string> fullViewPaths = null)
 {
     return(ControllerExtensions.GetViews(controller, fullViewPaths, null));
 }
        public static IEnumerable <string> GetPartialViews(this Controller controller, IList <string> fullViewPaths = null)
        {
            var viewLocations = ControllerExtensions.GetPartialViewLocations(controller);

            return(ControllerExtensions.GetViews(controller, viewLocations));
        }
        /// <summary>
        /// Gets the views that are available to the controller.
        /// </summary>
        /// <param name="controller">The controller.</param>
        public static IEnumerable <string> GetViews(this Controller controller)
        {
            var viewLocations = ControllerExtensions.GetViewLocations(controller);

            return(ControllerExtensions.GetViews(controller, viewLocations));
        }
Exemple #14
0
        internal static IEnumerable <string> GetPartialViews(this Controller controller, ref Dictionary <string, string> viewFilesMappings, IList <string> fullViewPaths = null)
        {
            var viewLocations = ControllerExtensions.GetPartialViewLocations(controller);

            return(ControllerExtensions.GetViews(controller, viewLocations, ref viewFilesMappings));
        }