public ActionResult Index()
        {
            using (var configService = new ConfigurationService())
                using (var httpService = new HttpService())
                    using (var service = new MonzoService(httpService, configService.GetEnviroment(EnviromentVariableAccessTokenName)))
                    {
                        var auth = service.GetAuthentication();
                        ViewData["authenticated"] = auth.Authenticated ? "Authenticated" : "Not Authenticated";
                        ViewData["googlemapskey"] = configService.GetEnviroment(EnviromentVariableGoogleMapsKey);
                    }

            return(View());
        }
        public string GetTransactions(string startDate, string endDate)
        {
            if (!DateTime.TryParseExact(startDate, "yyyyMMdd", CultureInfo.CurrentUICulture, DateTimeStyles.None, out DateTime parsedStart))
            {
                throw new ArgumentException($"{nameof(startDate)} could not be parsed");
            }

            if (!DateTime.TryParseExact(endDate, "yyyyMMdd", CultureInfo.CurrentUICulture, DateTimeStyles.None, out DateTime parsedEnd))
            {
                throw new ArgumentException($"{nameof(endDate)} could not be parsed");
            }

            using (var configService = new ConfigurationService())
                using (var httpService = new HttpService())
                    using (var service = new MonzoService(httpService, configService.GetEnviroment(EnviromentVariableAccessTokenName)))
                    {
                        var account = service.GetAccounts();

                        if (account == null || account.AccountList == null || account.AccountList.Count == 0)
                        {
                            throw new MissingMemberException("No Accounts found");
                        }

                        var returnedTransactions = new Transactions {
                            TransactionList = new List <Transaction>()
                        };
                        var accountTasks = new List <Task>(account.AccountList.Count());

                        foreach (Account currentAccount in account.AccountList)
                        {
                            accountTasks.Add(Task.Factory.StartNew(() =>
                            {
                                var currentTransactions = service.GetPhysicalTransactionsByDate(currentAccount, parsedStart, parsedEnd).TransactionList;

                                lock (lockObject)
                                {
                                    returnedTransactions.TransactionList = returnedTransactions.TransactionList.Union(currentTransactions);
                                }
                            }));
                        }

                        Task.WaitAll(accountTasks.ToArray());
                        returnedTransactions.TransactionList = returnedTransactions.TransactionList.OrderBy(x => x.Created);

                        return(JsonConvert.SerializeObject(returnedTransactions));
                    }
        }
예제 #3
0
        /// <summary>
        /// The entry point of the program, where the program control starts and ends.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            using (var configService = new ConfigurationService())
                using (var httpService = new HttpService())
                    using (var service = new MonzoService(httpService, configService.GetEnviroment(EnviromentVariableAccessTokenName)))
                    {
                        WriteLine(SectionBreak);
                        var auth = service.GetAuthentication();

                        WriteLine(auth);
                        ForegroundColor = (auth.Authenticated) ? ConsoleColor.Green : throw new UnauthorizedAccessException(auth.ToString());

                        WriteLine(SectionBreak);

                        // Print Detected Acccounts.
                        WriteLine("ID\tDesciption\t");
                        var accounts = service.GetAccounts();
                        foreach (var account in accounts.AccountList)
                        {
                            WriteLine(account.ID + "\t" + account.Description);
                        }

                        WriteLine(SectionBreak);

                        // Print Physical Transactions by Date.
                        WriteLine("ID\tName\tCreated\tLatitude\tLongitude\t");

                        var transactions = service.GetPhysicalTransactionsByDate(accounts.AccountList.ElementAt(0), DateTime.Now.AddDays(-7.0), DateTime.Now);
                        transactions.TransactionList = transactions.TransactionList.Where(x => x.Merchant != null && x.Merchant.Address != null);

                        foreach (var t in transactions.TransactionList.OrderBy(x => x.Created))
                        {
                            WriteLine(t.ID + "\t" + t.Merchant.Name + "\t" + t.Created + "\t" + t.Merchant.Address.Latitude + "\t" + t.Merchant.Address.longitude);
                        }
                    }

            ReadKey();
        }