/// <summary> /// Convert attribute set array to the format of ItemType for AddItemCall. /// </summary> /// <param name="attrSets">The attribute set list generated by AttributeMaster.</param> /// <returns>The converted array that is compatible with ItemType in AddItemCall.</returns> public AttributeSetTypeCollection ConvertAttributeSetArray(IAttributeSetCollection attrSets) { AttributeSetTypeCollection toSets = new AttributeSetTypeCollection(); foreach (AttributeSetType from in attrSets) { AttributeSetType toAst = new AttributeSetType(); toAst.Any = from.Any; toAst.attributeSetID = from.attributeSetID; toAst.attributeSetIDSpecified = from.attributeSetIDSpecified; toAst.attributeSetVersion = from.attributeSetVersion; toAst.Attribute = ConvertAttributeArray(from.Attribute); toSets.Add(toAst); } return(toSets); }
/// <summary> /// get all attributes from the charactersic with which the specific category is mapping /// </summary> /// <param name="categoryId"></param> /// <param name="apiContext"></param> /// <returns></returns> private static AttributeSetTypeCollection GetAttributeSetCol(int categoryId,ApiContext apiContext) { IAttributesMaster attributesMaster=new AttributesMaster(); AttributeSetTypeCollection attributeSTC=new AttributeSetTypeCollection(); attributesMaster.CategoryCSProvider=new CategoryCSDownloader(apiContext); attributesMaster.XmlProvider=new AttributesXmlDownloader(apiContext); //get the characteristic set id of the specified category IAttributeSetCollection attributeSetCol=attributesMaster.GetItemSpecificAttributeSetsForCategories(new Int32Collection(new int[]{categoryId})); Assert.IsNotNull(attributeSetCol); IAttributesXmlProvider iaxp=attributesMaster.XmlProvider; //download all attributes from ebay XmlDocument document=iaxp.DownloadXml(); //write the memory xml to disk WriteXMLToDisk(document); AttributeSetTypeCollection attributeSetTypeCol=new AttributeSetTypeCollection(); //get Required Item specifics by call getAttributesCS foreach(AttributeSet attributeSet in attributeSetCol) { AttributeSetType attributeST=new AttributeSetType(); attributeST.attributeSetID=attributeSet.attributeSetID; String xpath="//Characteristics/CharacteristicsSet[@id='"+attributeSet.attributeSetID.ToString()+"']//CharacteristicsList//Initial//Attribute"; XmlNodeList nodeList; XmlNode root = document.DocumentElement; nodeList=root.SelectNodes(xpath); AttributeTypeCollection attributeTypeCol=new AttributeTypeCollection(); foreach (XmlNode node in nodeList) { AttributeType attributeT=new AttributeType(); XmlAttributeCollection attributes=node.Attributes; Assert.IsNotNull(attributes); XmlNode idNode = attributes.GetNamedItem("id"); attributeT.attributeID=int.Parse(idNode.Value); ValTypeCollection valTypeCol=getValue(node); if(valTypeCol==null) { System.Console.WriteLine("can not find any specific value!"); } attributeT.Value=valTypeCol; attributeTypeCol.Add(attributeT); } attributeST.Attribute=attributeTypeCol; attributeSTC.Add(attributeST); } return attributeSTC; }
private void BtnSuggestedAttr_Click(object sender, System.EventArgs e) { try { ItemType item = FillItem(RecommendationEngineCodeType.SuggestedAttributes); GetItemRecommendationsCall apicall = new GetItemRecommendationsCall(Context); GetRecommendationsRequestContainerType req = new GetRecommendationsRequestContainerType(); req.Item = item; req.Item.LookupAttributeArray = null; req.ListingFlow = ListingFlowCodeType.AddItem; req.RecommendationEngine = new RecommendationEngineCodeTypeCollection(); req.RecommendationEngine.Add(RecommendationEngineCodeType.SuggestedAttributes); if (TxtQuery.Text.Length > 0) { req.Query = TxtQuery.Text; } GetRecommendationsRequestContainerTypeCollection reqc = new GetRecommendationsRequestContainerTypeCollection(); reqc.Add(req); // Make API call apicall.GetItemRecommendations(reqc); GetRecommendationsResponseContainerTypeCollection resps = apicall.ApiResponse.GetRecommendationsResponseContainer; AttributeRecommendationsType attributes = resps[0].AttributeRecommendations; AttributeSetTypeCollection attrSets = null; if (attributes != null) { attrSets = attributes.AttributeSetArray; } if (attrSets != null) { foreach (AttributeSetType attribute in attrSets) { if (attribute != null) { string[] listparams = new string[3]; listparams[0] = attribute.attributeSetID.ToString(); listparams[1] = attribute.attributeSetVersion; listparams[2] = attribute.Attribute.Count.ToString(); ListViewItem vi = new ListViewItem(listparams); LstAttr.Items.Add(vi); } } } ProductInfoTypeCollection products = resps[0].ProductRecommendations; if (products != null) { foreach (ProductInfoType product in products) { if (product != null) { string[] listparams = new string[4]; listparams[0] = product.Title; listparams[1] = product.productInfoID; if (product.AverageStartPrice != null) { listparams[2] = product.AverageStartPrice.Value.ToString(); } if (product.AverageSoldPrice != null) { listparams[3] = product.AverageSoldPrice.Value.ToString();; } ListViewItem vi = new ListViewItem(listparams); lstProduct.Items.Add(vi); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Convert attribute set array to the format of ItemType for AddItemCall. /// </summary> /// <param name="attrSets">The attribute set list generated by AttributeMaster.</param> /// <returns>The converted array that is compatible with ItemType in AddItemCall.</returns> public AttributeSetTypeCollection ConvertAttributeSetArray(IAttributeSetCollection attrSets) { AttributeSetTypeCollection toSets = new AttributeSetTypeCollection(); foreach(AttributeSetType from in attrSets) { AttributeSetType toAst = new AttributeSetType(); toAst.Any = from.Any; toAst.attributeSetID = from.attributeSetID; toAst.attributeSetIDSpecified = from.attributeSetIDSpecified; toAst.attributeSetVersion = from.attributeSetVersion; toAst.Attribute = ConvertAttributeArray(from.Attribute); toSets.Add(toAst); } return toSets; }