Esempio n. 1
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);
        }
Esempio n. 2
0
        public void DoRefresh(int id)
        {
            set("processLink", to(Process, id));

            StringBuilder sb = LogCacher.GetNewImportLog("log" + ctx.viewer.Id);
            ImportState   ts = new ImportState();

            ts.TemplateId = id;
            ts.Log        = sb;

            new Thread(ImportUtil.BeginImport).Start(ts);
        }
Esempio n. 3
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;
        }
Esempio n. 4
0
        public static void BeginImport(object param)
        {
            ImportState ts = param as ImportState;

            try {
                beginImportPrivate(ts);
            }
            catch (Exception ex) {
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
                ts.Log.AppendLine(ex.Message);
                ts.Log.AppendLine(ex.StackTrace);

                DbContext.closeConnectionAll();
            }
        }
Esempio n. 5
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();

            }
        }
Esempio n. 6
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();
            }
        }
Esempio n. 7
0
        public virtual void DoRefresh( long id ) {

            set( "processLink", to( Process, id ) );

            StringBuilder sb = LogCacher.GetNewImportLog( "log" + ctx.viewer.Id );
            ImportState ts = new ImportState();
            ts.TemplateId = id;
            ts.Log = sb;

            new Thread( ImportUtil.BeginImport ).Start( ts );
        }