예제 #1
0
        /// <summary>
        /// 获取商城最近更新的产品
        /// </summary>
        public void LoadUpdateItems()
        {
            GomeCpsApi gmApi = new GomeCpsApi();
            gmApi.UpdateStartDate = DateTime.Now;
            gmApi.Format = "json";

            int proTotal = 0;

            do
            {
                string url = gmApi.GetUpdateItemsUrl();
                string catList = HtmlAnalysis.Gethtmlcode(url);
                if (proTotal == 0)
                    proTotal = RegGroupsX<int>(catList, "\"total_count\":(?<x>\\d+)");
                if (catList.IndexOf("items", StringComparison.Ordinal) < 0 || catList.IndexOf('}') == -1)
                {
                    LogServer.WriteLog("apiUrl:" + url + "\tcatList" + catList, "ApiError");
                    gmApi.PageNo++;
                    proTotal = proTotal - gmApi.PageSize;
                    continue;
                }
                catList = catList.Substring(catList.IndexOf("items", StringComparison.Ordinal) + 7).TrimEnd('}');
                var proList = ServiceStack.Text.JsonSerializer.DeserializeFromString<List<ItemEF>>(catList);
                AddProInfo(proList);
                gmApi.PageNo++;
                proTotal = proTotal - gmApi.PageSize;
            } while (proTotal > 0);
            gmApi.PageNo = 1;
        }
예제 #2
0
 private void getProBySkuid(string skuid)
 {
     GomeCpsApi gmApi = new GomeCpsApi();
     gmApi.SkuId = skuid;
     string url = gmApi.GetAllItemsUrl();
     string catList = HtmlAnalysis.Gethtmlcode(url);
 }
예제 #3
0
        public void SaveAllSiteClass()
        {
            GomeCpsApi gmApi = new GomeCpsApi();
            HasBindClasslist = new SiteClassInfoDB().getAllSiteCatInfo(Baseinfo.SiteId);
            gmApi.Format = "json";
            string urlclass = gmApi.GetCategorysurl();

            string catResult = HtmlAnalysis.Gethtmlcode(urlclass);
            catResult = catResult.Substring("{\"categorys\":".Length);
            catResult = catResult.Substring(0, catResult.Length - 1);
            var catList = ServiceStack.Text.JsonSerializer.DeserializeFromString<List<CategoryEF>>(catResult);

            foreach (var cat in catList)
            {
                if (HasBindClasslist.Exists(p => p.ClassId == cat.category_id))
                    continue;

                if (!ValidCatId(cat.category_id))
                {
                    LogServer.WriteLog("ClassId:" + cat.category_id + "验证失败\turl:" + urlclass, "AddClassError");
                    return;
                }

                SiteClassInfo preclassinfo = new SiteClassInfo();
                preclassinfo.ClassName = cat.category_name;
                preclassinfo.ClassId = cat.category_id;
                preclassinfo.SiteId = Baseinfo.SiteId;
                preclassinfo.Urlinfo = "http://www.gome.com.cn/category/" + cat.category_id + ".html";
                if (cat.parent_id != "")
                    preclassinfo.ParentUrl = "http://www.gome.com.cn/category/" + cat.parent_id + ".html";
                if (cat.category_grade == "3")
                    preclassinfo.HasChild = false;
                else
                    preclassinfo.HasChild = true;
                preclassinfo.ParentClass = cat.parent_id;
                preclassinfo.IsDel = false;
                preclassinfo.CreateDate = DateTime.Now;
                preclassinfo.UpdateTime = DateTime.Now;
                HasBindClasslist.Add(preclassinfo);
                shopClasslist.Add(preclassinfo);
                if (shopClasslist.Count > 100)
                {
                    new SiteClassInfoDB().AddSiteClass(shopClasslist);
                    shopClasslist.Clear();
                }

            }
            if (shopClasslist.Count > 0)
            {
                new SiteClassInfoDB().AddSiteClass(shopClasslist);
                shopClasslist.Clear();
            }
        }