Esempio 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");
            }
        }
Esempio n. 2
0
 private void info(CommandStack stack)
 {
     if (stack.Any())
     {
         var arglist = stack.ToList();
         var s       = string.Join(" ", arglist);
         var airport = data.Airports.FirstOrDefault(ap => ap.IATA == s.ToUpper());
         if (airport != null)
         {
             txtOut.WriteLine("Airport " + airport.IATA + "/" + airport.ICAO);
             txtOut.WriteLine("Name " + airport.Name);
             txtOut.WriteLine("City " + airport.City);
             txtOut.WriteLine("Country " + airport.Country);
             txtOut.WriteLine("Type " + airport.Type);
             txtOut.WriteLine("Timezone " + airport.Timezone);
             txtOut.WriteLine("DST " + airport.DST);
         }
         var cities = data.Airports.Where(ap => s.Equals(ap.City, StringComparison.OrdinalIgnoreCase)).ToList();
         if (cities.Any())
         {
             txtOut.WriteLine("Airports in " + s);
             foreach (var c in cities)
             {
                 txtOut.WriteLine("\t" + c.IATA + ": " + c.Name);
             }
         }
         var airline = data.Airlines.FirstOrDefault(al => s.Equals(al.Name, StringComparison.OrdinalIgnoreCase) || s.ToUpper() == al.IATA || s.ToUpper() == al.ICAO);
         if (airline != null)
         {
             txtOut.WriteLine("Airline info for " + s);
             txtOut.WriteLine("\t" + airline.IATA + "/" + airline.ICAO);
             txtOut.WriteLine("\tName:" + airline.Name);
             txtOut.WriteLine("\tCallsign:" + airline.Callsign);
             txtOut.WriteLine("\tCountry:" + airline.Country);
         }
         var plane = data.Planes.FirstOrDefault(p => s.ToUpper() == p.IATA || s.ToUpper() == p.ICAO);
         if (plane != null)
         {
             txtOut.WriteLine("Airplane info for " + s);
             txtOut.WriteLine("\t" + plane.IATA + "/" + plane.ICAO);
             txtOut.WriteLine("\tName:" + plane.Name);
         }
         if (arglist.Count >= 2)
         {
             var orig      = arglist[0];
             var dest      = arglist[1] == "-" && arglist.Count > 2 ? arglist[2] : arglist[1];
             var routeList = data.Routes.Where(r => r.FromIATA == orig.ToUpper() && r.ToIATA == dest.ToUpper()).ToList();
             if (routeList.Any())
             {
                 txtOut.WriteLine("Routes from " + orig + " to " + dest);
                 foreach (var r in routeList)
                 {
                     txtOut.WriteLine("\t" + r.AirlineCode + (r.CodeShare ? " codeshare " : ""));
                 }
             }
         }
     }
 }
Esempio n. 3
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");
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
                }
            }
        }
Esempio n. 6
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);
        }