Inheritance: ConsoleApp
 public Task Start()
 {
     ConsolePageApp app = new ConsolePageApp(0, 0, ConsoleProvider.Current.BufferWidth, 25);
     app.PageStack.RegisterDefaultRoute("{*}", CreateExplorerPage);
     app.PageStack.Navigate("");
     return app.Start();
 }
Ejemplo n.º 2
0
        public static void Parse(ConsolePageApp pageApp, IEnumerable <string> markupFiles)
        {
            foreach (var markup in markupFiles)
            {
                ParserContext context = new ParserContext()
                {
                    RootElement = new XmlElement(markup),
                };

                context.CurrentElement = context.RootElement;

                if (context.RootElement.Name != "Page")
                {
                    throw new InvalidOperationException("Root element must be a page");
                }

                if (context.RootElement["Route"] == null)
                {
                    throw new InvalidOperationException("Page tag is missing Route tag");
                }

                Func <Page> pageFactory = () =>
                {
                    Type baseType = typeof(Page);
                    if (context.RootElement["BaseType"] != null)
                    {
                        baseType = FindType(context.RootElement["BaseType"], context);
                    }

                    var page = (Page)Activator.CreateInstance(baseType);

                    if (context.RootElement["ViewModelType"] != null)
                    {
                        var viewModelType = FindType(context.RootElement["ViewModelType"], context);
                        context.RootViewModel    = Activator.CreateInstance(viewModelType);
                        context.CurrentViewModel = context.RootViewModel;
                    }

                    ParsePanel(context, page);

                    return(page);
                };

                if (context.RootElement["IsDefaultRoute"] == "true")
                {
                    pageApp.PageStack.RegisterDefaultRoute(context.RootElement["Route"], pageFactory);
                }
                else
                {
                    pageApp.PageStack.RegisterRoute(context.RootElement["Route"], pageFactory);
                }
            }
        }