Beispiel #1
0
        static void Main()
        {
            var app = Application.Current;

            app.Use(new HtmlFromJsonProvider());
            app.Use(new PartialToStandaloneHtmlProvider());

            DummyData.Create();

            Handle.GET("/KitchenSink/master", () =>
            {
                Session session = Session.Current;
                if (session != null && session.Data != null)
                {
                    return(session.Data);
                }

                var master = new MasterPage();

                if (session == null)
                {
                    session = new Session(SessionOptions.PatchVersioning);
                }

                var nav            = new NavPage();
                master.CurrentPage = nav;

                master.Session = session;
                return(master);
            });

            Handle.GET("/KitchenSink/json", () => { return(new Json()); });

            Handle.GET("/KitchenSink/partial/mainpage", () => new MainPage());
            Handle.GET("/KitchenSink/mainpage", () => WrapPage <MainPage>("/KitchenSink/partial/mainpage"));

            Handle.GET("/KitchenSink", () => { return(Self.GET("/KitchenSink/mainpage")); });

            Handle.GET("/KitchenSink/partial/button", () => new ButtonPage());
            Handle.GET("/KitchenSink/button", () => WrapPage <ButtonPage>("/KitchenSink/partial/button"));

            Handle.GET("/KitchenSink/partial/breadcrumb",
                       () => { return(Db.Scope(() => { return new BreadcrumbPage(); })); });
            Handle.GET("/KitchenSink/breadcrumb", () => WrapPage <BreadcrumbPage>("/KitchenSink/partial/breadcrumb"));

            Handle.GET("/KitchenSink/partial/chart", () => new ChartPage());
            Handle.GET("/KitchenSink/chart", () => WrapPage <ChartPage>("/KitchenSink/partial/chart"));

            Handle.GET("/KitchenSink/partial/checkbox", () => new CheckboxPage());
            Handle.GET("/KitchenSink/checkbox", () => WrapPage <CheckboxPage>("/KitchenSink/partial/checkbox"));

            Handle.GET("/KitchenSink/partial/togglebutton", () => new ToggleButtonPage());
            Handle.GET("/KitchenSink/togglebutton",
                       () => WrapPage <ToggleButtonPage>("/KitchenSink/partial/togglebutton"));

            Handle.GET("/KitchenSink/partial/datagrid", () => new DatagridPage());
            Handle.GET("/KitchenSink/datagrid", () => WrapPage <DatagridPage>("/KitchenSink/partial/datagrid"));

            Handle.GET("/KitchenSink/partial/decimal", () => new DecimalPage());
            Handle.GET("/KitchenSink/decimal", () => WrapPage <DecimalPage>("/KitchenSink/partial/decimal"));

            Handle.GET("/KitchenSink/partial/dropdown", () => new DropdownPage());
            Handle.GET("/KitchenSink/dropdown", () => WrapPage <DropdownPage>("/KitchenSink/partial/dropdown"));

            Handle.GET("/KitchenSink/partial/html", () => new HtmlPage());
            Handle.GET("/KitchenSink/html", () => WrapPage <HtmlPage>("/KitchenSink/partial/html"));

            Handle.GET("/KitchenSink/partial/integer", () => new IntegerPage());
            Handle.GET("/KitchenSink/integer", () => WrapPage <IntegerPage>("/KitchenSink/partial/integer"));

            Handle.GET("/KitchenSink/partial/Geo", () =>
            {
                return(Db.Scope(() =>
                {
                    var geoPage = new GeoPage();
                    geoPage.Init();
                    return geoPage;
                }));
            });
            Handle.GET("/KitchenSink/Geo", () => WrapPage <GeoPage>("/KitchenSink/partial/Geo"));

            Handle.GET("/KitchenSink/partial/markdown", () => new MarkdownPage());
            Handle.GET("/KitchenSink/markdown", () => WrapPage <MarkdownPage>("/KitchenSink/partial/markdown"));

            Handle.GET("/KitchenSink/partial/nested", () => new NestedPartial
            {
                Data = new AnyData()
            });
            Handle.GET("/KitchenSink/nested", () => WrapPage <NestedPartial>("/KitchenSink/partial/nested"));

            Handle.GET("/KitchenSink/partial/radiolist", () => new RadiolistPage());
            Handle.GET("/KitchenSink/radiolist", () => WrapPage <RadiolistPage>("/KitchenSink/partial/radiolist"));

            Handle.GET("/KitchenSink/partial/multiselect", () => new MultiselectPage());
            Handle.GET("/KitchenSink/multiselect", () => WrapPage <MultiselectPage>("/KitchenSink/partial/multiselect"));

            Handle.GET("/KitchenSink/partial/password", () => new PasswordPage());
            Handle.GET("/KitchenSink/password", () => WrapPage <PasswordPage>("/KitchenSink/partial/password"));

            Handle.GET("/KitchenSink/partial/table", () => new TablePage());
            Handle.GET("/KitchenSink/table", () => WrapPage <TablePage>("/KitchenSink/partial/table"));

            Handle.GET("/KitchenSink/partial/text", () => new TextPage());
            Handle.GET("/KitchenSink/text", () => WrapPage <TextPage>("/KitchenSink/partial/text"));

            Handle.GET("/KitchenSink/partial/textarea", () => new TextareaPage());
            Handle.GET("/KitchenSink/textarea", () => WrapPage <TextareaPage>("/KitchenSink/partial/textarea"));

            Handle.GET("/KitchenSink/partial/radio", () => new RadioPage());
            Handle.GET("/KitchenSink/radio", () => WrapPage <RadioPage>("/KitchenSink/partial/radio"));

            Handle.GET("/KitchenSink/partial/Redirect", () => new RedirectPage());
            Handle.GET("/KitchenSink/Redirect", () => WrapPage <RedirectPage>("/KitchenSink/partial/Redirect"));

            Handle.GET("/KitchenSink/partial/Validation", () => new ValidationPage());
            Handle.GET("/KitchenSink/Validation", () => WrapPage <ValidationPage>("/KitchenSink/partial/Validation"));

            Handle.GET("/KitchenSink/Redirect/{?}", (string param) =>
            {
                var master            = WrapPage <RedirectPage>("/KitchenSink/partial/Redirect") as MasterPage;
                var nav               = master.CurrentPage as NavPage;
                var page              = nav.CurrentPage as RedirectPage;
                page.YourFavoriteFood = "You've got some tasty " + param;
                return(master);
            });

            Handle.GET("/KitchenSink/partial/url", () => new UrlPage());
            Handle.GET("/KitchenSink/url", () => WrapPage <UrlPage>("/KitchenSink/partial/url"));

            Handle.GET("/KitchenSink/partial/datepicker", () => new DatepickerPage());
            Handle.GET("/KitchenSink/datepicker", () => WrapPage <DatepickerPage>("/KitchenSink/partial/datepicker"));

            Handle.GET("/KitchenSink/partial/fileupload", () => new FileUploadPage());
            Handle.GET("/KitchenSink/fileupload", () => WrapPage <FileUploadPage>("/KitchenSink/partial/fileupload"));

            Handle.GET("/KitchenSink/partial/callback", () => new CallbackPage());
            Handle.GET("/KitchenSink/callback", () => WrapPage <CallbackPage>("/KitchenSink/partial/callback"));

            Handle.GET("/KitchenSink/partial/dialog", () => new DialogPage());
            Handle.GET("/KitchenSink/dialog", () => WrapPage <DialogPage>("/KitchenSink/partial/dialog"));

            Handle.GET("/KitchenSink/partial/progressbar", () => new ProgressBarPage());
            Handle.GET("/Kitchensink/progressbar", () => WrapPage <ProgressBarPage>("/KitchenSink/partial/progressbar"));

            Handle.GET("/KitchenSink/partial/lazyloading", () => new LazyLoadingPage());
            Handle.GET("/Kitchensink/lazyloading", () => WrapPage <LazyLoadingPage>("/KitchenSink/partial/lazyloading"));

            Handle.GET("/KitchenSink/partial/pagination", () => new PaginationPage());
            Handle.GET("/Kitchensink/pagination", () => WrapPage <PaginationPage>("/KitchenSink/partial/pagination"));

            Handle.GET("/KitchenSink/partial/flashmessage", () => new FlashMessagePage());
            Handle.GET("/Kitchensink/flashmessage", () => WrapPage <FlashMessagePage>("/KitchenSink/partial/flashmessage"));

            Handle.GET("/KitchenSink/partial/sortablelist", () => new SortableListPage());
            Handle.GET("/Kitchensink/sortablelist", () => WrapPage <SortableListPage>("/KitchenSink/partial/sortablelist"));

            Handle.GET("/KitchenSink/partial/cookie", (Request request) =>
            {
                string name     = "KitchenSink";
                CookiePage page = new CookiePage();
                Cookie cookie   = request.Cookies.Select(x => new Cookie(x)).FirstOrDefault(x => x.Name == name);

                if (cookie != null)
                {
                    page.RequestCookie = cookie.Value;
                }

                cookie = new Cookie()
                {
                    Name    = name,
                    Value   = string.Format("KitchenSinkCookie-{0}", DateTime.Now.ToString()),
                    Expires = DateTime.Now.AddDays(1)
                };

                Handle.AddOutgoingCookie(name, cookie.GetFullValueString());

                return(page);
            });
            Handle.GET("/KitchenSink/cookie", () => WrapPage <CookiePage>("/KitchenSink/partial/cookie"));

            HandleFile.GET("/KitchenSink/fileupload/upload", task =>
            {
                Session.ScheduleTask(task.SessionId, (s, id) =>
                {
                    MasterPage master = s.Data as MasterPage;

                    if (master == null)
                    {
                        return;
                    }

                    NavPage nav = master.CurrentPage as NavPage;

                    if (nav == null)
                    {
                        return;
                    }

                    FileUploadPage page = nav.CurrentPage as FileUploadPage;

                    if (page == null)
                    {
                        return;
                    }

                    var item = page.Tasks.FirstOrDefault(x => x.FileName == task.FileName);

                    if (task.State == HandleFile.UploadTaskState.Error)
                    {
                        if (item != null)
                        {
                            page.Tasks.Remove(item);
                        }
                    }
                    else if (task.State == HandleFile.UploadTaskState.Completed)
                    {
                        if (item != null)
                        {
                            page.Tasks.Remove(item);
                        }

                        var file = page.Files.FirstOrDefault(x => x.FileName == task.FileName);

                        if (file == null)
                        {
                            file = page.Files.Add();
                        }

                        file.FileName = task.FileName;
                        file.FileSize = task.FileSize;
                        file.FilePath = task.FilePath;
                    }
                    else
                    {
                        if (item == null)
                        {
                            item = page.Tasks.Add();
                        }

                        item.FileName = task.FileName;
                        item.FileSize = task.FileSize;
                        item.Progress = task.Progress;
                    }

                    s.CalculatePatchAndPushOnWebSocket();
                });
            });

            Handle.GET("/KitchenSink/partial/autocomplete", () => Db.Scope(() => new AutocompletePage()));
            Handle.GET("/KitchenSink/autocomplete", () => WrapPage <AutocompletePage>("/KitchenSink/partial/autocomplete"));

            //for a launcher
            Handle.GET("/KitchenSink/app-name", () => { return(new AppName()); });

            Handle.GET("/KitchenSink/menu", () => { return(new AppMenuPage()); });

            UriMapping.Map("/KitchenSink/menu", UriMapping.MappingUriPrefix + "/menu");
            UriMapping.Map("/KitchenSink/app-name", UriMapping.MappingUriPrefix + "/app-name");
        }
Beispiel #2
0
        static void Main()
        {
            Handle.GET("/KitchenSink/standalone", () => {
                Session session = Session.Current;

                if (session != null && session.Data != null)
                {
                    return(session.Data);
                }

                var standalone = new StandalonePage();

                if (session == null)
                {
                    session         = new Session(SessionOptions.PatchVersioning);
                    standalone.Html = "/KitchenSink/StandalonePage.html";
                }
                else
                {
                    standalone.Html = "/KitchenSink/LauncherWrapperPage.html";
                }

                var nav = new NavPage();
                standalone.CurrentPage = nav;

                standalone.Session = session;
                return(standalone);
            });

            Handle.GET("/KitchenSink", () => {
                return(Self.GET("/KitchenSink/text"));
            });

            Handle.GET("/KitchenSink/button", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is ButtonPage))
                {
                    var page = new ButtonPage();
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/chart", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is ChartPage))
                {
                    var page = new ChartPage();

                    page.AddChartData("January", 4);
                    page.AddChartData("February", 7);
                    page.AddChartData("March", 9);
                    page.AddChartData("April", 12);
                    page.AddChartData("May", 15);
                    page.AddChartData("June", 19);

                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/checkbox", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is CheckboxPage))
                {
                    var page = new CheckboxPage();
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/datagrid", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is DatagridPage))
                {
                    var page = new DatagridPage();

                    DatagridPagePetsElementJson pet;
                    pet      = page.Pets.Add();
                    pet.Name = "Rocky";
                    pet.Kind = "Dog";

                    pet      = page.Pets.Add();
                    pet.Name = "Tigger";
                    pet.Kind = "Cat";

                    pet      = page.Pets.Add();
                    pet.Name = "Bella";
                    pet.Kind = "Rabbit";

                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/decimal", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is DecimalPage))
                {
                    var page   = new DecimalPage();
                    page.Price = 10;
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/dropdown", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is DropdownPage))
                {
                    var page = new DropdownPage();

                    DropdownPage.PetsElementJson pet;
                    pet       = page.Pets.Add();
                    pet.Label = "dogs";

                    pet       = page.Pets.Add();
                    pet.Label = "cats";

                    pet       = page.Pets.Add();
                    pet.Label = "rabbit";

                    page.SelectedPet = "dogs";

                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/html", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is HtmlPage))
                {
                    var page = new HtmlPage();
                    page.Bio = @"<h1>This is a markup text</h1>

You can put <strong>any</strong> <a href=""https://en.wikipedia.org/wiki/HTML"">HTML</a> in it.";
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/integer", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is IntegerPage))
                {
                    var page = new IntegerPage();
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/Geo", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is MapPage))
                {
                    var page = new MapPage();
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/markdown", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is MarkdownPage))
                {
                    var page = new MarkdownPage();
                    page.Bio = @"# This is a strucured text

It supports **markdown** *syntax*.";
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/radiolist", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is RadiolistPage))
                {
                    var page = new RadiolistPage();
                    MenuOptionsElement a;
                    a       = page.MenuOptions.Add();
                    a.Label = "Dogs";
                    a       = page.MenuOptions.Add();
                    a.Label = "Cats";
                    page.SelectOption(0);
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/multiselect", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is MultiselectPage))
                {
                    var page = new MultiselectPage()
                    {
                        Data = null
                    };
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/password", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is PasswordPage))
                {
                    var page = new PasswordPage();
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/table", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is TablePage))
                {
                    var page = new TablePage();

                    TablePage.PetsElementJson pet;
                    pet      = page.Pets.Add();
                    pet.Name = "Rocky";
                    pet.Kind = "Dog";

                    pet      = page.Pets.Add();
                    pet.Name = "Tigger";
                    pet.Kind = "Cat";

                    pet      = page.Pets.Add();
                    pet.Name = "Bella";
                    pet.Kind = "Rabbit";

                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/text", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is TextPage))
                {
                    var page = new TextPage();
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/textarea", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is TextareaPage))
                {
                    var page = new TextareaPage();
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/radio", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is RadioPage))
                {
                    var page = new RadioPage();

                    RadioPage.PetsElementJson pet;
                    pet       = page.Pets.Add();
                    pet.Label = "dogs";

                    pet       = page.Pets.Add();
                    pet.Label = "cats";

                    pet       = page.Pets.Add();
                    pet.Label = "rabbit";

                    page.SelectedPet = "dogs";

                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            Handle.GET("/KitchenSink/url", () => {
                var master = (StandalonePage)Self.GET("/KitchenSink/standalone");
                if (!((master.CurrentPage as NavPage).CurrentPage is UrlPage))
                {
                    var page   = new UrlPage();
                    page.Url   = "/KitchenSink";
                    page.Label = "Go to home page";
                    (master.CurrentPage as NavPage).CurrentPage = page;
                }
                return(master);
            });

            //for a launcher
            Handle.GET("/KitchenSink/app-name", () => {
                return(new AppName());
            });

            Handle.GET("/KitchenSink/menu", () => {
                return(new Page()
                {
                    Html = "/KitchenSink/AppMenuPage.html"
                });
            });

            UriMapping.Map("/KitchenSink/menu", UriMapping.MappingUriPrefix + "/menu");
            UriMapping.Map("/KitchenSink/app-name", UriMapping.MappingUriPrefix + "/app-name");
        }