public static IView FindView(this ViewEngineCollection viewEngines, CommandContext commandContext, string viewName)
        {
            if (viewEngines == null || viewEngines.Count == 0)
            {
                var message =
                    string.Format("No view engines have been added, call ViewEngines.Add<>() in your Program.cs");
                throw new ViewEngineException(message);
            }

            IView result =
                (from viewEngine in viewEngines
                 select viewEngine.FindView(commandContext, viewName))
                .FirstOrDefault(view => view != null);

            if (result == null)
            {
                var message =
                    string.Format(
                        "No view found with the name '{0}'\nMake sure you set the view's Build action to 'Embedded resource'",
                        viewName);
                throw new ViewEngineException(message);
            }

            return result;
        }
Esempio n. 2
0
 private static bool TryRenderDefaultView(Assembly callingAssembly, ConsoleApp app)
 {
     try
     {
         var context = new CommandContext(callingAssembly);
         var view = app.ViewEngines.FindView(context, DefaultViewName);
         var result = view.Render<object>(null);
         Console.WriteLine(result);
         return true;
     }
     catch (ViewEngineException)
     {
     }
     return false;
 }
 public IView FindView(CommandContext commandContext, string viewName)
 {
     var text = GetView(viewName, commandContext.Assembly);
     return text != null ? CreateView(text) : null;
 }