Exemplo n.º 1
0
        private void login(CommandStack stack)
        {
            var u = options.UserName;
            var p = options.Password;

            if (u.IsNullOrWhiteSpace() && stack.Any())
            {
                u = stack.Pop();
            }
            else
            {
                txtOut.WriteLine("User: "******"Enter password: "******"Login for " + u + " " + (result ? " success" : "failed"));
            }
            catch (Exception ex)
            {
                txtOut.WriteLine("Login failed");
            }
        }
Exemplo n.º 2
0
        private void login(CommandStack stack)
        {
            var userName = options.UserName;
            var passWord = options.Password;

            if (userName.IsNullOrWhiteSpace())
            {
                if (stack.Any())
                {
                    userName = stack.Pop();
                }
                else
                {
                    txtOut.WriteLine("User: "******"Enter password: "******"Login for {userName}  {(result ? " success" : "failed")}");
            }
            catch (Exception)
            {
                txtOut.WriteLine("Login failed");
            }
        }
Exemplo n.º 3
0
        public SASQuery Parse(string input)
        {
            var      splitChars = new[] { ' ', ',', '-' };
            var      stack      = new CommandStack(input, splitChars);
            SASQuery request    = null;

            if (stack.Count > 2)
            {
                request      = new SASQuery();
                request.From = stack.Pop().ToUpper();
                if (airportExp.IsMatch(stack.Peek()))
                {
                    request.To = stack.Pop().ToUpper();
                    if (airportExp.IsMatch(stack.Peek()))
                    {
                        request.ReturnFrom = stack.Pop().ToUpper();
                        if (airportExp.IsMatch(stack.Peek()))
                        {
                            //req.ReturnTo = stack.Pop().ToUpper();
                            var tmp = stack.Pop().ToUpper();
                            if (tmp != request.From)
                            {
                                throw new ParserException("Must return to origin");
                            }
                        }
                    }
                }
                request.OutDate = parseDate(stack.Pop(), DateTime.Now.Date);
                if (stack.Any())
                {
                    request.InDate = parseDate(stack.Pop(), request.OutDate.Value);
                }
            }
            else
            {
                throw new ParserException("Too few arguments");
            }
            return(request);
        }
Exemplo n.º 4
0
        private void history(CommandStack stack, bool export)
        {
            int  n                 = 1;
            int  pages             = 1;
            bool fetchAll          = true;
            List <Transaction> all = new List <Transaction>();
            TransactionRoot    res = null;

            if (stack.Any())
            {
                if (int.TryParse(stack.Pop(), out n) && !stack.Any())
                {
                    fetchAll = false;
                }
                else
                {
                    txtOut.WriteLine("Parser error");
                    return;
                }
            }
            txtOut.WriteLine("");
            do
            {
                txtOut.Write("\rFetching page " + n + (pages > 1 ? " of " + pages.ToString() : ""));
                try
                {
                    res = client.History(n);
                }
                catch (Exception ex)
                {
                    txtOut.WriteLine("Error getting page " + n);
                    txtOut.WriteLine(ex.Message);
                }
                if (res.errors != null)
                {
                    txtOut.WriteLine("Error getting page " + n + " " + res.errors.First().errorMessage);
                }
                n++;
                if (fetchAll)
                {
                    pages = res.eurobonus.transactionHistory.totalNumberOfPages;
                }
                if (res.errors == null && res.eurobonus != null && res.eurobonus.transactionHistory.transaction != null)
                {
                    all.AddRange(res.eurobonus.transactionHistory.transaction);
                }
            } while (n <= pages);
            txtOut.Write("\r");
            if (export)
            {
                var exporter = new FlightExporter();
                var list     = exporter.Convert(all);
                txtOut.WriteLine("Found " + list.Count + " flight");
                if (list.Any())
                {
                    try
                    {
                        exporter.SaveCSV(list);
                        txtOut.WriteLine("Files saved");
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            else
            {
                Table t = new Table();
                foreach (var r in all)
                {
                    var values = new List <string>();
                    values.Add(r.datePerformed.ToString("yyyy-MM-dd"));
                    values.Add(r.typeOfTransaction);
                    values.Add(r.basicPointsAfterTransaction);
                    values.Add(r.availablePointsAfterTransaction.ToString());
                    values.Add(r.description1 + " " + r.description2);

                    t.Rows.Add(values);
                }

                t.Alignment[3] = TextAlignment.Right;
                t.Print(txtOut);
                if (fetchAll)
                {
                    txtOut.WriteLine("Summary");
                    t = new Table();
                    foreach (var g in all.GroupBy(trans => trans.typeOfTransaction))
                    {
                        t.Rows.Add(new List <string>(new[] { g.Key, g.Sum(trans => trans.availablePointsAfterTransaction).ToString() }));
                    }
                    t.Alignment[1] = TextAlignment.Right;
                    t.Print(txtOut);
                }
            }
        }
Exemplo n.º 5
0
        bool Command(string input)
        {
            var names = Enum.GetNames(typeof(Commands));
            var stack = new CommandStack(input);

            if (stack.Any())
            {
                var sCmd = stack.Pop();
                var name = names.FirstOrDefault(s => s.Equals(sCmd, StringComparison.OrdinalIgnoreCase));
                if (name != null)
                {
                    Commands cmd = (Commands)Enum.Parse(typeof(Commands), name);
                    if (!client.LoggedIn && requiresLogin.Contains(cmd))
                    {
                        txtOut.WriteLine("This feature requires login");
                        return(true);
                    }
                    switch (cmd)
                    {
                    case Commands.Set:
                        options.Set(stack);
                        break;

                    case Commands.Info:
                        info(stack);
                        break;

                    case Commands.Login:
                        login(stack);
                        break;

                    case Commands.Export:
                        history(stack, true);
                        break;

                    case Commands.History:
                        history(stack, false);
                        break;

                    case Commands.Points:
                        points();
                        break;

                    case Commands.Benchmark:
                        benchMark();
                        break;

                    case Commands.Options:
                        txtOut.Write(options.Help() + Environment.NewLine);
                        break;

                    case Commands.Help:
                        txtOut.WriteLine("Commands:");
                        foreach (var s in names)
                        {
                            txtOut.WriteLine("\t" + s);
                        }
                        break;

                    case Commands.Logout:
                        client.Logout();
                        break;

                    case Commands.Quit:
                        client.Logout();
                        Environment.Exit(0);
                        break;
                    }
                    return(true);
                }
            }
            return(false);
        }