/// <summary>
        /// Handles the ebay validation response.
        /// <remarks>
        /// if validation response is OK sends command to fetch data from user's ebay account.<br/>
        /// if validation fails sends back error response.
        /// </remarks>
        /// </summary>
        /// <param name="command">The command.</param>
        public void Handle(EbayValidationCommandResponse command)
        {
            if (!command.IsAccountValid.HasValue)
            {
                return; //not our validation command so exit (we looked only for this property, so somebody else invoked validation, but not this handler)
            }

            if (!command.IsAccountValid.IsTrue())
            {
                ReplyToOrigin(command, resp => resp.IsAccountValid = false);
                return; //invalid account
            }

            int    marketPlaceId = (int)command.Payload[MarketplaceId];
            int    marketPlaceUpdatingHistoryId = (int)command.Payload[MarketPlaceUpdatingHistoryId];
            string sessionId  = (string)command.Payload[SessionId];
            int    customerId = (int)command.Payload[CustomerId];


            EbayGetUserData3dPartyCommand getUserData = new EbayGetUserData3dPartyCommand {
                Token     = command.Token,
                SessionId = sessionId,
                //                GetOrdersTimeFrom = TODO time
                Payload = new Dictionary <string, object> {
                    {
                        MarketplaceId, marketPlaceId
                    }, {
                        MarketPlaceUpdatingHistoryId, marketPlaceUpdatingHistoryId
                    }
                }
            };

            //sends command to fetch data from user's ebay account
            SendCommand(ThirdPartyService.Address, getUserData, command);
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        public async void Handle(EbayGetUserData3dPartyCommand command)
        {
            InfoAccumulator info  = new InfoAccumulator();
            string          token = command.Token;

            if (string.IsNullOrEmpty(token))
            {
                token = await EBayService.FetchToken(command.SessionId);
            }
            var userTask           = EBayService.GetUserData(token);
            var accountTask        = EBayService.GetAccount(token);
            var feedbackTask       = EBayService.GetUserFeedback(token);
            var getOrdersCallsTask = EBayService.GetOrders(token, command.GetOrdersTimeFrom, DateTime.Now);

            await Task.WhenAll(userTask, accountTask, feedbackTask, getOrdersCallsTask);

            SendReply(info, command, resp => {
                resp.Token = token;

                resp.EbayUserRegistrationAddressData  = GetUserAddress(userTask.Result.RegistrationAddress);
                resp.EbayUserSellerPaymentAddressData = GetUserAddress(userTask.Result.SellerInfo.SellerPaymentAddress);
                resp.EbayUserData = GetUserData(userTask.Result);

                resp.EbayUserAccountData    = GetUserAccountData(accountTask.Result);
                resp.AdditionalUserAccounts = GetAdditionalUserAccountData(accountTask.Result);

                resp.EbayFeedback      = GetFeedback(feedbackTask.Result);
                resp.EbayRatings       = GetRatings(feedbackTask.Result);
                resp.EbayFeedbackItems = GetFeedbackItems(feedbackTask.Result);

                resp.EbayOrders = GetOrders(getOrdersCallsTask.Result);
                resp.Payload    = command.Payload;
            });
        }