Exemple #1
0
        /// <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);
        }
Exemple #2
0
        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;
        }
Exemple #3
0
        /// <summary>
        ///return leaf category objects of specific number
        /// </summary>
        /// <param name="number">how many leaf categories you wanna get.</param>
        /// <param name="category"></param>
        /// <param name="apiContext"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static bool GetLeafCategory(int number, out CategoryTypeCollection categories, ApiContext apiContext, out string message)
        {
            CategoryTypeCollection categoryTypeCollection;

            categories = new CategoryTypeCollection();
            if (number <= 0)
            {
                number = 1;
            }

            if (getAllCategories(apiContext, out categoryTypeCollection, out message))
            {
                foreach (CategoryType category in categoryTypeCollection)
                {
                    if (category.LeafCategory == true)
                    {
                        categories.Add(category);

                        if (categories.Count == number)
                        {
                            break;
                        }
                    }
                }

                return(true);
            }

            return(false);
        }
		/// <summary>
		///return leaf category objects of specific number
		/// </summary>
		/// <param name="number">how many leaf categories you wanna get.</param>
		/// <param name="category"></param>
		/// <param name="apiContext"></param>
		/// <param name="message"></param>
		/// <returns></returns>
		public static bool GetLeafCategory(int number,out CategoryTypeCollection categories,ApiContext apiContext,out string message)
		{
			CategoryTypeCollection categoryTypeCollection;
			categories=new CategoryTypeCollection();
			if(number<=0)
			{
				number=1;
			}

			if(getAllCategories(apiContext,out categoryTypeCollection,out message))
			{
				foreach(CategoryType category in categoryTypeCollection)
				{
					if(category.LeafCategory==true)
					{
						categories.Add(category);

						if(categories.Count==number)
						{
							break;
						}
					}
				}

				return true;
			}

			return false;
		}
Exemple #5
0
        private void writeCategoryTypeObjectToDisk(CategoryTypeCollection obj)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(CategoryTypeCollection));
            TextWriter    writer     = new StreamWriter(CATCS_FILE_NAME);

            serializer.Serialize(writer, obj);
            writer.Close();
        }
Exemple #6
0
        /// <summary>
        /// get some items which supports the ad format category, you can specify the number
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="num"></param>
        /// <param name="categoryTypeCollection"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static bool GetAdFormatCategory(ApiContext apiContext, int num, out CategoryTypeCollection categoryTypeCollection, out string message)
        {
            message = string.Empty;
            CategoryTypeCollection tmpCategories;

            categoryTypeCollection = null;
            num = (num <= 0)?1:num;

            GetCategoryFeaturesCall api = new GetCategoryFeaturesCall(apiContext);

            setBasicInfo(ref api);
            //spcify category id
            if (!getAllCategories(apiContext, out tmpCategories, out message))
            {
                message = message + ",203";
                return(false);
            }

            FeatureIDCodeTypeCollection features = new FeatureIDCodeTypeCollection();
            FeatureIDCodeType           type     = FeatureIDCodeType.AdFormatEnabled;

            features.Add(type);

            string categoryID = string.Empty;

            foreach (CategoryType category in tmpCategories)
            {
                if (category.LeafCategory == true)
                {
                    categoryID = category.CategoryID;
                    try
                    {
                        //call
                        CategoryFeatureTypeCollection featureTypes = api.GetCategoryFeatures(categoryID, 10, true, features, true);

                        if (featureTypes != null && featureTypes.Count > 0)
                        {
                            if (featureTypes[0].AdFormatEnabled == AdFormatEnabledCodeType.Enabled)
                            {
                                categoryTypeCollection.Add(category);
                            }

                            if (categoryTypeCollection.Count >= num)
                            {
                                break;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        message = e.Message + ",204";
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemple #7
0
 public Month() : base()
 {
     Year          = new SaveableXmlElement <IYear>();
     MonthType     = (MonthEnum)DateTime.Now.Month;
     AlignedMonths = new AlignedMonths(this);
     Transactions  = new ElementCollection <ITransaction>();
     Name          = MonthType.ConvertToText();
     Types         = new CategoryTypeCollection();
 }
Exemple #8
0
        private CategoryTypeCollection readCategoryTypeObjectFromDisk()
        {
            XmlSerializer          serializer    = new XmlSerializer(typeof(CategoryTypeCollection));
            FileStream             fs            = new FileStream(CATCS_FILE_NAME, FileMode.Open);
            CategoryTypeCollection categoryTypes = (CategoryTypeCollection)serializer.Deserialize(fs);

            fs.Close();
            return(categoryTypes);
        }
Exemple #9
0
        /// <summary>
        /// get some items which supports the ad format category, you can specify the number
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="num"></param>
        /// <param name="categoryTypeCollection"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static bool GetAdFormatCategory(ApiContext apiContext,int num,out CategoryTypeCollection categoryTypeCollection,out string message)
        {
            message=string.Empty;
            CategoryTypeCollection tmpCategories;
            categoryTypeCollection = null;
            num=(num<=0)?1:num;

            GetCategoryFeaturesCall api = new GetCategoryFeaturesCall(apiContext);
            setBasicInfo(ref api);
            //spcify category id
            if(!getAllCategories(apiContext,out tmpCategories, out message))
            {
                message=message+",203";
                return false;
            }

            FeatureIDCodeTypeCollection features=new FeatureIDCodeTypeCollection();
            FeatureIDCodeType type=FeatureIDCodeType.AdFormatEnabled;
            features.Add(type);

            string categoryID=string.Empty;

            foreach(CategoryType category in tmpCategories)
            {
                if(category.LeafCategory == true)
                {
                    categoryID=category.CategoryID;
                    try
                    {
                        //call
                        CategoryFeatureTypeCollection featureTypes = api.GetCategoryFeatures(categoryID,10,true,features,true);

                        if(featureTypes!=null&&featureTypes.Count>0)
                        {
                            if(featureTypes[0].AdFormatEnabled==AdFormatEnabledCodeType.Enabled)
                            {
                                categoryTypeCollection.Add(category);
                            }

                            if(categoryTypeCollection.Count>=num)
                            {
                                break;
                            }
                        }

                    }
                    catch(Exception e)
                    {
                        message=e.Message+",204";
                        return false;
                    }
                }
            }

            return true;
        }
        //get all categories
        public static CategoryTypeCollection GetAllCategories(ApiContext apiContext)
        {
            CategoriesDownloader   downloader = new CategoriesDownloader(apiContext);
            CategoryTypeCollection catsCol    = downloader.GetAllCategories();

            //cache the categories in hashtable
            foreach (CategoryType cat in catsCol)
            {
                catsTable.Add(cat.CategoryID, cat);
            }

            return(catsCol);
        }
        private void getCatList(int number, ref StringCollection catList, out CategoryTypeCollection categories)
        {
            bool   isSuccess;
            string message;

            catList.Clear();
            //get a leaf category
            isSuccess = CategoryHelper.GetCISSupportLeafCategory(number, out categories, this.apiContext, out message);
            Assert.IsTrue(isSuccess, message);
            for (int i = 0; i < number; i++)
            {
                //add to catList
                catList.Add(categories[i].CategoryID);
            }
        }
        private void getCatList(int number,ref StringCollection catList,out CategoryTypeCollection categories)
        {
            bool isSuccess;
            string message;

            catList.Clear();
            //get a leaf category
            isSuccess=CategoryHelper.GetCISSupportLeafCategory(number,out categories,this.apiContext,out message);
            Assert.IsTrue(isSuccess,message);
            for(int i=0;i<number;i++)
            {
                //add to catList
                catList.Add(categories[i].CategoryID);
            }
        }
Exemple #13
0
        private void init(string catId)
        {
            if (currentVersion == null || currentVersion.Length == 0)
            {
                currentVersion = getCurrentAttributeSystemVersion();
            }
            string site = apiContext.Site.ToString();

            CATCS_FILE_NAME_PREFIX = (catId == null)?"ALL":catId;
            ROOT_DIR = "C:\\TEMP";              //System.Environment.GetEnvironmentVariable(AttributesMaster.SDK_ENV_NAME);
            DirectoryInfo dirInfo = new DirectoryInfo(ROOT_DIR);

            if (!dirInfo.Exists)
            {
                dirInfo.Create();
            }
            string fileNamePrefix = site + "." + CATCS_FILE_NAME_PREFIX + "." + currentVersion;

            string[] dataFiles       = getDataFiles(dirInfo);
            bool     foundVersion    = false;
            bool     foundAllVersion = false;

            if (dataFiles != null && dataFiles.Length != 0)
            {
                foundVersion = FoundVersion(dataFiles, fileNamePrefix);
                if (!foundVersion)
                {
                    foundAllVersion = FoundVersion(dataFiles, site + "." + "ALL" + "." + currentVersion);
                }
                if (foundAllVersion)
                {
                    fileNamePrefix = site + "." + "ALL" + "." + currentVersion;
                }
            }
            CATCS_FILE_NAME = ROOT_DIR + "\\" + fileNamePrefix + "." + CATCS_FILE_EXTENSION;
            SW_FILE_NAME    = ROOT_DIR + "\\" + fileNamePrefix + "." + SW_FILE_EXTENSION;
            if (foundVersion || foundAllVersion)
            {
                mCats = readCategoryTypeObjectFromDisk();
                mSiteWideCharacteristicSets = readSiteWideCharTypeObjectFromDisk();
            }
            else
            {
                mCats = DownloadCategoryCS(catId);
                writeCategoryTypeObjectToDisk(mCats);
                writeSiteWideCharTypeObjectToDisk(mSiteWideCharacteristicSets);
            }
        }
Exemple #14
0
        /// <summary>
        /// Get CategoryCS data by calling eBay API. Special version for fast example usage.
        /// </summary>
        /// <param name="asn">The <c>ApiContext</c> object to make API call.</param>
        /// <param name="categoryId">A specific category ID for which to download CategoryCS data.</param>
        public CategoryTypeCollection DownloadCategoryCS(ApiContext asn, string categoryId)
        {
            GetCategory2CSCall api = new GetCategory2CSCall(asn);

            //api.ErrorLevel = ErrorLevelEnum.BothShortAndLongErrorStrings;
            if (categoryId != null)
            {
                api.CategoryID = categoryId;
            }
            api.DetailLevelList.Add(DetailLevelCodeType.ReturnAll);             //.DetailLevel = 1;
            api.Timeout = 480000;
            mCats       = api.GetCategory2CS();
            mSiteWideCharacteristicSets = api.SiteWideCharacteristicList;

            return(mCats);
        }
        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);
            }
        }
		//sort categories in ascending order and remove nonleaf category
		public static CategoryTypeCollection SortCategories(CategoryTypeCollection catsCol)
		{
			SortedList catSL = new SortedList();
			foreach(CategoryType cat in catsCol)
			{
				if (cat.LeafCategory) //we only care leaf categories
				{
					catSL.Add(int.Parse(cat.CategoryID), cat);
				}
			}
			CategoryTypeCollection sortedCatCol = new CategoryTypeCollection();
			for(int i = 0; i < catSL.Count; i++)
			{
				sortedCatCol.Add((CategoryType)catSL.GetByIndex(i));
			}
			return sortedCatCol;
		}
Exemple #17
0
        public static bool GetCISSupportLeafCategory(int number, out CategoryTypeCollection categories, ApiContext apiContext, out string message)
        {
            CategoryTypeCollection categoryTypeCollection;

            categories = new CategoryTypeCollection();
            bool isSuccess, isSupport;

            if (number <= 0)
            {
                number = 1;
            }

            if (getAllCategories(apiContext, out categoryTypeCollection, out message))
            {
                foreach (CategoryType category in categoryTypeCollection)
                {
                    if (category.LeafCategory == true)
                    {
                        //check whether the category support the ItemSpecificsEnabled;
                        FeatureIDCodeTypeCollection features = new FeatureIDCodeTypeCollection();
                        FeatureIDCodeType           type     = FeatureIDCodeType.ItemSpecificsEnabled;
                        features.Add(type);
                        isSuccess = isSupportFeature(int.Parse(category.CategoryID), features, apiContext, out isSupport, out message);
                        if (!isSuccess)
                        {
                            return(false);
                        }

                        if (isSupport)
                        {
                            categories.Add(category);

                            if (categories.Count == number)
                            {
                                break;
                            }
                        }
                    }            //end if
                }                //end foreach

                return(true);
            }

            return(false);
        }
Exemple #18
0
        private SortedList GetSortedLeafCategories()
        {
            SortedList catSL = new SortedList();

            CategoryTypeCollection catCol = controller.SiteFacade.GetAllMergedCategories();

            foreach (CategoryType cat in catCol)
            {
                //remove non-leaf category
                if (!cat.LeafCategory)
                {
                    continue;
                }
                catSL.Add(int.Parse(cat.CategoryID), cat);
            }

            return(catSL);
        }
		private void init(string catId) 
		{
			if(currentVersion == null || currentVersion.Length == 0) 
			{
				currentVersion = getCurrentAttributeSystemVersion();
			}
			string site = apiContext.Site.ToString();
			CATCS_FILE_NAME_PREFIX = (catId == null)?"ALL":catId;
			ROOT_DIR = "C:\\TEMP";	//System.Environment.GetEnvironmentVariable(AttributesMaster.SDK_ENV_NAME);
			DirectoryInfo dirInfo = new DirectoryInfo(ROOT_DIR);
			if(!dirInfo.Exists) 
			{
				dirInfo.Create();
			}
			string fileNamePrefix = site + "." + CATCS_FILE_NAME_PREFIX + "." + currentVersion;
			string[] dataFiles = getDataFiles(dirInfo);
			bool foundVersion = false;
			bool foundAllVersion = false;
			if(dataFiles != null && dataFiles.Length != 0) 
			{
				foundVersion = FoundVersion(dataFiles, fileNamePrefix);
				if(!foundVersion) 
				{
					foundAllVersion = FoundVersion(dataFiles, site + "." + "ALL" + "." + currentVersion);
				} 
				if(foundAllVersion) 
				{
					fileNamePrefix = site + "." + "ALL" + "." + currentVersion;
				}
			}
			CATCS_FILE_NAME = ROOT_DIR + "\\" + fileNamePrefix + "." + CATCS_FILE_EXTENSION;
			SW_FILE_NAME = ROOT_DIR + "\\" + fileNamePrefix + "." + SW_FILE_EXTENSION;
			if(foundVersion || foundAllVersion) 
			{
				mCats = readCategoryTypeObjectFromDisk();
				mSiteWideCharacteristicSets	= readSiteWideCharTypeObjectFromDisk();
			} 
			else 
			{
				mCats = DownloadCategoryCS(catId);
				writeCategoryTypeObjectToDisk(mCats);
				writeSiteWideCharTypeObjectToDisk(mSiteWideCharacteristicSets);
			}
		}
        //sort categories in ascending order and remove nonleaf category
        public static CategoryTypeCollection SortCategories(CategoryTypeCollection catsCol)
        {
            SortedList catSL = new SortedList();

            foreach (CategoryType cat in catsCol)
            {
                if (cat.LeafCategory)                 //we only care leaf categories
                {
                    catSL.Add(int.Parse(cat.CategoryID), cat);
                }
            }
            CategoryTypeCollection sortedCatCol = new CategoryTypeCollection();

            for (int i = 0; i < catSL.Count; i++)
            {
                sortedCatCol.Add((CategoryType)catSL.GetByIndex(i));
            }
            return(sortedCatCol);
        }
Exemple #21
0
        //get all categories table
        public Hashtable GetAllCategoriesTable()
        {
            if (!siteCategoriesTable.ContainsKey(apiContext.Site))
            {
                Hashtable              catsTable  = new Hashtable(TABLE_SIZE);
                CategoriesDownloader   downloader = new CategoriesDownloader(apiContext);
                CategoryTypeCollection catsCol    = downloader.GetAllCategories();

                foreach (CategoryType cat in catsCol)
                {
                    catsTable.Add(cat.CategoryID, cat);
                }
                siteMergedCategoriesTable.Add(apiContext.Site, catsCol);
                siteCategoriesTable.Add(apiContext.Site, catsTable);
                return(catsTable);
            }
            else
            {
                return(siteCategoriesTable[apiContext.Site] as Hashtable);
            }
        }
Exemple #22
0
        /// <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);
        }
Exemple #23
0
 /// <summary>
 /// get all categories
 /// </summary>
 /// <param name="apiContext"></param>
 /// <param name="categoryTypeCollection"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static bool GetAllCategories(ApiContext apiContext, out CategoryTypeCollection categoryTypeCollection, out string message)
 {
     return(getAllCategories(apiContext, out categoryTypeCollection, out message));
 }
		/// <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 bool GetCISSupportLeafCategory(int number,out CategoryTypeCollection categories,ApiContext apiContext,out string message)
		{
			CategoryTypeCollection categoryTypeCollection;
			categories=new CategoryTypeCollection();
			bool isSuccess,isSupport;
			if(number<=0)
			{
				number=1;
			}

			if(getAllCategories(apiContext,out categoryTypeCollection,out message))
			{
				foreach(CategoryType category in categoryTypeCollection)
				{
					if(category.LeafCategory==true)
					{
						//check whether the category support the ItemSpecificsEnabled;
						FeatureIDCodeTypeCollection features=new FeatureIDCodeTypeCollection();
						FeatureIDCodeType type=FeatureIDCodeType.ItemSpecificsEnabled;
						features.Add(type);
						isSuccess=isSupportFeature(int.Parse(category.CategoryID),features,apiContext,out isSupport,out message);
						if(!isSuccess)
						{
							return false;
						}
						
						if(isSupport)
						{
							categories.Add(category);

							if(categories.Count==number)
							{
								break;
							}
						}
					}//end if
				}//end foreach

				return true;
			}

			return false;
		}
		/// <summary>
		/// get all categories
		/// </summary>
		/// <param name="apiContext"></param>
		/// <param name="categoryTypeCollection"></param>
		/// <param name="message"></param>
		/// <returns></returns>
		public static bool GetAllCategories(ApiContext apiContext,out CategoryTypeCollection categoryTypeCollection,out string message)
		{
			return getAllCategories(apiContext,out categoryTypeCollection,out message);
		}
Exemple #28
0
        /// <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);
        }
Exemple #29
0
        /// <summary>
        /// Install plugin
        /// </summary>
        public override void Install()
        {
            _context.Install();

            var settings = new ConfigurationModel
            {
                AppID  = "PhuocPha-worldbuy-PRD-28e35c535-94b2bb4b",
                DevID  = "4343ce44-efa1-4c33-a431-18daed74c054",
                Token  = "v^1.1#i^1#p^1#r^0#I^3#f^0#t^H4sIAAAAAAAAAOVXa2wUVRTu9oVIizESwYK4nRZjkJm98+ruDt2FpS20aWkXtiBQCZnHHXZgdmYzc5ftxjTWGpr4gB/+MPFFahRJE8WKSg3aRCQEoeAfNfEBPzQQrMQYeQQjwXhndinbSngWIXH/bObcM+ee7zvfOXcu6C6dPLe3sfd8uWdSYV836C70eOgpYHJpyeNTiworSgpAnoOnr7u6u7in6JdaW0zoSWE5tJOmYUNvZ0I3bME1hoiUZQimaGu2YIgJaAtIFmKRpS0CQwEhaZnIlE2d8DbVhwiOlRiFkThallRIcwq2GpditpshgpFYKShyNTDA8KzEAbxu2ynYZNhINBBeB7SfBEGS5tqBX+BogaapGkCvIbwroWVrpoFdKECE3XQF910rL9erpyraNrQQDkKEmyKLY22RpvqG1vZaX16scI6HGBJRyh77VGcq0LtS1FPw6tvYrrcQS8kytG3CF87uMDaoELmUzE2k71JNK5CtYZSAn1UkhhbhhFC52LQSIrp6Ho5FU0jVdRWggTSUuRajmA1pA5RR7qkVh2iq9zp/y1KirqkatEJEw6LI6kg0SoSj8ZQpR+MimTYtXZFSGTK6vJ5kApDlZZ7lySAnMZLESbmNstFyNI/bqc40FM0hzfa2mmgRxFnD8dywedxgpzajzYqoyMko3y+Y45APsmucomarmEJxw6krTGAivO7jtSsw+jZClialEByNMH7BpShEiMmkphDjF10t5uTTaYeIOEJJwedLp9NUmqVMa72PAYD2rVraEpPjMCES2Nfp9ay/du0XSM2FImNtYX8BZZI4l06sVZyAsZ4I4x7284Ec72PTCo+3/suQh9k3tiMmqkNkMSjjGRNgFBb4eV6eiA4J50Tqc/KAkpghE6K1EaKkLsqQlLHOUgloaYrA8irDBlRIKjVBleSCqkpKvFJD0iqEAEJJkoOB/1OjXK/UY7KZhFFT1+TMhAh+wsTOWkpUtFAmBnUdG65X9VcEaTsgbzs8p9dvCKITw8ZBxKRGOdqmZDPhM0U81BzTOjfrW8Kt4fPwrioqBphFqinZg4xy4VL2JpmyoG2mLHyGU23OXG83N0IDdwmyTF2H1kr6lpiYuIl+h6b5FVHJuoZpXHe3IbvBMXmT2hbRHURd3OPpuAJymge4qlzAf2tqrXPr2p75D4bWDRW20bQRVG7DB4hv7HUoXOD+6B7Px6DH8wG+UQEfmENXgcrSohXFRWUVtoYgpYkqZWvrDfyVb0FqI8wkRc0qLPV0zBroX5d3AetbC2aMXsEmF9FT8u5jYNbllRL6vunltB8EaQ74OZqm14Cqy6vF9IPF08oemfVoWlnV/9zfp56Jb7t/2+9/8IOgfNTJ4ykpwMooONbwUs3M6a38yMDJtx+rq5SmlZ3Z17ug5bfBc7v3jJxhv18y79Ck9+a9cbbs8EDz8Fr9+TeHRuYfr336kyWf9aiVW6u/014c3v1rsLfw1Fx+YeHhrpnw02DVO5tbd/55Ysve+tiiZct2WcZbJU/81HXvA+rPof3NM/oeenjf4Ef97efC2/U9+0bK2YXxAx21p4deLZ2XPliVOHvh/Q3qzl3bza9+/Lx6xwWmujTR8eyOv3zD06xNXUdjP+zS7zm4YviF9JeNRQfOD84+8uHeoddnt758RGrZ8u6TA8e/qGCPvbL/4tRDFd7j2+K1g1+f/Hbh/Dmd/emnXlt7cfPWqmYVrN4xMrRgdd2JrsrTR6lvsuX7B4CTuGQaDwAA",
                CertID = "PRD-8e35c5356f0f-1449-425a-a638-6322"
            };

            _settingService.SaveSetting(settings);

            this.AddOrUpdatePluginLocaleResource("Plugins.Widgets.Affiliate.Ebay.AppID", "App ID");
            this.AddOrUpdatePluginLocaleResource("Plugins.Widgets.Affiliate.Ebay.CertID", "Cert ID");
            this.AddOrUpdatePluginLocaleResource("Plugins.Widgets.Affiliate.Ebay.Token", "Token");
            this.AddOrUpdatePluginLocaleResource("Plugins.Widgets.Affiliate.Ebay.DevID", "Dev ID");
            this.AddOrUpdatePluginLocaleResource("Plugins.Widgets.Affiliate.Ebay.CategoryId", "Category Worldbuy");
            this.AddOrUpdatePluginLocaleResource("Plugins.Widgets.Affiliate.Ebay.CategoryEbayId", "Category Ebay");
            this.AddOrUpdatePluginLocaleResource("Plugins.AffiliateEbay.MapCategory.Error", "Danh mục đã được map");
            this.AddOrUpdatePluginLocaleResource("Plugins.AffiliateEbay.MapCategory.Added", "Map danh mục thành công");
            this.AddOrUpdatePluginLocaleResource("Plugins.AffiliateEbay.CallApi.Error", "Map danh mục trước khi lấy sản phẩm");
            this.AddOrUpdatePluginLocaleResource("Admin.Catalog.Products.Added", "Lấy sản phẩm thành công");
            this.AddOrUpdatePluginLocaleResource("Plugin.Configuration.Settings.Ebay", "Lấy sản phẩm thành công");
            this.AddOrUpdatePluginLocaleResource("Nop.Plugin.Affiliate.Ebay.Mapping", "Mapping Category");
            this.AddOrUpdatePluginLocaleResource("Nop.Plugin.Affiliate.Ebay.Product", "Get Product");
            this.AddOrUpdatePluginLocaleResource("Nop.Plugin.Affiliate.Ebay.Setting", "Config Plugin");
            this.AddOrUpdatePluginLocaleResource("Nop.Plugin.Affiliate.Ebay", "Plugin Ebay");
            this.AddOrUpdatePluginLocaleResource("Plugin.Configuration.Settings.Ebay", "Configure Ebay");
            this.AddOrUpdatePluginLocaleResource("Plugin.Ebay.Configuration.Settings.CallApi", "Get Product Ebay");
            this.AddOrUpdatePluginLocaleResource("Plugin.Ebay.Configuration.Settings.MappingCategory", "Mapping Category");
            this.AddOrUpdatePluginLocaleResource("Plugins.Widgets.Affiliate.Ebay.KeyWord", "Keyword");

            //Insert CategoryEbay
            // set devId, appId, certId in ApiAccount
            ApiAccount account = new ApiAccount();

            account.Developer   = "4343ce44-efa1-4c33-a431-18daed74c054";
            account.Application = "PhuocPha-worldbuy-PRD-28e35c535-94b2bb4b";
            account.Certificate = "PRD-8e35c5356f0f-1449-425a-a638-6322";

            // set ApiAccount and token in ApiCredential
            ApiCredential credential = new ApiCredential();

            credential.ApiAccount = account;
            credential.eBayToken  = "AgAAAA**AQAAAA**aAAAAA**JYLgWQ**nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6ACl4CiC5KHowqdj6x9nY+seQ**Pt8DAA**AAMAAA**XEESS+BUaGiTZWWj64HwUby9/+ABWbn3NBturqmQgtWJzIW3f/FNc8Wm/EtypFpT5NU6yfvf9lBvyp7kUifGyih/PIQTmDWVrDJjXU+PxJX6QEGFzw4noZK/E1n01EFm6heicUJ5XVj8KY0GA7WVatXy3k2AVDc6psRDoscGAya5mZVDhHgqdyiTHTs/G/5y6G01HBS9ehbkui4eRbggCX6eyee9nCz/UmLOn19C9WJmCpLng8PxcifyEu4Ca8UInQJsaAqYKKGVflBofV0D+6jd4URuEaKl3J2lZbUrjPIBgmCZtYHv8LOKw5OgCRQKCl014DBz91PgOKpUfZCvh7suXazzNOdjh2t4qitzPCi7uMTmzXUzN7WjN5pbFx+3n90FOe+uKjZN1ZhrFx7295qtt5eFh7xxV0ZqdwbBQUILUKm9tE5/KYlpKS+3wjMFpTw66hYuw0s2CIv7axomq+NV2d+rEY2FXAKD3v8OWVnbIFjzQJY+cV8bpMxxDkHsTN9G7lOhbCGxGlRkV1xy5JYeGmqzGYhuDRZ9glfERySkCXJflU94H/bOls8GgEVDrV6iDvcBgPYVhf8YgLN4MUCY3U/osTZbAXh+bV5RPgvtZLNQ4ZB1WhP/qtCsufdkJKnnpxYy1Zswl8QBRZK4+TVkf7/CEqfNSsJGEllxzmznD+Ox4KL+A1n8nzk/NYPMceXFZPS3l4047juy6lTQ6BSBzP+N0CMjezHAoA4tE0vdlJKTRFPyt1sSCjj03MVX";

            // add ApiCredential to ApiContext
            ApiContext context = new ApiContext();

            context.ApiCredential = credential;

            // set eBay server URL to call
            context.SoapApiServerUrl = "https://api.ebay.com/wsapi";

            // set timeout in milliseconds - 3 minutes
            context.Timeout = 180000;

            // set wsdl version number
            context.Version = "1027";

            // create ApiCall object - we'll use it to make the call
            GetCategoriesCall apicall = new GetCategoriesCall(context);

            apicall.LevelLimit = 3;
            apicall.DetailLevelList.Add(DetailLevelCodeType.ReturnAll);

            CategoryTypeCollection cats = apicall.GetCategories();

            foreach (CategoryType category in cats)
            {
                var cate    = new CategoryEbay();
                var ebayId  = Convert.ToInt32(category.CategoryParentID.ItemAt(0));
                var getCate = _affiliateEbayService.GetByEbayId(ebayId);
                if (getCate != null)
                {
                    cate.ParentCategoryId = getCate.Id;
                }
                else
                {
                    cate.ParentCategoryId = 0;
                }
                cate.EbayId    = Convert.ToInt32(category.CategoryID);
                cate.Name      = category.CategoryName;
                cate.Level     = category.CategoryLevel;
                cate.Published = true;
                cate.Deleted   = false;
                _affiliateEbayService.InsertCategoryEbay(cate);
            }

            base.Install();
        }
Exemple #30
0
 /// <summary>
 ///  get a number of CatalogEnabled Categories.
 /// </summary>
 /// <param name="number">specify the number of categories that you want.</param>
 /// <param name="apiContext"></param>
 /// <param name="categories"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static bool GetCatalogEnabledCategory(int number,ApiContext apiContext,CategoryEnableCodeType enableType,out CategoryTypeCollection categories,out string message)
 {
     return getCatagoryEnabledCategory(number,apiContext,enableType,out categories,out message);
 }
Exemple #31
0
        /// <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;
        }
Exemple #32
0
 public static CategoryType FindCategory(CategoryTypeCollection cats, string catId)
 {
     foreach(CategoryType cat in cats)
     {
         if (cat.CategoryID == catId)
             return cat;
     }
     return null;
 }
		/// <summary>
		/// Get CategoryCS data by calling eBay API. Special version for fast example usage.
		/// </summary>
		/// <param name="asn">The <c>ApiContext</c> object to make API call.</param>
		/// <param name="categoryId">A specific category ID for which to download CategoryCS data.</param>
		public CategoryTypeCollection DownloadCategoryCS(ApiContext asn, string categoryId)
		{
			GetCategory2CSCall	api = new GetCategory2CSCall(asn);
			//api.ErrorLevel = ErrorLevelEnum.BothShortAndLongErrorStrings;
			if (categoryId != null) 
			{
				api.CategoryID = categoryId;
			}
			api.DetailLevelList.Add(DetailLevelCodeType.ReturnAll);	//.DetailLevel = 1;
			api.Timeout = 480000;
			mCats = api.GetCategory2CS();
			mSiteWideCharacteristicSets = api.SiteWideCharacteristicList;

			return mCats;
		}
		private void writeCategoryTypeObjectToDisk(CategoryTypeCollection obj) 
		{
			XmlSerializer serializer =  new XmlSerializer(typeof(CategoryTypeCollection));
			TextWriter writer = new StreamWriter(CATCS_FILE_NAME);
			serializer.Serialize(writer, obj);
			writer.Close();
		}
Exemple #35
0
        /**
           * Get categories using GetCategory2CS and GetCategories calls,
           * although some categories have no characteristics sets, they may still have custom
           * item specifics, so we merge the categories accordingly.
           */
        private CategoryTypeCollection downloadCategories(ApiContext context, string catID)
        {
            AttributesMaster amst = initailAttributesMaster(context);
            //Get all categories that are mapped to characteristics sets
            CategoryTypeCollection cats = ((CategoryCSDownloader)amst.CategoryCSProvider).GetCategoriesCS(catID);
            Hashtable csCatsTable = new Hashtable();
            foreach(CategoryType cat in cats)
            {
                if (csCatsTable.ContainsKey(cat.CategoryID)) continue;
                csCatsTable.Add(cat.CategoryID, cat);
            }

            //get all categories
            Hashtable allCatsTable = Global.GetAllCategoriesTable(context);

               if (catID != null) //one category case, catId specified
               {
               if (allCatsTable.ContainsKey(catID))
               {
                   CategoryType cat = allCatsTable[catID] as CategoryType;
                   CategoryType csCat = csCatsTable[cat.CategoryID] as CategoryType;
                   if (csCat != null)
                   {
                       //copy category name and leaf category fields, since these
                       //fields are not set when using GetCategory2CS call.
                       csCat.CategoryName = cat.CategoryName;
                       csCat.LeafCategory = cat.LeafCategory;
                   }
                   else
                   {
                       //some category has no characteristic sets,
                       //but it may has custom item specifics
                       csCat = cat;
                   }
                   CategoryTypeCollection catCol = new CategoryTypeCollection();
                   catCol.Add(csCat);
                   return catCol;
               }
               else
               {
                   //no category found
                   return new CategoryTypeCollection();
               }

               }
               else //all categories case, catId not specified
               {
               foreach(CategoryType cat in allCatsTable.Values)
               {
                   CategoryType csCat = csCatsTable[cat.CategoryID] as CategoryType;
                   if (csCat != null)
                   {
                       //copy category name and leaf category fields, since these
                       //fields are not set when using GetCategoryCS call.
                       csCat.CategoryName = cat.CategoryName;
                       csCat.LeafCategory = cat.LeafCategory;
                   }
                   else
                   {
                       //some category has no characteristics sets,
                       //but it may has custom item specifics
                       csCatsTable.Add(cat.CategoryID, cat);
                   }
               }

               CategoryTypeCollection catCol = new CategoryTypeCollection();
               foreach(CategoryType cat in csCatsTable.Values)
               {
                   catCol.Add(cat);
               }

               return catCol;

               }
        }
Exemple #36
0
        /**
         * Get categories using GetCategory2CS and GetCategories calls,
         * and merge the categories
         *
         */
        public CategoryTypeCollection GetAllMergedCategories()
        {
            if (!siteMergedCategoriesTable.ContainsKey(apiContext.Site))
            {
                //Get all categories that are mapped to characteristics sets
                CategoryCSDownloader categoryCSDownloader = new CategoryCSDownloader(apiContext);
                CategoryTypeCollection cats = categoryCSDownloader.GetCategoriesCS();
                Hashtable csCatsTable = new Hashtable();
                foreach (CategoryType cat in cats)
                {
                    if (csCatsTable.ContainsKey(cat.CategoryID)) continue;
                    csCatsTable.Add(cat.CategoryID, cat);
                }

                //get all categories
                Hashtable allCatsTable = GetAllCategoriesTable();

                foreach (CategoryType cat in allCatsTable.Values)
                {
                    CategoryType csCat = csCatsTable[cat.CategoryID] as CategoryType;
                    if (csCat != null)
                    {
                        //copy category name and leaf category fields, since these
                        //fields are not set when using GetCategoryCS call.
                        csCat.CategoryName = cat.CategoryName;
                        csCat.LeafCategory = cat.LeafCategory;
                    }
                    else
                    {
                        //some category has no characteristics sets,
                        //but it may has custom item specifics
                        csCatsTable.Add(cat.CategoryID, cat);
                    }
                }

                CategoryTypeCollection catCol = new CategoryTypeCollection();
                foreach (CategoryType cat in csCatsTable.Values)
                {
                    catCol.Add(cat);
                }

                siteMergedCategoriesTable.Add(apiContext.Site, catCol);

                return catCol;
            }
            else
            {
                return siteMergedCategoriesTable[apiContext.Site] as CategoryTypeCollection;
            }
        }