Exemplo n.º 1
0
        /// <summary>
        /// 批量保存数据,在保存之前会根据isExistFields参数值判断该条数据是否重复
        /// </summary>
        /// <param name="entityList"></param>
        /// <param name="isExistFields">如不需要判断是否存在数据,则该参数值为null或空字符串</param>
        /// <returns></returns>
        public static int SaveDatas(IList entityList, string isExistFields)
        {
            if (entityList == null || entityList.Count < 1)
            {
                return(0);
            }
            int success = 0;

            object[] successList;
            success = ToolCoreDb.SaveDatas(entityList, isExistFields, new List <BaseAttach>(), out successList, true, false, false);
            return(success);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据反射,从实体中调用方法,得到返回结果
        /// </summary>
        /// <param name="assemblyPath"></param>
        /// <param name="entityFullName"></param>
        /// <param name="crawlAll">是否抓取所有数据</param>
        /// <returns></returns>
        public static string DealEntity(WebSiteCrawller crawller)
        {
            StringBuilder result = new StringBuilder();

            try
            {
                //处理信息
                IList infoList = crawller.Crawl(false);
                if (infoList != null && infoList.Count > 0)
                {
                    object[]          successList;
                    List <BaseAttach> tattachList = crawller.AttachList;

                    int count = ToolCoreDb.SaveDatas(infoList, crawller.ExistCompareFields, tattachList, out successList, crawller.ExistsUpdate, crawller.ExistsHtlCtx, crawller.ExistsUpdateAttach);
                    result.Append("【").Append(crawller.Title).Append("】信息【").Append(count).Append("/").Append(infoList.Count).Append("】条;");
                    Base.KdService.CrawlerService ser = new Base.KdService.CrawlerService();
                    int resultCount;
                    //处理附件
                    List <BaseAttach> newAttachList = new List <BaseAttach>();
                    if (crawller.ExistsUpdateAttach)
                    {
                        if (infoList != null && infoList.Count > 0)
                        {
                            List <BaseAttach> attch = null;
                            foreach (var item in infoList)
                            {
                                Type   types = item.GetType();
                                string id    = types.GetProperty("Id").GetValue(item, null).ToString();
                                attch = tattachList.FindAll(a => a.SourceID == id);
                                for (int i = 0; i < attch.Count; i++)
                                {
                                    newAttachList.Add(attch[i]);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (successList != null && successList.Length > 0)
                        {
                            List <BaseAttach> attch = null;
                            foreach (var item in successList)
                            {
                                Type   types = item.GetType();
                                string id    = types.GetProperty("Id").GetValue(item, null).ToString();
                                attch = tattachList.FindAll(a => a.SourceID == id);
                                for (int i = 0; i < attch.Count; i++)
                                {
                                    newAttachList.Add(attch[i]);
                                }
                            }
                        }
                    }

                    count = ToolCoreDb.SaveDatas(newAttachList, "SourceID,AttachServerPath");
                    result.Append("附件【").Append(count).Append("/").Append(tattachList.Count).Append("】条;");
                    crawller.AttachList.Clear();
                }
                else
                {
                    result.Append("【").Append(crawller.Title).Append("】信息【").Append("0").Append("/").Append("0").Append("】条;");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                result.Remove(0, result.Length);
                result.Append("抓取【").Append(crawller.Title).Append("】出现异常,详见日志文件!");
            }

            return(result.ToString());
        }