示例#1
0
        private static async Task TestApp()
        {
            await PgletClient.ServeApp(async (page) =>
            {
                page.OnClose = (e) =>
                {
                    Console.WriteLine("Session closed");
                };

                page.OnHashChange = (e) =>
                {
                    Console.WriteLine("Hash changed: " + e.Data);
                };

                //Console.WriteLine($"Session started: {page.Connection.PipeId}");
                Console.WriteLine($"Hash: {page.Hash}");

                var txt = new TextBox();
                await page.AddAsync(txt, new Button
                {
                    Text    = "Test!",
                    OnClick = (e) =>
                    {
                        Console.WriteLine(txt.Value);
                    }
                });

                await Task.Delay(5000);

                //throw new Exception("Error!!!");

                Console.WriteLine("Session end");
            }, "page-aaa", noWindow : true);
        }
示例#2
0
        private static Task TestApp1(CancellationToken cancellationToken)
        {
            return(PgletClient.ServeApp(async(page) =>
            {
                Console.WriteLine("Session start");
                //var mainStack = new Stack
                //{
                //    Controls =
                //    {
                //        new Text { Value = page.SessionId }
                //    }
                //};

                //await page.AddAsync(mainStack);

                //for(int i = 0; i < 10; i++)
                //{
                //    await page.AddAsync(new Text { Value = i.ToString() });
                //}

                var txtName = new TextBox();
                var submitBtn = new Button {
                    Text = "Click me!", Primary = true, OnClick = (e) => { Console.WriteLine($"click: {txtName.Value}"); }
                };
                await page.AddAsync(txtName, submitBtn);

                Console.WriteLine("Session end");
            }, "index3", web: false, cancellationToken: cancellationToken));
        }
示例#3
0
        private static async Task TestPage1()
        {
            var cts = new CancellationTokenSource();

            var page = await PgletClient.ConnectPage("page-2", serverUrl : "http://localhost:5000", cancellationToken : cts.Token);

            await page.CleanAsync();

            var mainStack = new Stack
            {
                Controls =
                {
                    new Text {
                        Value = "Line 1"
                    }
                }
            };

            await page.AddAsync(mainStack);

            mainStack.Controls.Add(new Text {
                Value = "Line 2"
            });
            //mainStack.Controls.RemoveAt(0);
            mainStack.Controls.Insert(0, new Text {
                Value = "Line 0"
            });

            await page.UpdateAsync();

            ////Console.ReadLine();
            await Task.Delay(200000);
        }
示例#4
0
        private static Task TestLines1(CancellationToken cancellationToken)
        {
            return(PgletClient.ServeApp(async(page) =>
            {
                Console.WriteLine("Session start");

                var txt = new Text {
                    Value = "Line 1"
                };
                await page.AddAsync(txt);
                await Task.Delay(5000);

                var txt1 = new Text {
                    Value = "Line 0"
                };
                await page.InsertAsync(0, txt1);
                await Task.Delay(5000);

                page.Controls.Add(new Text {
                    Value = "Line 3"
                });
                page.Controls.RemoveAt(1);
                await page.UpdateAsync();

                Console.WriteLine("Session end");
            }, web: false, cancellationToken: cancellationToken));
        }
示例#5
0
        private static Task TestApp()
        {
            return(PgletClient.ServeApp(async(page) =>
            {
                page.OnClose = (e) =>
                {
                    Console.WriteLine("Session closed");
                };

                page.OnHashChange = (e) =>
                {
                    Console.WriteLine("Hash changed: " + e.Data);
                };

                //Console.WriteLine($"Session started: {page.Connection.PipeId}");
                Console.WriteLine($"Hash: {page.Hash}");

                var txt = new TextBox();
                await page.AddAsync(txt, new Button
                {
                    Text = "Test!",
                    OnClick = async(e) =>
                    {
                        await page.CleanAsync();
                        Console.WriteLine(txt.Value);
                    }
                });

                await Task.Delay(5000);
                Console.WriteLine("Session end");
            }, "index", noWindow: true));
        }
示例#6
0
 static async Task Main()
 {
     await PgletClient.ServeApp(async (page) =>
     {
         await page.AddAsync(
             new Text {
             Value = "Standard button", Size = TextSize.Large
         },
             new Stack
         {
             Horizontal = true,
             Controls   =
             {
                 new Button {
                     Text = "Standard", OnClick = (e) =>
                     {
                         Console.WriteLine("Button clicked!");
                     }
                 },
                 new Button {
                     Text = "Standard disabled", Disabled = true
                 }
             }
         },
             new Text {
             Value = "Primary button", Size = TextSize.Large
         },
             new Stack
         {
             Horizontal = true,
             Controls   =
             {
                 new Button {
                     Primary = true, Text = "Primary"
                 },
                 new Button {
                     Primary = true, Text = "Primary disabled", Disabled = true
                 }
             }
         },
             new Text {
             Value = "Compound button", Size = TextSize.Large
         },
             new Stack
         {
             Horizontal = true,
             Controls   =
             {
                 new Button {
                     Compound = true, Text = "Compound", SecondaryText = "This is a secondary text"
                 },
                 new Button {
                     Compound = true, Primary = true, Text = "Primary Compound", SecondaryText = "This is a secondary text"
                 }
             }
         });
     }, "csharp-buttons");
 }
        protected override void ProcessRecord()
        {
            var page = PgletClient.ConnectPage(pageName: Name, web: Web.ToBool(), noWindow: NoWindow.ToBool(),
                                               serverUrl: Server, token: Token, permissions: Permissions,
                                               createPage: (conn, pageUrl, pageName, sessionId) =>
                                               new PsPage(conn, pageUrl, pageName, sessionId, this)).GetAwaiter().GetResult();

            SessionState.PSVariable.Set(new PSVariable(Constants.PGLET_PAGE, page, ScopedItemOptions.Private));
            WriteObject(page);
        }
示例#8
0
        private static async Task TestPage2()
        {
            var cts = new CancellationTokenSource();

            var page = await PgletClient.ConnectPage("page-1", serverUrl : "http://localhost:5000", cancellationToken : cts.Token);

            await page.CleanAsync();

            var txtName = new TextBox();

            var submitBtn = new Button {
                Text = "Click me!", Primary = true, OnClick = (e) => { Console.WriteLine($"click: {txtName.Value}"); }
            };
            var cancelBtn = new Button {
                Text = "Cancel", OnClick = (e) => { Console.WriteLine("click cancel"); }
            };

            var mainStack = new Stack
            {
                Controls =
                {
                    new TextBox(),
                    new Stack
                    {
                        Horizontal = true,
                        Controls   =
                        {
                            submitBtn,
                            cancelBtn
                        }
                    }
                }
            };

            await page.AddAsync(mainStack);

            await Task.Delay(5000);

            submitBtn.Text = "Send something!";
            mainStack.Controls.Add(new Text {
                Value = "Oh, well..."
            });
            mainStack.Controls.RemoveAt(0);

            mainStack.Controls.Insert(0, txtName);
            await page.UpdateAsync();


            //await Task.Delay(200000);
        }
示例#9
0
        private static async Task TestApp2()
        {
            var cts = new CancellationTokenSource();

            await PgletClient.ServeApp(async (page) =>
            {
                var txtName   = new TextBox();
                var submitBtn = new Button {
                    Text = "Click me!", Primary = true, OnClick = (e) => { Console.WriteLine($"click: {txtName.Value}"); }
                };
                await page.AddAsync(txtName, submitBtn);
            }, "app-1", serverUrl : "http://localhost:5000", cancellationToken : cts.Token);

            //Console.ReadLine();
            await Task.Delay(200000);
        }
示例#10
0
 static async Task Main()
 {
     await PgletClient.ServeApp(async (page) =>
     {
         await page.AddAsync(
             new Text {
             Value = "Vertical stack", Size = TextSize.Large
         },
             new Stack
         {
             Controls =
             {
                 new Text {
                     Value = "Text 1"
                 },
                 new Text {
                     Value = "Text 2"
                 }
             }
         },
             new Text {
             Value = "Horizontal stack", Size = TextSize.Large
         },
             new Stack
         {
             Horizontal = true,
             Controls   =
             {
                 new Text {
                     Value = "Text 1"
                 },
                 new Text {
                     Value = "Text 2"
                 }
             }
         });
     }, "csharp-stack");
 }
示例#11
0
        private static async Task TestControls()
        {
            Page page = await PgletClient.ConnectPage("controls-1", serverUrl : "http://localhost:5000", noWindow : true);

            await page.CleanAsync();

            page.Title           = "Example 1";
            page.HorizontalAlign = Align.Start;
            await page.UpdateAsync();

            //page.ThemePrimaryColor = "";
            //page.ThemeTextColor = "";
            //page.ThemeBackgroundColor = "";

            var firstName = new TextBox {
                Label = "First name"
            };
            var lastName = new TextBox {
                Label = "Last name"
            };
            var notes = new TextBox {
                Label = "Notes", Multiline = true, Visible = false
            };

            var vaccinated = new Checkbox
            {
                Label    = "Vaccinated",
                OnChange = async(e) =>
                {
                    Console.WriteLine("vaccinated changed: " + e.Data);
                    notes.Visible = (e.Control as Checkbox).Value;
                    await page.UpdateAsync();
                }
            };

            var testBtn = new Button
            {
                Text    = "Test!",
                OnClick = async(e) =>
                {
                    Console.WriteLine("clicked!");
                    Console.WriteLine($"First name: {firstName.Value}");
                    Console.WriteLine($"Last name: {lastName.Value}");
                    Console.WriteLine($"Vaccinated: {vaccinated.Value}");
                    Console.WriteLine($"Notes name: {notes.Value}");

                    firstName.Value = "";
                    lastName.Value  = "";
                    await page.UpdateAsync();

                    await Task.Delay(5000);

                    Console.WriteLine("done!");
                }
            };

            var stack = new Stack
            {
                Horizontal      = true,
                HorizontalAlign = Align.SpaceBetween,
                Controls        =
                {
                    new Icon {
                        Name = "Shop", Color = "orange"
                    },
                    new Icon {
                        Name = "DependencyAdd", Color = "green"
                    }
                }
            };

            // 1st render
            await page.AddAsync(
                stack,
                firstName,
                lastName,
                vaccinated,
                notes,
                testBtn);

            stack.Margin = "10";
            stack.Controls.Add(new Icon {
                Name = "Edit", Color = "red"
            });
            stack.Controls.RemoveAt(0);

            // button with menu
            page.Controls.Add(new Button
            {
                Split     = true,
                Text      = "Button with menu",
                OnClick   = (e) => { Console.WriteLine("Button click!"); },
                MenuItems =
                {
                    new MenuItem
                    {
                        Text    = "Item 1",
                        OnClick = (e) =>{ Console.WriteLine("Menu item click!");                      }
                    },
                    new MenuItem
                    {
                        Text         = "Sub menu",
                        SubMenuItems =
                        {
                            new MenuItem
                            {
                                Text    = "Sub menu item 1",
                                OnClick = (e) =>{ Console.WriteLine("Sub menu 1 item click!");                },
                            },
                            new MenuItem
                            {
                                Text    = "Sub menu item 2",
                                OnClick = (e) =>{ Console.WriteLine("Sub menu 2 item click!");                },
                            }
                        }
                    }
                }
            });

            // checkbox
            page.Controls.Add(new Checkbox
            {
                Label   = "Check it, check it, check it",
                BoxSide = BoxSide.End,
                Value   = true
            });

            // dialog
            var dlg = new Dialog
            {
                Title    = "Title 1",
                SubText  = "Sub Text",
                Controls =
                {
                    new Text {
                        Value = "Body text"
                    }
                },
                FooterControls =
                {
                    new Button {
                        Text = "OK"
                    },
                    new Button {
                        Text = "Cancel"
                    }
                }
            };

            page.Controls.Add(dlg);
            page.Controls.Add(new Button
            {
                Text    = "Show dialog",
                OnClick = async(e) =>
                {
                    dlg.Open = true;
                    await page.UpdateAsync();
                }
            });

            // 2nd update
            await page.UpdateAsync();


            // BarChart
            stack.Controls.Add(new BarChart
            {
                DataMode = BarChartDataMode.Percentage,
                Points   =
                {
                    new BarChartDataPoint {
                        X = 10, Y = 20, Color = "Yellow", Legend = "Disk C:"
                    },
                    new BarChartDataPoint {
                        X = 10, Y = 100, Color = "Green", Legend = "Disk D:"
                    }
                }
            });
            await stack.UpdateAsync();
        }
示例#12
0
        private static async Task TestGrid()
        {
            await PgletClient.ServeApp(async (page) =>
            {
                var p1 = new Person {
                    FirstName = "John", LastName = "Smith", Age = 30, Employee = true
                };
                var p2 = new Person {
                    FirstName = "Samantha", LastName = "Fox", Age = 43, Employee = false
                };
                var p3 = new Person {
                    FirstName = "Alice", LastName = "Brown", Age = 25, Employee = true
                };

                var grid = new Grid
                {
                    PreserveSelection = true,
                    SelectionMode     = GridSelectionMode.Multiple,
                    OnSelect          = (e) =>
                    {
                        Console.WriteLine(e.Data);
                        foreach (var item in (e.Control as Grid).SelectedItems)
                        {
                            Console.WriteLine(item);
                        }
                    },
                    Columns =
                    {
                        new GridColumn
                        {
                            Name             = "Employee",
                            FieldName        = "Employee",
                            MaxWidth         = 100,
                            TemplateControls =
                            {
                                new Checkbox {
                                    ValueField = "Employee"
                                }
                            }
                        },
                        new GridColumn
                        {
                            Name             = "First name",
                            FieldName        = "FirstName",
                            TemplateControls =
                            {
                                new TextBox  {
                                    Value = "{FirstName}"
                                }
                            }
                        },
                        new GridColumn       {
                            Name = "Last name", FieldName = "LastName"
                        },
                        new GridColumn       {
                            Name = "Age", FieldName = "Age"
                        }
                    },
                    Items =
                    {
                        p1, p2, p3
                    }
                };

                int n            = 1;
                var btnAddRecord = new Button
                {
                    Text    = "Add record",
                    OnClick = async(e) =>
                    {
                        grid.Items.RemoveAt(0);
                        grid.Items.Add(new Person
                        {
                            FirstName = $"First {n}",
                            LastName  = $"Last {n}",
                            Age       = n
                        });
                        await grid.UpdateAsync();
                        n++;
                    }
                };

                var btnShowRecords = new Button
                {
                    Text    = "Show records",
                    OnClick = (e) =>
                    {
                        (grid.Items[0] as Person).Age = 22;
                        foreach (var p in grid.Items)
                        {
                            Console.WriteLine(p);
                        }
                    }
                };

                await page.AddAsync(grid, btnAddRecord, btnShowRecords);
            }, "grid-1");
        }