Beispiel #1
0
        public static void Update(AccountData[] accountData)
        {
            if (accountData == null)
            {
                return;
            }

            var netWorth = accountData.Sum(data => data.Balance);
            var balanceIssueCount = accountData.Count(data => data.AccountType == "bank" && data.Balance < 0);
            var loginIssueCount = accountData.Count(data => data.LoginStatus == AccountLoginStatus.Invalid);

            var tile = ShellTile.ActiveTiles.First();

            var tileData = new StandardTileData();

            tileData.Count = loginIssueCount + balanceIssueCount;
            tileData.BackTitle = "Net Worth";
            tileData.BackContent = String.Format("{0:c}", netWorth);
            if (balanceIssueCount > 0)
            {
                tileData.BackgroundImage = new Uri("/Assets/Tiles/TileMediumIconRed.png", UriKind.Relative);
                tileData.BackBackgroundImage = new Uri("/Assets/Tiles/TileMediumRed.png", UriKind.Relative);
            }
            else
            {
                tileData.BackgroundImage = new Uri("/Assets/Tiles/TileMediumIcon.png", UriKind.Relative);
                tileData.BackBackgroundImage = new Uri(String.Empty, UriKind.Relative);
            }

            tile.Update(tileData);
        }
Beispiel #2
0
        public static async Task<AccountData[]> GetAccountDataAsync(string username, string password)
        {
            var baseUrl = "https://wwws.mint.com";
            var cookieContainer = new CookieContainer();
            
            var userClient = new RestClient(baseUrl);
            userClient.CookieContainer = cookieContainer;
            var userRequest = new RestRequest("getUserPod.xevent", Method.POST);
            userRequest.AddParameter("username", username);

            await userClient.ExecuteTask(userRequest);

            var loginClient = new RestClient(baseUrl);
            loginClient.CookieContainer = cookieContainer;
            loginClient.Authenticator = new SimpleAuthenticator("username", username, "password", password);
            loginClient.FollowRedirects = true;
            var loginRequest = new RestRequest("loginUserSubmit.xevent", Method.POST);
            loginRequest.AddParameter("task", "L");

            var loginResponse = await loginClient.ExecuteTask(loginRequest);

            if (loginResponse.ResponseUri.ToString().EndsWith("login.event?task=L"))
            {
                throw new AuthenticationException("Invalid credentials.");
            }

            var tokenRegex = new Regex(@"\<input\stype=""hidden""\sid=""javascript-token""\svalue=""(?<Token>.*?)""/\>");
            var tokenMatch = tokenRegex.Match(loginResponse.Content);
            if (tokenMatch == null || tokenMatch.Groups["Token"] == null || String.IsNullOrEmpty(tokenMatch.Groups["Token"].Value))
            {
                throw new Exception("The 'javascript-token' value was not found.");
            }

            var token = tokenMatch.Groups["Token"].Value;

            var getAccountsClient = new RestClient(baseUrl);
            getAccountsClient.CookieContainer = cookieContainer;
            var getAccountsRequest = new RestRequest("bundledServiceController.xevent?token=" + token, Method.POST);
            getAccountsRequest.AddParameter("input", @"[{""args"":{""types"":[""BANK"",""CREDIT"",""INVESTMENT"",""LOAN"",""MORTGAGE"",""OTHER_PROPERTY"",""REAL_ESTATE"",""VEHICLE"",""UNCLASSIFIED""]},""service"":""MintAccountService"",""task"":""getAccountsSorted"",""id"":""accounts""}]", ParameterType.GetOrPost);

            var getAccountsResponse = await getAccountsClient.ExecuteTask(getAccountsRequest);

            dynamic dataObject = JObject.Parse(getAccountsResponse.Content);

            var accountDataList = new List<AccountData>();
            foreach (var accountObject in dataObject["response"]["accounts"]["response"])
            {
                if ((string)accountObject["accountStatus"] != "1")
                {
                    continue;
                }

                var accountData = new AccountData();
                accountData.AccountType = (string)accountObject["accountType"];
                accountData.Name = (string)accountObject["accountName"];
                accountData.InstitutionName = (string)accountObject["fiName"];
                accountData.Balance = GetBalance((decimal)accountObject["currentBalance"], (string)accountObject["accountType"]);
                accountData.LastUpdated = new DateTime((long)accountObject["lastUpdated"] * 10000 + 621355968000000000);
                accountData.LoginStatus = GetLoginStatus((string)accountObject["fiLoginStatus"]);
                
                accountDataList.Add(accountData);
            }

            return accountDataList.ToArray();
        }