示例#1
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;
		}
示例#3
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);
        }
示例#4
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);
        }
        //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);
        }
		/// <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;
		}
		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;
		}
示例#8
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;
            }
        }
		//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;
		}
示例#10
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;

               }
        }
示例#11
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;
        }