public void GetCategories() { bool isValid=true; GetCategoriesCall api = new GetCategoriesCall(this.apiContext); DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] { DetailLevelCodeType.ReturnAll }; api.DetailLevelList = new DetailLevelCodeTypeCollection(detailLevels); api.LevelLimit = 1; api.ViewAllNodes = true; api.Timeout = 300000; // CategoryTypeCollection cats = api.GetCategories(); //check whether the call is success. Assert.IsTrue(api.ApiResponse.Ack==AckCodeType.Success || api.ApiResponse.Ack==AckCodeType.Warning,"do not success!"); Assert.IsNotNull(cats); Assert.IsTrue(cats.Count > 0); //the return category's level must be 1. foreach(CategoryType category in cats) { if(category.CategoryLevel!=1) { isValid=false; break; } } Assert.IsTrue(isValid,"the return value is not valid"); // Save the result. TestData.Categories = cats; }
public List<eBaySvc.Core.Soap.CategoryType> GetCategories(int parentId, int level) { GetCategoriesCall apicall = new GetCategoriesCall(GetContext()); // Enable HTTP compression to reduce the download size. apicall.EnableCompression = true; apicall.DetailLevelList.Add(DetailLevelCodeType.ReturnAll); apicall.ViewAllNodes = true; apicall.LevelLimit = level; apicall.CategoryParent = new StringCollection(); if (parentId > 0) apicall.CategoryParent.Add(parentId.ToString()); CategoryTypeCollection cats = apicall.GetCategories(); List<CategoryType> Items = new List<CategoryType>(); foreach (CategoryType category in cats) { Items.Add(category); } if (Items[0].CategoryID == parentId.ToString()) Items.RemoveAt(0); return Items; }
/// <summary> /// get last update time from site /// </summary> /// <returns>string</returns> protected override string getLastUpdateTime() { GetCategoriesCall api = new GetCategoriesCall(context); //set output selector api.ApiRequest.OutputSelector = new StringCollection(new String[]{"UpdateTime"}); //execute call api.GetCategories(); DateTime updateTime = api.ApiResponse.UpdateTime; return updateTime.ToString("yyyy-MM-dd-hh-mm-ss"); }
/// <summary> /// call GetCategories to get all categories for a given site /// </summary> /// <returns>generic object</returns> protected override object callApi() { GetCategoriesCall api = new GetCategoriesCall(context); //set detail level api.DetailLevelList.Add(DetailLevelCodeType.ReturnAll); api.Timeout = 480000; api.ViewAllNodes =true; //execute call api.GetCategories(); return api.ApiResponse; }
/// <summary> /// init the call /// </summary> /// <param name="api"></param> private static void setBasicInfo(ref GetCategoriesCall api) { //set basic info to the call api.CategorySiteID=Convert.ToString(0); DetailLevelCodeTypeCollection detailLevel=new DetailLevelCodeTypeCollection(); DetailLevelCodeType type=DetailLevelCodeType.ReturnAll; detailLevel.Add(type); api.DetailLevelList=detailLevel; }
/// <summary> /// get a number of CatalogEnabled Categories. /// </summary> /// <param name="number"></param> /// <param name="apiContext"></param> /// <param name="categories"></param> /// <param name="message"></param> /// <returns></returns> //private static bool getCatagoryEnabledCategory(int number,ApiContext apiContext,CategoryEnableCodeType enableType,out CategoryTypeCollection categories,out string message) //{ // CategoryTypeCollection categoryTypeCollection; // categories=new CategoryTypeCollection(); // bool isSuccess,isCatalogEnable; // if(number<=0) // { // number=1; // } // if(getAllCategories(apiContext,out categoryTypeCollection,out message)) // { // foreach(CategoryType category in categoryTypeCollection) // { // if(category.LeafCategory) // { // isSuccess = isCatagoryEnabled(apiContext,category.CategoryID,enableType,out isCatalogEnable,out message); // if(isSuccess) // { // if(isCatalogEnable) // { // categories.Add(category); // } // if(categories.Count>=number) // { // return true; // } // } // else // { // message=message+";get features failure!"; // return false; // } // } // }//end foreach // return true; // } // return false; //} /// <summary> /// check an category whether it is catalog-enabled. /// </summary> /// <param name="apiContext"></param> /// <param name="categorid"></param> /// <param name="isCatalogEnable"></param> /// <param name="message"></param> /// <returns></returns> //private static bool isCatagoryEnabled(ApiContext apiContext,string categorid,CategoryEnableCodeType enableType,out bool isEnable,out string message) //{ // CategoryTypeCollection categories; // isEnable=false; // message=string.Empty; // GetCategory2CSCall api =new GetCategory2CSCall(apiContext); // //GetCategoryFeaturesCall api = new GetCategoryFeaturesCall(apiContext); // DetailLevelCodeType detaillevel= DetailLevelCodeType.ReturnAll; // api.DetailLevelList=new DetailLevelCodeTypeCollection(new DetailLevelCodeType[]{detaillevel}); // api.CategoryID=categorid; // try // { // categories = api.GetCategoryFeatures(); // foreach(CategoryType category in categories) // { // if(string.Compare(category.CategoryID,categorid,false)==0) // { // if(enableType==CategoryEnableCodeType.CatalogEnabled) // { // isEnable=category.CatalogEnabled; // break; // } // else if(enableType==CategoryEnableCodeType.ProductSearchPageAvailable) // { // isEnable=category.ProductSearchPageAvailable; // break; // } // } // } // } // catch(Exception e) // { // message=e.Message; // return false; // } // return true; //} /// <summary> /// check whether a category id is valid. /// </summary> /// <param name="apiContext"></param> /// <param name="isValid"></param> /// <param name="message"></param> /// <returns></returns> private static bool isValidCategory(ApiContext apiContext,ref string categoryID,out bool isValid,out string message) { CategoryTypeCollection categories=null; message=string.Empty; isValid=false; GetCategoriesCall api=new GetCategoriesCall(apiContext); setBasicInfo(ref api); StringCollection parents=new StringCollection(); parents.Add(categoryID); api.CategoryParent=parents; try { categories=api.GetCategories(); if(categories!=null&&categories.Count>0) { foreach(CategoryType category in categories) { if(string.Compare(category.CategoryID,categoryID,true)==0) { isValid=true; break; } } } } catch(Exception e) { message=e.Message; return false; } return true; }
/// <summary> /// return the all leaf categories /// </summary> /// <param name="parentCategoryID"></param> /// <param name="categoryTypeCollection"></param> /// <returns></returns> private static bool getAllSubCategories(int parentCategoryID,ApiContext apiContext,out CategoryTypeCollection categoryTypeCollection,out string message) { //basic init GetCategoriesCall api = new GetCategoriesCall(apiContext); setBasicInfo(ref api); //return all childs categories StringCollection parent=new StringCollection(); parent.Add(parentCategoryID.ToString()); api.CategoryParent=parent; api.ViewAllNodes=true; api.LevelLimit=10; categoryTypeCollection=null; message=string.Empty; try { //call categoryTypeCollection = api.GetCategories(); } catch(Exception e) { message=e.Message; return false; } return true; }
/// <summary> /// return all categories on us sit /// </summary> /// <param name="categoryTypeCollection"></param> /// <returns></returns> private static bool getAllCategories(ApiContext apiContext,out CategoryTypeCollection categoryTypeCollection,out string message) { //basic init categoryTypeCollection=new CategoryTypeCollection(); GetCategoriesCall api = new GetCategoriesCall(apiContext); setBasicInfo(ref api); message=string.Empty; try { if(allCategories==null) { //call categoryTypeCollection = api.GetCategories(); //cach all categories allCategories=categoryTypeCollection; } else { categoryTypeCollection=allCategories; } } catch(Exception e) { message=e.Message; return false; } return true; }
public static CategoryContainer BuildCategoryFromeBay(bool storeCatBuild = false) { if (storeCatBuild == false) { CategoryContainer container = new CategoryContainer(); apiContext = AppSettingHelper.GetApiContext(); apiContext.ApiLogManager = new ApiLogManager(); apiContext.ApiLogManager.ApiLoggerList.Add(new FileLogger("log.txt", true, true, true)); apiContext.ApiLogManager.EnableLogging = true; apiContext.Site = SiteCodeType.US; GetCategoriesCall catCall = new GetCategoriesCall(apiContext) { EnableCompression = true, ViewAllNodes = true }; catCall.DetailLevelList.Add(DetailLevelCodeType.ReturnAll); catCall.GetCategories(); Dictionary<string, CategoryDef> catIdCMLst = new Dictionary<string, CategoryDef>(); foreach (CategoryType category in catCall.CategoryList) { int categoryId = Int32.Parse(category.CategoryID); int? parentId = Int32.Parse(category.CategoryParentID[0]); if (parentId == categoryId) { parentId = null; } if (parentId == null) { catIdCMLst.Add(category.CategoryID, new CategoryDef(category.CategoryName, category.CategoryID)); } else { catIdCMLst.Add(category.CategoryID, new CategoryDef(category.CategoryName, category.CategoryID, parentId.ToString())); } } // Lets get all parent categories so we can build down the tree. var parentQuery = from parentCategory in catIdCMLst where parentCategory.Value.ParentId == "" select parentCategory; foreach (var parentCategory in parentQuery) { string catName = parentCategory.Value.CategoryName; // LoadNode(parent category id, container) -> find all cats call -> LoadNode(parent category id, container) string pId = parentCategory.Key; CategoryItm catItm = new CategoryItm(pId, catName); container.IdLinkList.Add(pId, catItm); container.Items.Add(catItm); LoadeBayNode(pId, catItm, catIdCMLst, container); } return container; } else { CategoryContainer container = new CategoryContainer(); apiContext = AppSettingHelper.GetApiContext(); apiContext.ApiLogManager = new ApiLogManager(); apiContext.ApiLogManager.ApiLoggerList.Add(new FileLogger("log.txt", true, true, true)); apiContext.ApiLogManager.EnableLogging = true; apiContext.Site = SiteCodeType.US; GetStoreCall getStoreCall = new GetStoreCall(apiContext) { EnableCompression = true }; getStoreCall.DetailLevelList.Add(DetailLevelCodeType.ReturnAll); getStoreCall.CategoryStructureOnly = true; getStoreCall.Execute(); StoreCustomCategoryType cType = new StoreCustomCategoryType(); Dictionary<string, CategoryDef> catIdCMLst = new Dictionary<string, CategoryDef>(); foreach (StoreCustomCategoryType category in getStoreCall.Store.CustomCategories) { CategoryItm catItm = new CategoryItm(category.CategoryID.ToString(), category.Name); container.IdLinkList.Add(category.CategoryID.ToString(), catItm); container.Items.Add(catItm); GeteBayChildCategoriesRoot(category, catItm, (int)category.CategoryID, catIdCMLst, container); //container.Items.Add(catItm); } // Lets get all parent categories so we can build down the tree. /*var parentQuery = from parentCategory in catIdCMLst select parentCategory; foreach (var parentCategory in parentQuery) { string catName = parentCategory.Value.CategoryName; // LoadNode(parent category id, container) -> find all cats call -> LoadNode(parent category id, container) string pId = parentCategory.Key; CategoryItm catItm = new CategoryItm(pId, catName); container.IdLinkList.Add(pId, catItm); container.Items.Add(catItm); LoadeBayNode(pId, catItm, catIdCMLst, container); }*/ return container; } //} //catch //{ // return null; //} }
public List<eBaySvc.Core.Soap.CategoryType> GetCategoryBreadCrumb(int categoryId) { GetCategoriesCall apicall = new GetCategoriesCall(GetContext()); // Enable HTTP compression to reduce the download size. apicall.EnableCompression = true; int level = 1; int parentId = 0; apicall.DetailLevelList.Add(DetailLevelCodeType.ReturnAll); apicall.ViewAllNodes = true; apicall.LevelLimit = level; apicall.CategoryParent = new StringCollection(); apicall.CategoryParent.Add(categoryId.ToString()); List<CategoryType> Items = new List<CategoryType>(); while (parentId == 0 && level < 10) // arbitrary bailout at 10 { CategoryTypeCollection cats = apicall.GetCategories(); if (cats.Count == 1) { // Add current cat Items.Add(cats[0]); // Find any parents parentId = Convert.ToInt32(cats[0].CategoryParentID[0]); } else { level++; apicall.LevelLimit = level; } } while (level > 0 && parentId != categoryId) { apicall.LevelLimit = level; apicall.CategoryParent = new StringCollection(); apicall.CategoryParent.Add(parentId.ToString()); CategoryTypeCollection cats = apicall.GetCategories(); if (cats.Count > 0) { Items.Add(cats[0]); if (cats[0].CategoryParentID.Count > 0) { if (parentId == Convert.ToInt32(cats[0].CategoryParentID[0])) break; else parentId = Convert.ToInt32(cats[0].CategoryParentID[0]); } else break; } level--; } Items.Reverse(); return Items; }
private void BtnGetCategories_Click(object sender, System.EventArgs e) { try { LstCategories.Items.Clear(); GetCategoriesCall apicall = new GetCategoriesCall(Context); // Enable HTTP compression to reduce the download size. apicall.EnableCompression = this.ChkEnableCompression.Checked; apicall.DetailLevelList.Add(DetailLevelCodeType.ReturnAll); apicall.ViewAllNodes = !ChkViewLeaf.Checked; if (TxtLevel.Text.Length > 0) apicall.LevelLimit = Convert.ToInt32(TxtLevel.Text); if (TxtParent.Text.Length > 0) { apicall.CategoryParent = new StringCollection(); apicall.CategoryParent.Add(TxtParent.Text); } CategoryTypeCollection cats = apicall.GetCategories(); foreach (CategoryType category in cats) { string[] listparams = new string[8]; listparams[0] = category.CategoryID; listparams[1] = category.CategoryLevel.ToString(); listparams[2] = category.CategoryName; listparams[3] = category.CategoryParentID[0].ToString(); listparams[4] = category.LeafCategory.ToString(); listparams[5] = category.BestOfferEnabled.ToString(); listparams[6] = apicall.ApiResponse.MinimumReservePrice.ToString(); ListViewItem vi = new ListViewItem(listparams); this.LstCategories.Items.Add(vi); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void EbayTopLevelCategories() { GetCategoriesCall Categories = new GetCategoriesCall(m_api); Categories.LevelLimit = 2; Categories.DetailLevelList.Add(DetailLevelCodeType.ReturnAll); CategoryTypeCollection cats =Categories.GetCategories(); foreach (CategoryType category in cats) { m_cats = new tblCategory(); m_cats.category_id= category.CategoryID; m_cats.category_level = category.CategoryLevel.ToString(); m_cats.category_name = category.CategoryName; m_cats.category_parent = category.CategoryParentID[0].ToString(); DataClasses1DataContext db = new DataClasses1DataContext(); try { DataClasses1DataContext context = new DataClasses1DataContext(); // context.Connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["EbayFactoryConnectionString"].ConnectionString; context.tblCategories.InsertOnSubmit(m_cats); context.SubmitChanges(); } catch(Exception e) { string er = e.Message; } } }