Exemple #1
0
        public static void waitThrottle(string MWSAction, AmazonAccount acct)
        {
            var key = $"MWSThrottle:{acct.SellerId}:{acct.MarketplaceId}:{MWSAction}";

            DateTime lastCall;

            CheckHourlyQuota(MWSAction, acct);


            using (var redis = RedisHelper.GetRedisConnection())
            {
                lastCall = redis.Get <DateTime>(key);


                if (throttleList.ContainsKey(MWSAction) && lastCall > DateTime.Now.AddDays(-1))
                {
                    var pace = throttleList[MWSAction];

                    var waitTimeMs = pace - (DateTime.Now - lastCall).TotalMilliseconds;

                    if (waitTimeMs > 0)
                    {
                        System.Threading.Thread.Sleep((int)waitTimeMs + 1);
                    }
                }


                redis.Set <DateTime>(key, DateTime.Now);
            }
        }
Exemple #2
0
        public async Task <IActionResult> Edit(int id, [Bind("AmazonAccountID,Name,Prefix")] AmazonAccount amazonAccount, List <int> Marketplaces)
        {
            if (id != amazonAccount.AmazonAccountID)
            {
                return(NotFound());
            }

            var productToUpdate = await _context.AmazonAccounts
                                  .Include(i => i.Marketplaces)
                                  .SingleOrDefaultAsync(m => m.AmazonAccountID == id);

            if (await TryUpdateModelAsync <AmazonAccount>(
                    productToUpdate,
                    "",
                    i => i.Name, i => i.Prefix))
            {
                UpdateAccountMarketplaces(Marketplaces, productToUpdate);
                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateException /* ex */)
                {
                    //Log the error (uncomment ex variable name and write a log.)
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
                return(RedirectToAction("Index"));
            }
            ViewData["AmazonMarketplaceID"] = new MultiSelectList(_context.AmazonMarketplaces, "AmazonMarketplaceID", "Name", amazonAccount.Marketplaces.Select(i => i.MarketplaceID).ToArray());
            return(View(amazonAccount));
        }
 public AMZNWebResponse(AmazonAccount acct)
 {
     _acct = acct;
     if (client == null)
     {
         client = new HttpClient();
     }
 }
Exemple #4
0
        private void UpdateAccountMarketplaces(List <int> Marketplaces, AmazonAccount productToUpdate)
        {
            _context.AccountMarketplaces.RemoveRange(_context.AccountMarketplaces.Where(i => i.AccountID == productToUpdate.AmazonAccountID));
            _context.SaveChanges();

            foreach (var marketplaceid in Marketplaces)
            {
                productToUpdate.Marketplaces.Add(new AccountMarketplaces {
                    AccountID = productToUpdate.AmazonAccountID, MarketplaceID = marketplaceid
                });
            }
        }
Exemple #5
0
        public Order(XElement order, AmazonAccount acct)
        {
            AmazonAccountId = acct.AmazonAccountId;

            AmazonOrderId      = Util.tryGetElementValueString(order, "AmazonOrderId", true);
            BuyerEmail         = Util.tryGetElementValueString(order, "BuyerEmail", false);
            BuyerName          = Util.tryGetElementValueString(order, "BuyerName", false);
            EarliestShipDate   = Util.tryGetElementValueDate(order, "EarliestShipDate", true);
            FulfillmentChannel = Util.tryGetElementValueString(order, "FulfillmentChannel", true);
            IsBusinessOrder    = Util.tryGetElementValueString(order, "IsBusinessOrder", true);
            IsPrime            = Util.tryGetElementValueString(order, "IsPrime", true);
            var dt = Util.tryGetElementValueDate(order, "LastUpdateDate", true);

            if (dt != null)
            {
                LastUpdateDate = (DateTime)dt;
            }

            logtimestamp = DateTime.Now;

            MarketplaceId        = Util.tryGetElementValueString(order, "MarketplaceId", true);
            NumberOfItemsShipped = Util.tryGetElementValueint(order, "NumberOfItemsShipped", true);


            OrderStatus = Util.tryGetElementValueString(order, "OrderStatus", true);
            try{
                OrderTotal = Double.Parse(Util.tryGetElementValueString(order, "OrderTotal", false).Replace("USD", ""));
            }
            catch (Exception) {}
            OrderType     = Util.tryGetElementValueString(order, "OrderType", true);
            PaymentMethod = Util.tryGetElementValueString(order, "PaymentMethod", false);
            dt            = Util.tryGetElementValueDate(order, "PurchaseDate", true);
            if (dt != null)
            {
                PurchaseDate = (DateTime)dt;
            }

            SalesChannel  = Util.tryGetElementValueString(order, "SalesChannel", true);
            SellerOrderId = Util.tryGetElementValueString(order, "SellerOrderId", false); //not there with MFN
            ShipmentServiceLevelCategory = Util.tryGetElementValueString(order, "ShipmentServiceLevelCategory", true);
            ShippingAddress_City         = Util.tryGetElementValueString(order.Element("ShippingAddress"), "City", false);
            ShippingAddress_Postal       = Util.tryGetElementValueString(order.Element("ShippingAddress"), "PostalCode", false);
            ShippingAddress_State        = Util.tryGetElementValueString(order.Element("ShippingAddress"), "StateOrRegion", false);
            ShippingAddress_AddressLine1 = Util.tryGetElementValueString(order.Element("ShippingAddress"), "AddressLine1", false);
            ShippingAddress_AddressLine2 = Util.tryGetElementValueString(order.Element("ShippingAddress"), "AddressLine2", false);


            ShipServiceLevel = Util.tryGetElementValueString(order, "ShipServiceLevel", true);

            this.logtimestamp = DateTime.Now;
            Order.Save(this);
        }
Exemple #6
0
        public async Task <IActionResult> Create([Bind("AmazonAccountID,Name,Prefix")] AmazonAccount amazonAccount, List <int> Marketplaces)
        {
            amazonAccount.Marketplaces = new List <AccountMarketplaces>();
            UpdateAccountMarketplaces(Marketplaces, amazonAccount);
            if (ModelState.IsValid)
            {
                _context.Add(amazonAccount);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["AmazonMarketplaceID"] = new MultiSelectList(_context.AmazonMarketplaces, "AmazonMarketplaceID", "Name", amazonAccount.Marketplaces.Select(i => i.MarketplaceID).ToArray());
            return(View(amazonAccount));
        }
Exemple #7
0
        private static void CheckHourlyQuota(string action, AmazonAccount acct)
        {
            // check hourly
            string cacheKey = $"MWSHourlyQuotaHold:{acct.SellerId}:{acct.MarketplaceId}:{action}";

            using (var redis = RedisHelper.GetRedisConnection())
            {
                //set a value expire when quota resets.

                var s = redis.Get <DateTime?>(cacheKey);
                if (s != null && s > DateTime.Now)
                {
                    var msToWait = ((DateTime)s - DateTime.Now).TotalMilliseconds;
                    System.Threading.Thread.Sleep((int)msToWait);
                }
            }
        }
Exemple #8
0
        public static void SetHourlyQuotaHold(string action, Single remaining, DateTime quotaResetWhen, AmazonAccount acct)
        {
            if (remaining < 2.0)
            {
                // see if we need to wait
                string cacheKey = $"MWSHourlyQuotaHold:{acct.SellerId}:{acct.MarketplaceId}:{action}";

                using (var redis = RedisHelper.GetRedisConnection())
                {
                    //set a value expire when quota resets.

                    redis.Set <DateTime>(cacheKey, quotaResetWhen, quotaResetWhen);
                }
            }
        }
 public OrderDownloader(AmazonAccount acct)
 {
     _acct = acct;
 }
Exemple #10
0
 public Report(AmazonAccount acct)
 {
     _acct = acct;
 }
 public AMZNHelper(AmazonAccount acct)
 {
     _acct = acct;
 }
Exemple #12
0
        public OrderItem(XElement orderItemElement, string AmazonOrderId, DateTime purchaseDate, AmazonAccount _acct)
        {
            try
            {
                this.AmazonOrderId   = AmazonOrderId;
                this.PurchaseDate    = purchaseDate;
                this.AmazonAccountId = _acct.AmazonAccountId;
                ASIN             = Util.tryGetElementValueString(orderItemElement, "ASIN", true);
                ItemPrice_Amount = Util.tryGetElementValueDouble(orderItemElement.Element("ItemPrice"), "Amount", false);
                ItemTax_Amount   = Util.tryGetElementValueDouble(orderItemElement.Element("ItemTax"), "Amount", false);

                OrderItemId = Util.tryGetElementValueString(orderItemElement, "OrderItemId", true);
                PromotionDiscount_Amount = Util.tryGetElementValueDouble(orderItemElement.Element("PromotionDiscount"), "Amount", false);
                QuantityShipped          = Util.tryGetElementValueint(orderItemElement, "QuantityShipped", true);
                QuantityOrdered          = Util.tryGetElementValueint(orderItemElement, "QuantityOrdered", true);

                SellerSKU = Util.tryGetElementValueString(orderItemElement, "SellerSKU", true);
                Title     = Util.tryGetElementValueString(orderItemElement, "Title", true);
                OrderItem.Save(this);
            }
            catch (Exception e)
            {
                Log.Error(_acct.AmazonAccountId, "Error trying to populate orderitem from xelement for orderid " + AmazonOrderId, e);
            }
        }
Exemple #13
0
 private void DeleteAccountMarketplaces(AmazonAccount productToUpdate)
 {
     _context.AccountMarketplaces.RemoveRange(_context.AccountMarketplaces.Where(i => i.AccountID == productToUpdate.AmazonAccountID));
     _context.SaveChanges();
 }