示例#1
0
        public virtual void Delete(long id)
        {
            SpiderImport s = SpiderImport.findById(id);

            s.IsDelete = 1;
            s.update("IsDelete");
        }
示例#2
0
        public virtual void Delete(long id)
        {
            SpiderImport item = importService.GetById(id);

            item.delete();
            redirect(List);
        }
示例#3
0
        private static int importDirect(SpiderArticle art, SpiderImport item, ContentSection section, ContentApp app)
        {
            ContentPost post = new ContentPost();

            post.Title   = art.Title;
            post.Content = art.Body;

            if (art.IsPic == 1)
            {
                post.CategoryId = PostCategory.Img;
                post.ImgLink    = art.PicUrl;
            }

            post.SourceLink = art.Url;

            post.Creator     = item.Creator;
            post.CreatorUrl  = item.Creator.Url;
            post.PageSection = section;
            post.OwnerId     = app.OwnerId;
            post.OwnerType   = app.OwnerType;
            post.OwnerUrl    = app.OwnerUrl;
            post.AppId       = app.Id;

            post.insert();
            return(post.Id);
        }
示例#4
0
        public void Delete(int id)
        {
            SpiderImport item = importService.GetById(id);

            item.delete();
            redirect(List);
        }
        public void Delete(int id)
        {
            SpiderImport s = SpiderImport.findById(id);

            s.IsDelete = 1;
            s.update("IsDelete");
        }
示例#6
0
        public void Stop(int id)
        {
            SpiderImport item = importService.GetById(id);

            item.IsDelete = 1;
            item.update("IsDelete");
            echoAjaxOk();
        }
        private string getImportDescription( SpiderImport it, List<SpiderTemplate> dataSrc ) {

            StringBuilder sb = getDataSrcInfo( it, dataSrc );
            sb.Append( " --> " );
            sb.Append( getTargetInfo( it ) );

            return sb.ToString();
        }
示例#8
0
        public virtual void Start(long id)
        {
            SpiderImport item = importService.GetById(id);

            item.IsDelete = 0;
            item.update("IsDelete");
            echoAjaxOk();
        }
示例#9
0
        private static List <long> beginImportPrivate(ImportState ts)
        {
            long id = ts.TemplateId;

            SpiderImport item = SpiderImport.findById(id);

            List <SpiderArticle> articles = SpiderArticle
                                            .find("SpiderTemplateId in (" + item.DataSourceIds + ") and Id>" + item.LastImportId + " order by Id")
                                            .list();

            List <ContentSection> sections = ContentSection.find("Id in (" + item.SectionIds + ")").list();

            if (sections.Count == 0)
            {
                throw new Exception("导入的目标section不存在");
            }

            ContentSection section = null;
            List <long>    results = new List <long>();

            for (int i = 0; i < articles.Count; i++)
            {
                if (articleExist(articles[i]))
                {
                    ts.Log.AppendLine("pass..." + articles[i].Title);
                    continue;
                }

                section = getNextSection(sections, section);   // 均匀分散到各目标section中
                ContentApp app = getApp(section);

                if (item.IsApprove == 1)
                {
                    importToTemp(articles[i], item, section, app);
                }
                else
                {
                    long newArticleId = importDirect(articles[i], item, section, app);
                    results.Add(newArticleId);
                }

                ts.Log.AppendLine("导入:" + articles[i].Title);
            }

            if (articles.Count > 0)
            {
                item.LastImportId = articles[articles.Count - 1].Id;
                item.update("LastImportId");
                ts.Log.AppendLine("导入完毕(操作结束)");
            }
            else
            {
                ts.Log.AppendLine("没有新条目可导入(操作结束)");
            }


            return(results);
        }
示例#10
0
        private string getImportDescription(SpiderImport it, List <SpiderTemplate> dataSrc)
        {
            StringBuilder sb = getDataSrcInfo(it, dataSrc);

            sb.Append(" --> ");
            sb.Append(getTargetInfo(it));

            return(sb.ToString());
        }
示例#11
0
        public ImportJson( SpiderImport it ) {

            this.Id = it.Id;
            this.Name = it.Name;
            this.DataSrcIds = cvtToString( it.DataSourceIds );
            this.TargetIds = cvtToString( it.SectionIds );
            this.Creator = it.Creator.Name;
            this.IsApprove = it.IsApprove == 1;
        }
示例#12
0
 public ImportJson(SpiderImport it)
 {
     this.Id         = it.Id;
     this.Name       = it.Name;
     this.DataSrcIds = cvtToString(it.DataSourceIds);
     this.TargetIds  = cvtToString(it.SectionIds);
     this.Creator    = it.Creator.Name;
     this.IsApprove  = it.IsApprove == 1;
 }
示例#13
0
        public void Save()
        {
            int    id        = ctx.PostInt("Id");
            int    isApprove = ctx.PostInt("isApprove");
            String name      = ctx.Post("name");
            String srcIds    = ctx.PostIdList("srcIds");
            String targetIds = ctx.PostIdList("targetIds");
            String userName  = ctx.Post("userName");

            if (strUtil.IsNullOrEmpty(name))
            {
                errors.Add("请填写名称");
            }
            if (strUtil.IsNullOrEmpty(srcIds))
            {
                errors.Add("请选择数据源");
            }
            if (strUtil.IsNullOrEmpty(targetIds))
            {
                errors.Add("请选择目标区块");
            }

            User user = userService.GetByName(userName);

            if (user == null)
            {
                errors.Add("用户不存在");
            }

            if (ctx.HasErrors)
            {
                echoError();
                return;
            }

            SpiderImport it = id > 0 ? importService.GetById(id) : new SpiderImport();

            it.Name          = name;
            it.DataSourceIds = srcIds;
            it.SectionIds    = targetIds;
            it.IsApprove     = isApprove;
            it.Creator       = user;

            if (id > 0)
            {
                it.update();
            }
            else
            {
                it.insert();
            }

            echoJsonMsg("操作成功", true, null);
        }
示例#14
0
        public void Show(int id)
        {
            SpiderImport item = importService.GetById(id);

            List <SpiderTemplate> dataSrc = templateService.GetAll();

            set("item.ApproveInfo", item.IsApprove == 1 ? "需要审核" : "不需要");
            bind("item", item);

            set("item.DataSourceInfo", getDataSrcInfo(item, dataSrc));
            set("item.TargetInfo", getTargetInfo(item));

            set("editUrl", to(Add, id));
        }
示例#15
0
        private StringBuilder getTargetInfo(SpiderImport it)
        {
            StringBuilder         sb       = new StringBuilder();
            List <ContentSection> sections = ContentSection.find("Id in (" + it.SectionIds + ")").list();

            for (int i = 0; i < sections.Count; i++)
            {
                sb.Append(sections[i].Title);
                if (i < sections.Count - 1)
                {
                    sb.Append(",");
                }
            }
            return(sb);
        }
示例#16
0
        private StringBuilder getDataSrcInfo(SpiderImport it, List <SpiderTemplate> dataSrc)
        {
            StringBuilder sb = new StringBuilder();

            int[] arrSrc = cvt.ToIntArray(it.DataSourceIds);
            for (int i = 0; i < arrSrc.Length; i++)
            {
                sb.Append(getTemplateName(arrSrc[i], dataSrc));
                if (i < arrSrc.Length - 1)
                {
                    sb.Append(",");
                }
            }

            return(sb);
        }
示例#17
0
        private static int importToTemp(SpiderArticle art, SpiderImport item, ContentSection section, ContentApp app)
        {
            ContentTempPost post = new ContentTempPost();

            post.Creator   = item.Creator;
            post.OwnerId   = app.OwnerId;
            post.OwnerType = app.OwnerType;
            post.AppId     = app.Id;
            post.SectionId = section.Id;

            post.Title      = art.Title;
            post.SourceLink = art.Url;
            post.Content    = art.Body;

            post.insert();

            return(post.Id);
        }
示例#18
0
        public void Add(int id)
        {
            if (id > 0)
            {
                SpiderImport item = importService.GetById(id);
                if (item == null)
                {
                    echoRedirect(lang("exDataNotFound"));
                    return;
                }
                set("itemJson", Json.ToString(new ImportJson(item)));
            }
            else
            {
                set("itemJson", "{Id:0}");
            }

            set("step3Action", to(Save));
            set("returnUrl", to(List));

            List <SpiderTemplate> list = templateService.GetAll();

            checkboxList("dataSrc", list, "SiteName=Id", null);

            //dataTarget
            List <ContentApp> apps  = ContentApp.find("OwnerType=:otype").set("otype", typeof(Site).FullName).list();
            IBlock            block = getBlock("apps");

            foreach (ContentApp app in apps)
            {
                block.Set("appId", app.Id);

                IMemberApp ma = appService.GetByApp(app);
                if (ma == null)
                {
                    continue;
                }

                block.Set("appName", ma.Name);
                List <ContentSection> sections = ContentSection.find("AppId=" + app.Id).list();
                block.Set("dataTarget", Html.CheckBoxList(sections, "dataTarget", "Title", "Id", null));
                block.Next();
            }
        }
示例#19
0
        public void Execute()
        {
            List <SpiderImport> items = SpiderImport.find("IsDelete=0").list();

            DbContext.closeConnectionAll();
            logger.Info("begin ImportJob=" + items.Count);

            StringBuilder log = new StringBuilder();

            foreach (SpiderImport item in items)
            {
                ImportState ts = new ImportState();
                ts.TemplateId = item.Id;
                ts.Log        = log;

                ImportUtil.BeginImport(ts);

                DbContext.closeConnectionAll();
            }
        }
示例#20
0
        public virtual void SaveSort()
        {
            int    id  = ctx.PostInt("id");
            String cmd = ctx.Post("cmd");

            SpiderImport        s    = importService.GetById(id);
            List <SpiderImport> list = importService.GetAll();

            if (cmd == "up")
            {
                new SortUtil <SpiderImport>(s, list).MoveUp();
                echoJsonOk();
            }
            else if (cmd == "down")
            {
                new SortUtil <SpiderImport>(s, list).MoveDown();
                echoJsonOk();
            }
            else
            {
                echoError(lang("exUnknowCmd"));
            }
        }
示例#21
0
 public virtual SpiderImport GetById(long id)
 {
     return(SpiderImport.findById(id));
 }
示例#22
0
        private StringBuilder getDataSrcInfo( SpiderImport it, List<SpiderTemplate> dataSrc ) {
            StringBuilder sb = new StringBuilder();
            int[] arrSrc = cvt.ToIntArray( it.DataSourceIds );
            for (int i = 0; i < arrSrc.Length; i++) {
                sb.Append( getTemplateName( arrSrc[i], dataSrc ) );
                if (i < arrSrc.Length - 1) sb.Append( "," );
            }

            return sb;
        }
示例#23
0
 private StringBuilder getTargetInfo( SpiderImport it ) {
     StringBuilder sb = new StringBuilder();
     List<ContentSection> sections = ContentSection.find( "Id in (" + it.SectionIds + ")" ).list();
     for (int i = 0; i < sections.Count; i++) {
         sb.Append( sections[i].Title );
         if (i < sections.Count - 1) sb.Append( "," );
     }
     return sb;
 }
示例#24
0
 public void Update( SpiderImport s )
 {
     s.update();
 }
示例#25
0
 public void Insert( SpiderImport s )
 {
     s.insert();
 }
示例#26
0
        private static int importToTemp( SpiderArticle art, SpiderImport item, ContentSection section, ContentApp app )
        {
            ContentTempPost post = new ContentTempPost();
            post.Creator = item.Creator;
            post.OwnerId = app.OwnerId;
            post.OwnerType = app.OwnerType;
            post.AppId = app.Id;
            post.SectionId = section.Id;

            post.Title = art.Title;
            post.SourceLink = art.Url;
            post.Content = art.Body;

            post.insert();

            return post.Id;
        }
示例#27
0
        private static int importDirect( SpiderArticle art, SpiderImport item, ContentSection section, ContentApp app )
        {
            ContentPost post = new ContentPost();
            post.Title = art.Title;
            post.Content = art.Body;

            if (art.IsPic == 1) {
                post.CategoryId = PostCategory.Img;
                post.ImgLink = art.PicUrl;
            }

            post.SourceLink = art.Url;

            post.Creator = item.Creator;
            post.CreatorUrl = item.Creator.Url;
            post.PageSection = section;
            post.OwnerId = app.OwnerId;
            post.OwnerType = app.OwnerType;
            post.OwnerUrl = app.OwnerUrl;
            post.AppId = app.Id;

            post.insert();
            return post.Id;
        }
 public List <SpiderImport> GetAll()
 {
     return(SpiderImport.find("order by OrderId desc, Id asc").list());
 }
 public void Update(SpiderImport s)
 {
     s.update();
 }
 public void Insert(SpiderImport s)
 {
     s.insert();
 }
 public SpiderImport GetById(int id)
 {
     return(SpiderImport.findById(id));
 }