Example #1
0
 /* Eg: give me the top sales customers */
 public static void TopResponse(ConversationContext cContext, TokenRequest p1, TokenQueryTop p2, TokenSales p3, TokenCustomers p4)
 {
     cContext.Say(CreateResponse(p3), null);
 }
Example #2
0
 /* Eg: give me the top overdue customers */
 public static void TopResponse(ConversationContext cContext, TokenWhoIs p1, TokenQueryTop p2, TokenOverdue p3, TokenCustomers p4)
 {
     cContext.Say(CreateResponse(p3), null);
 }
Example #3
0
        public override IEnumerable<TokenResult> Parse(string input, string UserId)
        {
            var tokenResults = new List<TokenResult>();
            string remainder = string.Empty;

            var results = base.Parse(input, UserId);

            if (results.Any())
            {
                tokenResults.Add(results.OrderByDescending(qty => qty.Length).First());

                int startPos = tokenResults.First().Start + tokenResults.First().Length + 1;

                if (startPos < input.Length)
                {
                    remainder = input.Substring(startPos);

                    if (remainder.Length > 0)
                    {
                        results = new TokenOverdue().Parse(remainder, UserId);
                        if (results.Any())
                        {
                            var tokenOverdue = results.OrderByDescending(token => token.Start).First();

                            tokenOverdue.Start += startPos;
                            startPos = tokenOverdue.Start + tokenOverdue.Length + 1;

                            tokenResults.Add(tokenOverdue);

                            remainder = (remainder.Length <= tokenOverdue.Length) ? string.Empty : remainder.Substring(tokenOverdue.Length + 1);

                            if (remainder.Length > 0)
                            {
                                results = new TokenCustomers().Parse(remainder, UserId);
                                if (results.Any())
                                {
                                    var tokenCust = results.OrderByDescending(token => token.Start).First();

                                    tokenCust.Start += startPos;
                                    startPos = tokenCust.Start + tokenCust.Length + 1;

                                    tokenResults.Add(tokenCust);

                                    remainder = (remainder.Length <= tokenCust.Length) ? string.Empty : remainder.Substring(tokenCust.Length + 1);
                                }
                            }
                        }
                        else
                        {
                            results = new TokenSales().Parse(remainder, UserId);

                            if (results.Any())
                            {
                                var tokenSales = results.OrderByDescending(token => token.Start).First();

                                tokenSales.Start += startPos;
                                startPos = tokenSales.Start + tokenSales.Length + 1;

                                tokenResults.Add(tokenSales);

                                remainder = (remainder.Length <= tokenSales.Length) ? string.Empty : remainder.Substring(tokenSales.Length + 1);

                                if (remainder.Length > 0)
                                {
                                    results = new TokenCustomers().Parse(remainder, UserId);
                                    if (results.Any())
                                    {
                                        var tokenCust = results.OrderByDescending(token => token.Start).First();

                                        tokenCust.Start += startPos;
                                        startPos = tokenCust.Start + tokenCust.Length + 1;

                                        tokenResults.Add(tokenCust);

                                        remainder = (remainder.Length <= tokenCust.Length) ? string.Empty : remainder.Substring(tokenCust.Length + 1);
                                    }
                                }
                            }
                        }

                        if (!string.IsNullOrEmpty(remainder))
                        {
                            tokenResults.Add(new TokenResult
                            {
                                Length = remainder.Length,
                                Start = startPos,
                                Token = new TokenQuotedPhrase { Value = remainder },
                                TokenType = typeof(TokenQuotedPhrase).ToString(),
                                Value = remainder
                            });
                        }
                    }
                }
            }

            return tokenResults;
        }