Ejemplo n.º 1
0
        public Product getSingleProduct(string ASIN)
        {
            AMZNHelper amznHelper = new AMZNHelper();

            IDictionary <string, string> r1 = new Dictionary <string, String>();

            r1["Action"]          = "GetMatchingProduct";
            r1["SellerId"]        = "A3FWGQLMG1AAXG";
            r1["MarketplaceId"]   = "ATVPDKIKX0DER";
            r1["ASINList.ASIN.1"] = ASIN;
            r1["Version"]         = "2011-10-01";


            MWSWebRequest wr = new MWSWebRequest();
            string        s  = wr.getResponse("https://mws.amazonservices.com/Products/2011-10-01", r1, false, true);


            var xDoc = XDocument.Parse(s);


            XElement xe = Util.stripNS(xDoc.Elements().First());

            IEnumerable <XElement> Products = xe.Descendants("Product");

            foreach (XElement product in Products)
            {
                string title = Util.tryGetElementValueString(xe.Descendants("ItemAttributes").First(), "Title", true);

                Product p = new Product(ASIN, title);
                DataStore.Upsert_Product(p);
                return(p);
            }

            return(null);
        }
Ejemplo n.º 2
0
        public void getAllInventoryItems()
        {
            AMZNHelper amznHelper = new AMZNHelper();

            IDictionary<string, string> r1 = new Dictionary<string, String>();

            r1["Action"] = "ListInventorySupply";
            r1["SellerId"] = "A3FWGQLMG1AAXG";
            r1["MarketplaceId"] = "ATVPDKIKX0DER";
            r1["QueryStartDateTime"] = amznHelper.GetFormattedTimestamp(DateTime.Now.AddMonths(-6));
            r1["Version"] = "2010-10-01";

            MWSWebRequest wr = new MWSWebRequest();
            string s = wr.getResponse("https://mws.amazonservices.com/FulfillmentInventory/2010-10-01", r1, false, true);

            var xDoc = XDocument.Parse(s);

            XElement xe = Util.stripNS(xDoc.Elements().First());

            IEnumerable<XElement> InventoryMembers = xe.Descendants("member");
            foreach (XElement member in InventoryMembers)
            {
                string asin = Util.tryGetElementValueString(member, "ASIN", true);
                string SellerSKU = Util.tryGetElementValueString(member, "SellerSKU", true);
                string fnsku = Util.tryGetElementValueString(member, "FNSKU", true);

                InventoryMember i = new InventoryMember(asin, fnsku, SellerSKU);
                DataStore.Upsert_Inventory(i);

            }

            return;
        }
Ejemplo n.º 3
0
        public Product getSingleProduct(string ASIN)
        {
            AMZNHelper amznHelper = new AMZNHelper();

            IDictionary<string, string> r1 = new Dictionary<string, String>();

            r1["Action"] = "GetMatchingProduct";
            r1["SellerId"] = "A3FWGQLMG1AAXG";
            r1["MarketplaceId"] = "ATVPDKIKX0DER";
            r1["ASINList.ASIN.1"] = ASIN;
            r1["Version"] = "2011-10-01";

            MWSWebRequest wr = new MWSWebRequest();
            string s = wr.getResponse("https://mws.amazonservices.com/Products/2011-10-01", r1, false, true);

            var xDoc = XDocument.Parse(s);

            XElement xe = Util.stripNS(xDoc.Elements().First());

            IEnumerable<XElement> Products = xe.Descendants("Product");
            foreach (XElement product in Products)
            {
                string title = Util.tryGetElementValueString(xe.Descendants("ItemAttributes").First(), "Title", true);

                Product p = new Product(ASIN, title);
                DataStore.Upsert_Product(p);
                return p;
            }

            return null;
        }
Ejemplo n.º 4
0
        public void getAllInventoryItems()
        {
            AMZNHelper amznHelper = new AMZNHelper();

            IDictionary <string, string> r1 = new Dictionary <string, String>();

            r1["Action"]             = "ListInventorySupply";
            r1["SellerId"]           = "A3FWGQLMG1AAXG";
            r1["MarketplaceId"]      = "ATVPDKIKX0DER";
            r1["QueryStartDateTime"] = amznHelper.GetFormattedTimestamp(DateTime.Now.AddMonths(-6));
            r1["Version"]            = "2010-10-01";


            MWSWebRequest wr = new MWSWebRequest();
            string        s  = wr.getResponse("https://mws.amazonservices.com/FulfillmentInventory/2010-10-01", r1, false, true);


            var xDoc = XDocument.Parse(s);


            XElement xe = Util.stripNS(xDoc.Elements().First());

            IEnumerable <XElement> InventoryMembers = xe.Descendants("member");

            foreach (XElement member in InventoryMembers)
            {
                string asin      = Util.tryGetElementValueString(member, "ASIN", true);
                string SellerSKU = Util.tryGetElementValueString(member, "SellerSKU", true);
                string fnsku     = Util.tryGetElementValueString(member, "FNSKU", true);

                InventoryMember i = new InventoryMember(asin, fnsku, SellerSKU);
                DataStore.Upsert_Inventory(i);
            }

            return;
        }
Ejemplo n.º 5
0
        public string getResponse(string serviceURL, IDictionary<string, string> parms, bool useMarketPlaceId, bool retry)
        {
            AMZNHelper amznHelper = new AMZNHelper();

            parms["SellerId"] = SecureLocalStore.getItem("SellerId");
            if (useMarketPlaceId)
            {
                parms["MarketplaceId"] = SecureLocalStore.getItem("MarketplaceId");
            }

            amznHelper.AddRequiredParameters(parms, serviceURL);

            //var content2 = HttpUtility.UrlEncode(str, System.Text.Encoding.UTF8);
            var content2 = new FormUrlEncodedContent(parms);
            var requestUrl = serviceURL + "?" + content2.ReadAsStringAsync().Result;

            this.url_called = requestUrl;
            this.logtimestamp = DateTime.Now;

            var start = DateTime.Now;

            WebRequest request = HttpWebRequest.Create(requestUrl);

            HttpWebResponse webResponse = null;

            try
            {
                webResponse = (HttpWebResponse)request.GetResponse();
                this.StatusCode = (int)webResponse.StatusCode;
                this.ContentLength = webResponse.ContentLength;

            }
            catch (WebException e)
            {

                // wait a bit, retry
                Util.ServiceLog.Warn("first error running " + requestUrl, e);
                if (retry)
                {
                    Util.ServiceLog.Info("waiting 2 mins...");
                    System.Threading.Thread.Sleep(120000);

                    try
                    {
                        start = DateTime.Now;
                        request = HttpWebRequest.Create(requestUrl);
                        webResponse = (HttpWebResponse)request.GetResponse();
                        this.StatusCode = (int)webResponse.StatusCode;
                        this.ContentLength = webResponse.ContentLength;
                    }
                    catch (WebException e2)
                    {
                        Util.ServiceLog.Error("Second try error running " + requestUrl, e2);
                        if (e2.Status == WebExceptionStatus.ProtocolError)
                        {
                            var exResponse = (HttpWebResponse)e2.Response;
                            if (exResponse != null)
                            {
                                this.StatusCode = (int)exResponse.StatusCode;
                                this.response = new StreamReader(exResponse.GetResponseStream()).ReadToEnd();
                            }
                        }

                    }
                }
                else
                {

                    if (e.Status == WebExceptionStatus.ProtocolError)
                    {
                        var exResponse = (HttpWebResponse)e.Response;
                        if (exResponse != null)
                        {
                            this.StatusCode = (int)exResponse.StatusCode;
                            this.response = new StreamReader(exResponse.GetResponseStream()).ReadToEnd();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Util.ServiceLog.Error("Exception running " + requestUrl, e);
                return "";
            }

            this.durationms = (int)(DateTime.Now - start).TotalMilliseconds;

            if (webResponse == null)
                return "";

            MemoryStream ms = new MemoryStream();

            webResponse.GetResponseStream().CopyTo(ms);
            ms.Seek(0, 0);
            string rv = Encoding.UTF8.GetString(ms.ToArray());

            if (this.StatusCode == (int)HttpStatusCode.OK)
            {
                this.response = Util.Compress(rv);
            }

            return rv;
        }
Ejemplo n.º 6
0
        public string getResponse(string serviceURL, IDictionary <string, string> parms, bool useMarketPlaceId, bool retry)
        {
            AMZNHelper amznHelper = new AMZNHelper();

            parms["SellerId"] = SecureLocalStore.getItem("SellerId");
            if (useMarketPlaceId)
            {
                parms["MarketplaceId"] = SecureLocalStore.getItem("MarketplaceId");
            }

            amznHelper.AddRequiredParameters(parms, serviceURL);


            //var content2 = HttpUtility.UrlEncode(str, System.Text.Encoding.UTF8);
            var content2   = new FormUrlEncodedContent(parms);
            var requestUrl = serviceURL + "?" + content2.ReadAsStringAsync().Result;


            this.url_called   = requestUrl;
            this.logtimestamp = DateTime.Now;

            var start = DateTime.Now;

            WebRequest request = HttpWebRequest.Create(requestUrl);


            HttpWebResponse webResponse = null;

            try
            {
                webResponse        = (HttpWebResponse)request.GetResponse();
                this.StatusCode    = (int)webResponse.StatusCode;
                this.ContentLength = webResponse.ContentLength;
            }
            catch (WebException e)
            {
                // wait a bit, retry
                Util.ServiceLog.Warn("first error running " + requestUrl, e);
                if (retry)
                {
                    Util.ServiceLog.Info("waiting 2 mins...");
                    System.Threading.Thread.Sleep(120000);

                    try
                    {
                        start              = DateTime.Now;
                        request            = HttpWebRequest.Create(requestUrl);
                        webResponse        = (HttpWebResponse)request.GetResponse();
                        this.StatusCode    = (int)webResponse.StatusCode;
                        this.ContentLength = webResponse.ContentLength;
                    }
                    catch (WebException e2)
                    {
                        Util.ServiceLog.Error("Second try error running " + requestUrl, e2);
                        if (e2.Status == WebExceptionStatus.ProtocolError)
                        {
                            var exResponse = (HttpWebResponse)e2.Response;
                            if (exResponse != null)
                            {
                                this.StatusCode = (int)exResponse.StatusCode;
                                this.response   = new StreamReader(exResponse.GetResponseStream()).ReadToEnd();
                            }
                        }
                    }
                }
                else
                {
                    if (e.Status == WebExceptionStatus.ProtocolError)
                    {
                        var exResponse = (HttpWebResponse)e.Response;
                        if (exResponse != null)
                        {
                            this.StatusCode = (int)exResponse.StatusCode;
                            this.response   = new StreamReader(exResponse.GetResponseStream()).ReadToEnd();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Util.ServiceLog.Error("Exception running " + requestUrl, e);
                return("");
            }

            this.durationms = (int)(DateTime.Now - start).TotalMilliseconds;

            if (webResponse == null)
            {
                return("");
            }

            MemoryStream ms = new MemoryStream();

            webResponse.GetResponseStream().CopyTo(ms);
            ms.Seek(0, 0);
            string rv = Encoding.UTF8.GetString(ms.ToArray());

            if (this.StatusCode == (int)HttpStatusCode.OK)
            {
                this.response = Util.Compress(rv);
            }



            return(rv);
        }