示例#1
0
        public static string HtmlItem(this string defaultVal, string culture, string itemCode, string fieldName, HtmlItemFieldTypes fieldType)
        {
            var htmlItem = ServiceFactory.HtmlItemManager.Get(new HtmlItem()
            {
                Code = itemCode, Culture = culture
            });

            if (htmlItem == null)
            {
                htmlItem = new HtmlItem()
                {
                    Code       = itemCode,
                    Culture    = culture,
                    ItemFields = new List <HtmlItemField>()
                };

                ServiceFactory.HtmlItemManager.Add(htmlItem);
            }

            var field = htmlItem.ItemFields.Where(f => f.FieldName.Equals(fieldName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();


            if (field != null)
            {
                if (fieldType != field.DataType)
                {
                    htmlItem.ItemFields.Remove(field);

                    var newField = new HtmlItemField()
                    {
                        ItemId    = htmlItem.Id,
                        FieldName = fieldName,
                        DataType  = fieldType,
                        DataValue = defaultVal,
                    };

                    htmlItem.ItemFields.Add(newField);

                    ServiceFactory.HtmlItemFieldManager.Update(newField, field);
                }
            }
            else
            {
                var newField = new HtmlItemField()
                {
                    ItemId    = htmlItem.Id,
                    FieldName = fieldName,
                    DataType  = fieldType,
                    DataValue = defaultVal,
                };
                htmlItem.ItemFields.Add(newField);

                ServiceFactory.HtmlItemFieldManager.Add(newField);
            }


            return(htmlItem[fieldName]);
        }
示例#2
0
        public void ImageType_Test()
        {
            var result = new HtmlItem("<img />", MediaTypeNames.Image.Jpeg, "content", "id");

            Assert.AreEqual("<img />", result.Html, "Unexpected html.");
            Assert.AreEqual(MediaTypeNames.Image.Jpeg, result.Type, "Unexpected type.");
            Assert.AreEqual("content", result.Content, "Unexpected content.");
            Assert.AreEqual("id", result.ContentId, "Unexpected content id.");
        }
        public async Task TestParseEventsWeb()
        {
            HtmlItem html = HtmlItemFactory.GetHtmlItem(Constants.LocationType.WEB, "https://theblueshound.com/music-calendar");
            int      i    = await html.GrabAsync();

            var lm = new EventListMaker(html.Html);

            Assert.AreNotEqual(lm, null);
        }
示例#4
0
        public void HtmlType_Test()
        {
            var result = new HtmlItem("Html", MediaTypeNames.Text.Html);

            Assert.AreEqual("Html", result.Html, "Unexpected html.");
            Assert.AreEqual(MediaTypeNames.Text.Html, result.Type, "Unexpected type.");
            Assert.AreEqual(null, result.Content, "Unexpected content.");
            Assert.AreEqual(null, result.ContentId, "Unexpected content id.");
        }
示例#5
0
        public async Task TestEventListMakerFile()
        {
            HtmlItem html = HtmlItemFactory.GetHtmlItem(ContentLib.Constants.LocationType.FILE, @"Cloud\\Classes\\Data\\Events.html");
            int      i    = await html.GrabAsync();

            var lm = new EventListMaker(html.Html);

            Assert.AreNotEqual(lm, null);
        }
示例#6
0
        public async Task TestVenueListMakerWeb()
        {
            HtmlItem html = HtmlItemFactory.GetHtmlItem(ContentLib.Constants.LocationType.WEB, "https://theblueshound.com/venue-listing");
            int      i    = await html.GrabAsync();

            var lm = new VenueListMaker(html.Html);

            Assert.AreNotEqual(lm, null);
        }
示例#7
0
        public List <HtmlItemField> GetByItem(HtmlItem item)
        {
            DbCommand comm = this.GetCommand("HtmlItemField_GetByItem");

            comm.AddParameter <int>(this.Factory, "ItemId", item.Id);

            DataTable dt = this.GetTable(comm);

            return(EntityBase.ParseListFromTable <HtmlItemField>(dt));
        }
示例#8
0
        public ActionResult AjaxForm()
        {
            var model = new HtmlItem();

            if (DoAction == ActionType.Edit)
            {
                model = _da.GetHtmlid(ArrId.FirstOrDefault());
            }
            ViewBag.Action     = DoAction;
            ViewBag.ActionText = ActionText;
            return(View(model));
        }
示例#9
0
        private void QueryHtmlData(object response)
        {
            HtmlItem html = response as HtmlItem;

            if (html == null)
            {
                return;
            }
            lstData.Items.Add(html.Url);
            LoggerWriter.CreateLogFile(html.Html, NowAppDirHelper.GetNowAppDir(AppCategory.WinApp) + "/" + ELogType.HttpResponse.ToString() + "/" + html.Domain, ELogType.HttpResponse);
            //提取索引页码
            //使用xpath <B class=ui-page-s-len>2/100</B>
            Regex           reg = new Regex("<B class=ui-page-s-len>(.+)</B>");//提取符合要求的一段文本
            GroupCollection gc  = reg.Match(html.Html).Groups;

            if (gc.Count <= 1)
            {//第一项为匹配的完整串,第二项为标签内的文本  [2/100]
                return;
            }
            string htmlEle = gc[0].Value; //提取匹配的标签
            Group  g       = gc[1];
            string value   = g.Value;     //提取标签内的内容

            string[] pageInfo = value.Split('/');
            if (pageInfo.Length < 2)
            {
                return;
            }
            int numerator = -1, denominator = -1;

            int.TryParse(pageInfo[0], out numerator);
            if (!int.TryParse(pageInfo[1], out denominator))
            {//转换失败时 设置 参数为-1 避免出现分母为0的情形
                denominator = -1;
            }
            if (numerator >= denominator)
            { //不是查询到尾页
                return;
            }
            numerator++;
            string url = "https://list.tmall.com/search_product.htm?spm=a220m.1000858.1000724.10.4f506713HbGUt4&s={page}&q=%C3%AB%D2%C2&sort=s&style=g&from=mallfp..pc_1_searchbutton&active=2&smAreaId=110106&type=pc#J_Filter";
            // 羽绒服 "https://list.tmall.com/search_product.htm?spm=a220m.1000858.1000724.10.7f5f72ac0cvkWI&s={page}&q=%D3%F0%C8%DE%B7%FE%C4%D0&sort=s&style=g&smAreaId=110106&type=pc";
            int start = numerator * 60;

            url = url.Replace("{page}", start.ToString());
            web.RefreshUrl(url);

            /*
             * js: /<B[^>]*>(.+)<\/B>/
             */
        }
示例#10
0
 void LoadUrlComplateEvent(object data) 
 {
     HtmlItem item = data as HtmlItem;
     if (item != null)
     {
         Init12306Cookie = item;
         string json = item.ConvertJson();
         LoggerWriter.CreateLogFile(json, NowAppDirHelper.GetNowAppDir(AppCategory.WinApp), ELogType.HttpResponse, string.Empty, false, Encoding.UTF8);
     }
     else
     {
         Init12306Cookie = new HtmlItem();
     }
 }
示例#11
0
        public ActionResult EditHtmlItem(HtmlItem model, string returnUrl)
        {
            model.Culture = Culture;
            var item = ServiceFactory.HtmlItemManager.Get(model);

            if (item != null)
            {
                foreach (var field in item.ItemFields)
                {
                    string val = Request[field.FieldName];
                    if (!string.IsNullOrEmpty(val))
                    {
                        field.DataValue = val;
                        field.ItemId    = item.Id;
                        ServiceFactory.HtmlItemFieldManager.Update(field, field);
                    }
                }
            }

            return(Redirect(returnUrl));
        }
示例#12
0
        public ActionResult ViewDetail(int id)
        {
            HtmlItem js = _htmlItemContract.HtmlItems.Where(x => x.Id == id).FirstOrDefault();

            return(PartialView(js));
        }
示例#13
0
 public List <HtmlItemField> GetByItem(HtmlItem item)
 {
     return(HtmlItemFieldProvider.GetByItem(item));
 }
示例#14
0
        public ActionResult View(int id)
        {
            HtmlItem htmlItem = _htmlItemContract.View(id);

            return(PartialView(htmlItem));
        }