Esempio n. 1
0
        static void Main(string[] args)
        {
            // TestValidate();
            var callDebug =
                Chain
                .From(() => new PromptDialog.PromptString("Locale?", null, 1))
                .ContinueWith <string, Choices>(async(ctx, locale) =>
            {
                Locale = await locale;
                CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo(Locale);
                CultureInfo.CurrentCulture   = CultureInfo.CurrentUICulture;
                return(new FormDialog <Choices>(new Choices(), () =>
                {
                    var builder = new FormBuilder <Choices>();
                    builder.Configuration.DefaultPrompt.ChoiceStyle = ChoiceStyleOptions.AutoText;
                    return builder.AddRemainingFields().Build();
                }
                                                , FormOptions.PromptInStart));
            })
                .ContinueWith <Choices, object>(async(context, result) =>
            {
                Choices choices;
                try
                {
                    choices = await result;
                }
                catch (Exception error)
                {
                    await context.PostAsync(error.ToString());
                    throw;
                }

                switch (choices.Choice)
                {
                case DebugOptions.AnnotationsAndNumbers:
                    return(MakeForm(() => PizzaOrder.BuildForm()));

                case DebugOptions.AnnotationsAndNoNumbers:
                    return(MakeForm(() => PizzaOrder.BuildForm(noNumbers: true)));

                case DebugOptions.AnnotationsAndButtons:
                    return(MakeForm(() => PizzaOrder.BuildForm(style: ChoiceStyleOptions.Auto)));

                case DebugOptions.NoAnnotations:
                    return(MakeForm(() => PizzaOrder.BuildForm(noNumbers: true, ignoreAnnotations: true)));

                case DebugOptions.NoFieldOrder:
                    return(MakeForm(() => new FormBuilder <PizzaOrder>().Build()));

                case DebugOptions.WithState:
                    return(new FormDialog <PizzaOrder>(new PizzaOrder()
                    {
                        Size = SizeOptions.Large, Kind = PizzaOptions.BYOPizza
                    },
                                                       () => PizzaOrder.BuildForm(),
                                                       options: FormOptions.PromptInStart | FormOptions.PromptFieldsWithValues,
                                                       entities: new Luis.Models.EntityModel[] {
                        new Luis.Models.EntityModel("DeliveryAddress", entity: "2"),
                        new Luis.Models.EntityModel("Signature", entity: "Hawaiian"),
                        new Luis.Models.EntityModel("BYO.Toppings", entity: "onions"),
                        new Luis.Models.EntityModel("BYO.Toppings", entity: "peppers"),
                        new Luis.Models.EntityModel("BYO.Toppings", entity: "ice"),
                        new Luis.Models.EntityModel("NumberOfPizzas", entity: "5"),
                        new Luis.Models.EntityModel("NotFound", entity: "OK")
                    }
                                                       ));

                case DebugOptions.Localized:
                    {
                        var form = PizzaOrder.BuildForm();
                        using (var stream = new FileStream("pizza.resx", FileMode.Create))
                            using (var writer = new ResXResourceWriter(stream))
                            {
                                form.SaveResources(writer);
                            }
                        Process.Start(new ProcessStartInfo(@"RView.exe", "pizza.resx -c " + Locale)
                        {
                            UseShellExecute = false, CreateNoWindow = true
                        }).WaitForExit();
                        return(MakeForm(() => PizzaOrder.BuildForm(false, false, true)));
                    }

                case DebugOptions.SimpleSandwichBot:
                    return(MakeForm(() => SimpleSandwichOrder.BuildForm()));

                case DebugOptions.AnnotatedSandwichBot:
                    return(MakeForm(() => AnnotatedSandwichOrder.BuildLocalizedForm()));

                //case DebugOptions.JSONSandwichBot:
                //    return MakeForm(() => AnnotatedSandwichOrder.BuildJsonForm());
                default:
                    throw new NotImplementedException();
                }
            })
                .Do(async(context, result) =>
            {
                try
                {
                    var item = await result;
                    Debug.WriteLine(item);
                }
                catch (FormCanceledException e)
                {
                    if (e.InnerException == null)
                    {
                        await context.PostAsync($"Quit on {e.Last} step.");
                    }
                    else
                    {
                        await context.PostAsync($"Exception {e.Message} on step {e.Last}.");
                    }
                }
            })
                .DefaultIfException()
                .Loop();

            Interactive(callDebug).GetAwaiter().GetResult();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            // TestValidate();

            var callDebug =
                Chain
                .From(() => FormDialog.FromType <Choices>())
                .ContinueWith <Choices, object>(async(context, result) =>
            {
                Choices choices;
                try
                {
                    choices = await result;
                }
                catch (Exception error)
                {
                    await context.PostAsync(error.ToString());
                    throw;
                }

                switch (choices.Choice)
                {
                case DebugOptions.AnnotationsAndNumbers:
                    return(MakeForm(() => BuildForm(noNumbers: false)));

                case DebugOptions.AnnotationsAndNoNumbers:
                    return(MakeForm(() => BuildForm(noNumbers: true)));

                case DebugOptions.NoAnnotations:
                    return(MakeForm(() => BuildForm(noNumbers: true, ignoreAnnotations: true)));

                case DebugOptions.NoFieldOrder:
                    return(MakeForm(() => new FormBuilder <PizzaOrder>().Build()));

                case DebugOptions.SimpleSandwichBot:
                    return(MakeForm(() => SimpleSandwichOrder.BuildForm()));

                case DebugOptions.AnnotatedSandwichBot:
                    return(MakeForm(() => AnnotatedSandwichOrder.BuildForm()));

                default:
                    throw new NotImplementedException();
                }
            })
                .Do(async result =>
            {
                try
                {
                    var item = await result;
                    Debug.WriteLine(item);
                }
                catch (OperationCanceledException)
                {
                    Debug.WriteLine("you cancelled");
                }
            })
                .Loop();

            Interactive(callDebug);

            /*
             * var dialogs = new DialogCollection().Add(debugForm);
             * var form = AddFields(new Form<PizzaOrder>("full"), noNumbers: true);
             * Console.WriteLine("\nWith annotations and numbers\n");
             * Interactive<Form<PizzaOrder>>(AddFields(new Form<PizzaOrder>("No numbers"), noNumbers: false));
             *
             * Console.WriteLine("With annotations and no numbers");
             * Interactive<Form<PizzaOrder>>(form);
             *
             * Console.WriteLine("\nWith no annotations\n");
             * Interactive<Form<PizzaOrder>>(AddFields(new Form<PizzaOrder>("No annotations", ignoreAnnotations: true), noNumbers: false));
             *
             * Console.WriteLine("\nWith no fields.\n");
             * Interactive<Form<PizzaOrder>>(new Form<PizzaOrder>("No fields"));
             */
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            // TestValidate();
            var callDebug =
                Chain
                .From(() => FormDialog.FromType <Choices>(FormOptions.PromptInStart))
                .ContinueWith <Choices, object>(async(context, result) =>
            {
                Choices choices;
                try
                {
                    choices = await result;
                }
                catch (Exception error)
                {
                    await context.PostAsync(error.ToString());
                    throw;
                }

                switch (choices.Choice)
                {
                case DebugOptions.AnnotationsAndNumbers:
                    return(MakeForm(() => BuildForm(noNumbers: false)));

                case DebugOptions.AnnotationsAndNoNumbers:
                    return(MakeForm(() => BuildForm(noNumbers: true)));

                case DebugOptions.NoAnnotations:
                    return(MakeForm(() => BuildForm(noNumbers: true, ignoreAnnotations: true)));

                case DebugOptions.NoFieldOrder:
                    return(MakeForm(() => new FormBuilder <PizzaOrder>().Build()));

                case DebugOptions.WithState:
                    return(new FormDialog <PizzaOrder>(new PizzaOrder()
                    {
                        Size = SizeOptions.Large, DeliveryAddress = "123 State", Kind = PizzaOptions.BYOPizza
                    },
                                                       () => BuildForm(noNumbers: false), options: FormOptions.PromptInStart));

#if LOCALIZE
                case DebugOptions.Localized:
                    return(MakeForm(() => BuildForm(false, false, true)));
#endif
                case DebugOptions.SimpleSandwichBot:
                    return(MakeForm(() => SimpleSandwichOrder.BuildForm()));

                case DebugOptions.AnnotatedSandwichBot:
                    return(MakeForm(() => AnnotatedSandwichOrder.BuildForm()));

                default:
                    throw new NotImplementedException();
                }
            })
                .Do(async(context, result) =>
            {
                try
                {
                    var item = await result;
                    Debug.WriteLine(item);
                }
                catch (FormCanceledException e)
                {
                    if (e.InnerException == null)
                    {
                        await context.PostAsync($"Quit on {e.Last} step.");
                    }
                    else
                    {
                        await context.PostAsync($"Exception {e.Message} on step {e.Last}.");
                    }
                }
            })
                .Loop();

            Interactive(callDebug).GetAwaiter().GetResult();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var callJoke = Chain
                           .From(() => new FormDialog <TopChoice>(new TopChoice(), options: FormOptions.PromptInStart))
                           .ContinueWith <TopChoice, object>(async(context, result) =>
            {
                switch ((await result).Choice)
                {
                case TopChoices.Joke: return(new FormDialog <ChooseJoke>(new ChooseJoke(), options: FormOptions.PromptInStart));

                default:
                    await context.PostAsync("I don't understand");
                    return(new NullDialog <object>());
                }
            })
                           .ContinueWith <object, object>(async(context, result) =>
            {
                var choice = await result;
                if (choice is ChooseJoke)
                {
                    switch ((choice as ChooseJoke).KindOfJoke)
                    {
                    case TypeOfJoke.Funny:
                        await context.PostAsync("Something funny");
                        break;

                    case TypeOfJoke.KnockKnock:
                        await context.PostAsync("Knock-knock...");
                        break;
                    }
                }
                return(new NullDialog <object>());
            });
            // TestValidate();
            var callDebug =
                Chain
                .From(() => FormDialog.FromType <Choices>(FormOptions.PromptInStart))
                .ContinueWith <Choices, object>(async(context, result) =>
            {
                Choices choices;
                try
                {
                    choices = await result;
                }
                catch (Exception error)
                {
                    await context.PostAsync(error.ToString());
                    throw;
                }

                switch (choices.Choice)
                {
                case DebugOptions.AnnotationsAndNumbers:
                    return(MakeForm(() => BuildForm(noNumbers: false)));

                case DebugOptions.AnnotationsAndNoNumbers:
                    return(MakeForm(() => BuildForm(noNumbers: true)));

                case DebugOptions.NoAnnotations:
                    return(MakeForm(() => BuildForm(noNumbers: true, ignoreAnnotations: true)));

                case DebugOptions.NoFieldOrder:
                    return(MakeForm(() => new FormBuilder <PizzaOrder>().Build()));

                case DebugOptions.WithState:
                    return(new FormDialog <PizzaOrder>(new PizzaOrder()
                    {
                        Size = SizeOptions.Large, DeliveryAddress = "123 State", Kind = PizzaOptions.BYOPizza
                    },
                                                       () => BuildForm(noNumbers: false), options: FormOptions.PromptInStart));

                case DebugOptions.SimpleSandwichBot:
                    return(MakeForm(() => SimpleSandwichOrder.BuildForm()));

                case DebugOptions.AnnotatedSandwichBot:
                    return(MakeForm(() => AnnotatedSandwichOrder.BuildForm()));

                default:
                    throw new NotImplementedException();
                }
            })
                .Do(async result =>
            {
                try
                {
                    var item = await result;
                    Debug.WriteLine(item);
                }
                catch (OperationCanceledException)
                {
                    Debug.WriteLine("you cancelled");
                }
            })
                .Loop();

            Interactive(callDebug).GetAwaiter().GetResult();

            /*
             * var dialogs = new DialogCollection().Add(debugForm);
             * var form = AddFields(new Form<PizzaOrder>("full"), noNumbers: true);
             * Console.WriteLine("\nWith annotations and numbers\n");
             * Interactive<Form<PizzaOrder>>(AddFields(new Form<PizzaOrder>("No numbers"), noNumbers: false));
             *
             * Console.WriteLine("With annotations and no numbers");
             * Interactive<Form<PizzaOrder>>(form);
             *
             * Console.WriteLine("\nWith no annotations\n");
             * Interactive<Form<PizzaOrder>>(AddFields(new Form<PizzaOrder>("No annotations", ignoreAnnotations: true), noNumbers: false));
             *
             * Console.WriteLine("\nWith no fields.\n");
             * Interactive<Form<PizzaOrder>>(new Form<PizzaOrder>("No fields"));
             */
        }