/// <summary> /// Handles the specified response. /// </summary> /// <param name="response">The response.</param> public void Handle(YodleeGetUserAccountsCommandResponse response) { if (response.IsFailed) { ReplyToOrigin(response); return; } var existingContentServicesIds = YodleeQueries.GetUserContentServicesIds(response.CustomerId) .ToLookup(o => o); List <YodleeContentServiceAccount> newAccounts = response.Accounts.Where(o => !existingContentServicesIds.Contains(o.ContentServiceId)) .ToList(); if (newAccounts.Count > 0) { InfoAccumulator info = new InfoAccumulator(); info.AddInfo("customer " + response.CustomerId + "added " + newAccounts.Count + " accounts"); SaveAccounts(newAccounts, response.UserName, response.UserPassword); SendTransactionsRequestCommand(newAccounts, response.UserName, response.UserPassword); SendReply(info, response); } else { InfoAccumulator info = new InfoAccumulator(); info.AddError("could not find added account for customer: " + response.CustomerId); SendReply(info, response); } }
/// <summary> /// Handles the specified command. /// </summary> /// <param name="cmd">The command.</param> public void Handle(YodleeUserAddedAccountCommand cmd) { InfoAccumulator info = new InfoAccumulator(); var userAccount = YodleeQueries.GetUserAccount(cmd.CustomerId); if (userAccount == null) { string err = "could not get useraccount from db for id: " + cmd.CustomerId; info.AddError(err); Log.Error(err); RegisterError(info, cmd); //go to retry throw new InvalidDataException(err); } YodleeGetUserAccountsCommand userAccountsCommand = new YodleeGetUserAccountsCommand { UserName = userAccount.Username, UserPassword = userAccount.Password, CobrandUserName = Config.CoBrandUserName, CobrandPassword = Config.CoBrandPassword, CustomerId = cmd.CustomerId }; SendCommand(ThirdPartyService.Address, userAccountsCommand, cmd); }
/// <summary> /// Saves the accounts. /// </summary> /// <param name="accounts">The accounts.</param> /// <param name="yodleeUserName">Name of the yodlee user.</param> /// <param name="yodleeUserPassword">The yodlee user password.</param> /// <exception cref="System.InvalidOperationException">could not save account</exception> private void SaveAccounts(IList <YodleeContentServiceAccount> accounts, string yodleeUserName, string yodleeUserPassword) { foreach (var userAccount in accounts) { var res = YodleeQueries.UpsertContentServiceAccount(ConvertToOrderItem(userAccount)); if (!res.HasValue || !res.Value) { throw new InvalidOperationException("could not save account"); } } }
/// <summary> /// Handles the specified command. /// </summary> /// <param name="cmd">The command.</param> /// <exception cref="System.IO.InvalidDataException"></exception> public void Handle(YodleeAddUserAccountCommand cmd) { InfoAccumulator info = new InfoAccumulator(); if (YodleeQueries.IsUserAlreadyHaveContentService(cmd.CustomerId, cmd.ContentServiceId)) { string msg = "the customer already added this content service" + cmd.ContentServiceId; info.AddError(msg); Log.Info(msg); SendReply(info, cmd); return; } var siteId = YodleeQueries.GetSiteIdFromContentServiceId(cmd.ContentServiceId); if (!siteId.HasValue) { string err = "could not retrieve site id from DB"; Log.Error(err); info.AddError(err); RegisterError(info, cmd); //go to retry throw new InvalidDataException(err); } var yodleeUserAccount = YodleeQueries.GetUserAccount(cmd.CustomerId); if (yodleeUserAccount == null) { var err = "could not get user account from DB for id: " + cmd.CustomerId; Log.Error(err); info.AddError(err); RegisterError(info, cmd); //go to retry throw new InvalidDataException(err); } YodleeGetFastLinkCommand fastLinkCommand = new YodleeGetFastLinkCommand { ContentServiceId = cmd.ContentServiceId, CobrandUserName = Config.CoBrandUserName, CobrandPassword = Config.CoBrandPassword, UserName = yodleeUserAccount.Username, UserPassword = yodleeUserAccount.Password, SiteId = siteId.Value }; SendCommand(ThirdPartyConfig.Address, fastLinkCommand, cmd); }
/// <summary> /// Handles a message. /// </summary> /// <param name="message">The message to handle.</param> /// <remarks> /// This method will be called when a message arrives on the bus and should contain /// the custom logic to execute when the message is received. /// </remarks> public void Handle(YodleeGetTransactionsCommandResponse message) { foreach (IGrouping <int, YodleeTransaction> group in message.Transactions.GroupBy(t => t.AccountId)) { YodleeOrderItem account = new YodleeOrderItem { accountNumber = group.First() .AccountNumber, bankAccountId = group.Key }; YodleeQueries.UpsertContentServiceAccount(account); YodleeQueries.UpsertTransactions(group.Select(ConvertToYodleeOrderItemTransaction)); } }