public Result CopySpider(string orientSpiderName) { return(Constraints.ServiceContext.ServiceDelegator.HandleTransactionEvent(Constraints.DbName, (session) => { //配置文件新增 var config = ConfigOfSpiders.Configs.First(c => c.SpiderName == orientSpiderName).Clone(); config.SpiderName = GetAvailableSpiderName(orientSpiderName); //数据库新增 var spider = new TSpider(); if (spider.Create(session, config.SpiderName)) { //配置文件新增 ConfigOfSpiders.Configs.Add(config); //缓存新增 Spiders.Add(spider); ////变更当前选项 //ConfigOfSpiders.LatestSpiderConfigName = config.SpiderName; //ChangeCurrentSpider(spider.SpiderName); ConfigOfSpiders.Save(); return new Result() { ResultCode = EResultCode.Success }; } else { return new Result() { ResultCode = EResultCode.Failure }; } })); }
public Result <TSpider> AddSpider(string spiderName, bool addByEnter = false) { return(Constraints.ServiceContext.ServiceDelegator.HandleTransactionEvent(Constraints.DbName, (session) => { //数据库新增 var spider = new TSpider(); if (spider.Create(session, spiderName)) { //配置文件新增 var newSpiderConfig = new ConfigOfSpider(spiderName); if (addByEnter) { ConfigOfSpiders.Configs.Add(newSpiderConfig); } ConfigOfSpiders.LatestSpiderConfigName = spiderName; //变更当前选项 Spiders.Add(spider); ChangeCurrentSpider(spider.SpiderName); ConfigOfSpiders.Save(); return new Result <TSpider>() { Data = spider, ResultCode = EResultCode.Success }; } else { return new Result <TSpider>() { ResultCode = EResultCode.Failure }; } })); }