예제 #1
0
        public AmazonItemLookup GetItemLookupAttribute()
        {
            var settings          = new Settings(ServiceConfiguration);
            AmazonItemLookup item = new AmazonItemLookup();

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(this.ResultXML);

                XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                nsmgr.AddNamespace("ns", "http://webservices.amazon.com/AWSECommerceService/2011-08-01");

                XmlNode attribute = doc.SelectSingleNode("/ns:ItemLookupResponse/ns:Items/ns:Item/ns:ItemAttributes/ns:" + this.AttributeName, nsmgr);

                if (attribute != null)
                {
                    this.ResultStatus   = "OK";
                    this.AttributeValue = attribute.InnerText;
                }
                else
                {
                    this.ResultStatus = "Not Found";
                }

                return(this);
            }
            catch (Exception ex)
            {
                this.ResultStatus  = "Exception";
                this.ResultMessage = ex.GetBaseException().Message;
                return(this);
            }
        }
예제 #2
0
        public List <AmazonItemLookup> ListItemLookupAttributes()
        {
            var settings = new Settings(ServiceConfiguration);
            List <AmazonItemLookup> items = new List <AmazonItemLookup>();

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(this.ResultXML);
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                nsmgr.AddNamespace("ns", "http://webservices.amazon.com/AWSECommerceService/2011-08-01");

                XmlNode attributes = doc.SelectSingleNode("/ns:ItemLookupResponse/ns:Items/ns:Item/ns:ItemAttributes", nsmgr);

                foreach (XmlNode attribute in attributes.ChildNodes)
                {
                    AmazonItemLookup item = new AmazonItemLookup();
                    item.AttributeName  = attribute.Name;
                    item.AttributeValue = attribute.InnerText;

                    items.Add(item);
                }

                return(items);
            }
            catch (Exception ex)
            {
                throw ex;
                //this.ResultStatus = "Exception";
                //this.ResultMessage = ex.GetBaseException().Message;
                //return this;
            }
        }
예제 #3
0
        private List <AmazonItemLookup> MapSearchProperties(ItemSearchResponse response)
        {
            List <AmazonItemLookup> items = new List <AmazonItemLookup>();

            if (response.Items != null && response.Items.Request != null && response.Items.Request.Errors != null)
            {
                throw new Exception(response.Items.Request.Errors.Error.Code + " - " + response.Items.Request.Errors.Error.Message);
            }

            if (response.Items != null && response.Items.Item != null)
            {
                foreach (var resultItem in response.Items.Item)
                {
                    AmazonItemLookup item = new AmazonItemLookup();

                    item.Keywords    = this.Keywords;
                    item.ItemPage    = this.ItemPage;
                    item.Sort        = this.Sort;
                    item.Condition   = this.Condition;
                    item.SearchIndex = this.SearchIndex;


                    item.ASIN          = resultItem.ASIN;
                    item.ParentASIN    = resultItem.ParentASIN != null ? resultItem.ParentASIN : "";
                    item.DetailPageURL = resultItem.DetailPageURL != null ? resultItem.DetailPageURL : "";

                    if (resultItem.SmallImage != null)
                    {
                        item.SmallImageUrl = resultItem.SmallImage.URL != null ? resultItem.SmallImage.URL : "";
                    }

                    if (resultItem.MediumImage != null)
                    {
                        item.MediumImageUrl = resultItem.MediumImage.URL != null ? resultItem.MediumImage.URL : "";
                    }

                    if (resultItem.MediumImage != null)
                    {
                        item.LargeImageUrl = resultItem.LargeImage.URL != null ? resultItem.LargeImage.URL : "";
                    }

                    if (resultItem.ItemAttributes != null)
                    {
                        item.Manufacturer = resultItem.ItemAttributes.Manufacturer != null ? resultItem.ItemAttributes.Manufacturer : "";
                        item.ProductGroup = resultItem.ItemAttributes.ProductGroup != null ? resultItem.ItemAttributes.ProductGroup : "";
                        item.Title        = resultItem.ItemAttributes.Title != null ? resultItem.ItemAttributes.Title : "";

                        if (resultItem.ItemAttributes.Feature != null && resultItem.ItemAttributes.Feature.Count() > 0)
                        {
                            item.FeatureDescription = resultItem.ItemAttributes.Feature != null?string.Join(" ", resultItem.ItemAttributes.Feature) : "";
                        }

                        item.Model       = resultItem.ItemAttributes.Model != null ? resultItem.ItemAttributes.Model : "";
                        item.UPC         = Convert.ToInt64(resultItem.ItemAttributes.UPC);
                        item.ProductType = resultItem.ItemAttributes.ProductTypeName;
                        if (resultItem.ItemAttributes.ListPrice != null)
                        {
                            item.ListPrice         = resultItem.ItemAttributes.ListPrice.FormattedPrice != null ? resultItem.ItemAttributes.ListPrice.FormattedPrice : "";
                            item.ListPriceCurrency = resultItem.ItemAttributes.ListPrice.CurrencyCode != null ? resultItem.ItemAttributes.ListPrice.CurrencyCode : "";
                            item.ListPriceValue    = resultItem.ItemAttributes.ListPrice.Amount != null ? resultItem.ItemAttributes.ListPrice.Amount : ulong.MinValue;
                        }
                    }

                    //if (resultItem.OfferSummary != null)
                    //{
                    //    if (resultItem.OfferSummary.ListPrice != null)
                    //    {
                    //        item.ListPriceCurrency = resultItem.OfferSummary.ListPrice.CurrencyCode;
                    //        item.ListPrice = resultItem.OfferSummary.ListPrice.FormattedPrice;
                    //        item.ListPriceValue = resultItem.OfferSummary.ListPrice.Amount;
                    //    }
                    //}

                    // inefficient - change FetchItem
                    //item.ResultXML = SerializeObject(resultItem);

                    items.Add(item);
                }
            }

            return(items);
        }
예제 #4
0
        //private string GetAttribute(string xpath)
        //{

        //}

        private AmazonItemLookup MapProperties(ItemLookupResponse response)
        {
            AmazonItemLookup item = new AmazonItemLookup();

            if (response.Items != null && response.Items.Item != null)
            {
                item.ASIN          = response.Items.Item.ASIN;
                item.ParentASIN    = response.Items.Item.ParentASIN != null ? response.Items.Item.ParentASIN : "";
                item.DetailPageURL = response.Items.Item.DetailPageURL != null ? response.Items.Item.DetailPageURL : "";

                if (response.Items.Item.SmallImage != null)
                {
                    item.SmallImageUrl = response.Items.Item.SmallImage.URL != null ? response.Items.Item.SmallImage.URL : "";
                }

                if (response.Items.Item.MediumImage != null)
                {
                    item.MediumImageUrl = response.Items.Item.MediumImage.URL != null ? response.Items.Item.MediumImage.URL : "";
                }

                if (response.Items.Item.MediumImage != null)
                {
                    item.LargeImageUrl = response.Items.Item.LargeImage.URL != null ? response.Items.Item.LargeImage.URL : "";
                }

                if (response.Items.Item.ItemAttributes != null)
                {
                    item.Manufacturer = response.Items.Item.ItemAttributes.Manufacturer != null ? response.Items.Item.ItemAttributes.Manufacturer : "";
                    item.ProductGroup = response.Items.Item.ItemAttributes.ProductGroup != null ? response.Items.Item.ItemAttributes.ProductGroup : "";
                    item.Title        = response.Items.Item.ItemAttributes.Title != null ? response.Items.Item.ItemAttributes.Title : "";

                    if (response.Items.Item.ItemAttributes.Feature != null && response.Items.Item.ItemAttributes.Feature.Count() > 0)
                    {
                        item.FeatureDescription = string.Join(" ", response.Items.Item.ItemAttributes.Feature);
                    }

                    item.ProductType = response.Items.Item.ItemAttributes.ProductTypeName;
                    item.UPC         = Convert.ToInt64(response.Items.Item.ItemAttributes.UPC);
                    item.Model       = response.Items.Item.ItemAttributes.Model != null ? response.Items.Item.ItemAttributes.Model : "";

                    if (response.Items.Item.ItemAttributes.ListPrice != null)
                    {
                        item.ListPrice         = response.Items.Item.ItemAttributes.ListPrice.FormattedPrice != null ? response.Items.Item.ItemAttributes.ListPrice.FormattedPrice : "";
                        item.ListPriceCurrency = response.Items.Item.ItemAttributes.ListPrice.CurrencyCode != null ? response.Items.Item.ItemAttributes.ListPrice.CurrencyCode : "";
                        item.ListPriceValue    = response.Items.Item.ItemAttributes.ListPrice.Amount != null ? response.Items.Item.ItemAttributes.ListPrice.Amount : ulong.MinValue;
                    }
                }

                //if (response.Items.Item.OfferSummary != null)
                //{
                //    if (response.Items.Item.OfferSummary.LowestNewPrice != null)
                //    {
                //        item.ListPriceCurrency = response.Items.Item.OfferSummary.LowestNewPrice.CurrencyCode;
                //        item.ListPrice = response.Items.Item.OfferSummary.LowestNewPrice.FormattedPrice;
                //        item.ListPriceValue = response.Items.Item.OfferSummary.LowestNewPrice.Amount;
                //    }
                //}
            }

            if (response.Items != null && response.Items.Request != null && response.Items.Request.Errors != null)
            {
                item.ErrorCode    = response.Items.Request.Errors.Error.Code != null ? response.Items.Request.Errors.Error.Code : "";
                item.ErrorMessage = response.Items.Request.Errors.Error.Message != null ? response.Items.Request.Errors.Error.Message : "";
            }

            // inefficient - change FetchItem
            item.ResultXML = SerializeObject(response);

            return(item);
        }