Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles a YodleeGetFastLinkCommand.
        /// </summary>
        /// <param name="cmd">The command.</param>
        public async void Handle(YodleeGetFastLinkCommand cmd)
        {
            YCobrandLoginRequest cobrandLoginRequest = new YCobrandLoginRequest().SetCobrandUserName(cmd.CobrandUserName)
                                                       .SetCobrandPassword(cmd.CobrandPassword);

            YCobrandLoginResponse yCobrandLoginResponse = await Yodlee.LoginCobrand(cobrandLoginRequest);

            YUserLoginRequest userLoginRequest = new YUserLoginRequest()
                                                 .SetCobrandSessionToken(yCobrandLoginResponse.cobrandConversationCredentials.sessionToken)
                                                 .SetUserName(cmd.UserName)
                                                 .SetUserPassword(cmd.UserPassword);

            YUserLoginResponse yUserLoginResponse = await Yodlee.LoginUser(userLoginRequest);

            YGetFastLinkTokenRequest getFastLinkTokenRequest = new YGetFastLinkTokenRequest()
                                                               .SetCobrandSessionToken(yCobrandLoginResponse.cobrandConversationCredentials.sessionToken)
                                                               .SetUserSessionToken(yUserLoginResponse.userContext.conversationCredentials.sessionToken);

            var yGetFastLinkTokenResponse = await Yodlee.GetFastLinkToken(getFastLinkTokenRequest);

            YFastLinkRequest yFastLinkRequest = new YFastLinkRequest()
                                                .SetFastLinkToken(yGetFastLinkTokenResponse.FastLinkToken)
                                                .SetUserSessionToken(yUserLoginResponse.userContext.conversationCredentials.sessionToken);

            if (cmd.ContentServiceId > 0)
            {
                yFastLinkRequest.SetOptionalFastLinkSite(cmd.SiteId);
            }

            string formHtml = yFastLinkRequest.GetFormHtml;

            string json = await Yodlee.MakeFastLink(yFastLinkRequest);

            SendReply(new InfoAccumulator(), cmd, reply => {
                reply.FastLinkUrl = json;
                reply.FormHtml    = formHtml;
            });
        }