예제 #1
0
        // Mètode que crearà un arbre a partir d'un fitxer i
        // ens tornarà una referència a l'arrel de l'arbre.
        public NodeDecisio BuildTree(string arxiu)
        {
            string line;

            Dictionary <int, NodeDecisio> nodes = new Dictionary <int, NodeDecisio>();
            Dictionary <int, Dictionary <string, int> > connexions = new Dictionary <int, Dictionary <string, int> >();

            System.IO.StreamReader file = new System.IO.StreamReader(arxiu);

            // Llegim el fitxer i emplenem les estructures auxiliars
            while ((line = file.ReadLine()) != null)
            {
                // Llegim l'ID del node i el processem
                int nodeId = int.Parse(new String(line.TakeWhile(Char.IsDigit).ToArray()));

                // Llegim el text que es mostrarà quan arribem al node
                line = file.ReadLine();
                var nodeActual = new NodeDecisio(nodeId, line);
                nodes.Add(nodeId, nodeActual);

                System.Console.WriteLine("Node " + nodeId);

                // Processem cada opció amb el respectiu node destí
                line = file.ReadLine();
                Console.WriteLine("Fills:");
                while (line != null && line != "#")
                {
                    string[] splitString = line.Split(" : ");
                    int      destiId     = int.Parse(splitString[1]);
                    string   opcio       = splitString[0];
                    System.Console.WriteLine(destiId);
                    if (!connexions.ContainsKey(nodeId))
                    {
                        connexions.Add(nodeId, new Dictionary <string, int>());
                    }
                    connexions[nodeId].Add(opcio, destiId);
                    line = file.ReadLine();
                }
            }

            // Ara recorrem les estructures auxiliars per emplenar els nodes.

            foreach (KeyValuePair <int, Dictionary <string, int> > node in connexions)
            {
                var nodeActual = nodes[node.Key];
                Console.WriteLine(node.Key);

                foreach (KeyValuePair <string, int> connexio in node.Value)
                {
                    var nodeDesti = nodes[connexio.Value];
                    nodeActual.fills.Add(connexio.Key, nodeDesti);
                }
            }

            return(nodes[1]);
        }
예제 #2
0
        private async Task <DialogTurnResult> DispatchStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var intent = stepContext.GetValue <string>("Intent");


            switch (intent)
            {
            case "ProductInformation":
            // TODO (ARREGLAR-HO)

            // Invoquem el mètode d'extensió que hem creat

            /*var productInfo = luisResult.ToProductInfo(Configuration);
             * if (productInfo != null)
             * {
             *  var attachment = CardUtils.CreateCardFromProductInfo(productInfo);
             *  var adaptiveCard = stepContext.Context.Activity.CreateReply();
             *
             *  adaptiveCard.Attachments = new List<Attachment>() { attachment };
             *  await stepContext.Context.SendActivityAsync(adaptiveCard, cancellationToken);
             * }
             * else
             * {
             *  await stepContext.Context.SendActivityAsync(MessageFactory.Text("Sorry, we couldn't find a product matching your requirements."), cancellationToken);
             * }
             * break;*/

            case "OrderProduct":
                var recognizer = stepContext.Result as RecognizerResult ?? null;
                // Invoquem el mètode d'extensió per extreure una comanda del json.
                return(await stepContext.BeginDialogAsync(nameof(OrderProductDialog), recognizer, cancellationToken));

            case "TechnicalAssistance":
                NodeConstructor nbuilder = new NodeConstructor();
                NodeDecisio     arrel    = nbuilder.BuildTree("ExempleArbre.txt");

                return(await stepContext.BeginDialogAsync(nameof(TechnicalAssistanceDialog), arrel, cancellationToken));

            case "ConfirmCart":
                return(await stepContext.BeginDialogAsync(nameof(ConfirmOrderDialog), null, cancellationToken));

            case "AddProductInfo":
                return(await stepContext.BeginDialogAsync(nameof(AddProductInfoDialog), null, cancellationToken));

            case "CheckProducts":
                var task = DisplayAllProductsAsync(stepContext, cancellationToken);

                await stepContext.Context.SendActivityAsync("Wait till I load them all...");

                await task;
                break;

            case "Register":
                var ps = new ProcessStartInfo("https://vitrosepstore.com/en/login?create_account=1")
                {
                    UseShellExecute = true,
                    Verb            = "open"
                };
                Process.Start(ps);
                break;

            case "AskValidation":
                var botId = stepContext.Context.Activity.From.Id;
                var user  = await UserController.GetUserByBotIdAsync(botId);

                if (user != null && user.PrestashopId != null)
                {
                    await NotifyController.RequestValidationAsync(botId);

                    await stepContext.Context.SendActivityAsync("I sent a validation request to a member of our staff");
                }
                else
                {
                    await stepContext.Context.SendActivityAsync("You're not logged in! In order to ask for validation " +
                                                                "you have to log in first (just ask me *I want to log in*), and if you're not registered yet " +
                                                                "ask me to register (*I want to register*) and then log in.\n You can request the validation right after :)");
                }
                break;

            case "ValidateUser":
                return(await stepContext.BeginDialogAsync(nameof(UserValidationDialog), null, cancellationToken));

            case "CartToOrder":


            case "QnA":
                var answer = (string)stepContext.Result;
                await stepContext.Context.SendActivityAsync(MessageFactory.Text(answer), cancellationToken);

                break;
            }

            return(await stepContext.NextAsync(null, cancellationToken));
        }