public Result <ConfigOfSpider> DeleteSpider(string spiderName) { return(Constraints.ServiceContext.ServiceDelegator.HandleTransactionEvent(Constraints.DbName, (session) => { var config = ConfigOfSpiders.Configs.First(c => c.SpiderName == spiderName); var spider = Spiders.First(c => c.SpiderName == config.SpiderName); if (spider.DbDelete(session)) { //配置文件删除 ConfigOfSpiders.Configs.Remove(config); //缓存删除 Spiders.Remove(spider); //变更当前选项 var currentSpider = ConfigOfSpiders.Configs.LastOrDefault(); if (currentSpider != null) { ChangeCurrentSpider(currentSpider.SpiderName); } ConfigOfSpiders.Save(); return new Result <ConfigOfSpider>() { ResultCode = EResultCode.Success, Data = currentSpider == null ? new ConfigOfSpider("") : currentSpider }; } else { return new Result <ConfigOfSpider>() { ResultCode = EResultCode.Failure }; } })); }
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 ChangeCurrentSpiderName(string spiderName) { return(Constraints.ServiceContext.ServiceDelegator.HandleTransactionEvent(Constraints.DbName, (session) => { var config = ConfigOfSpiders.Configs.First(c => c.SpiderName == CurrentConfigOfSpider.SpiderName); var spider = Spiders.First(c => c.SpiderName == CurrentConfigOfSpider.SpiderName); if (spider.ChangeName(session, spiderName)) { //配置文件变更 config.SpiderName = spiderName; //最后选项变更 ConfigOfSpiders.LatestSpiderConfigName = 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 }; } })); }
public Result Init() { //检测服务依赖项 var checkResult = Constraints.CheckNodeReferences(); if (!checkResult.IsAllDependenciesAvailable) { return(new Result() { ResultCode = EResultCode.Error, Message = checkResult.Message, }); } //没有配置文件时初始化生成 if (!File.Exists(ConfigOfSpiders.OutputFilePath)) { ConfigOfSpiders.Save(); } //加载所有配置 ConfigOfSpiders.Load(); var loadResult = LoadSpiders(); if (loadResult.ResultCode != EResultCode.Success) { return(loadResult); } var spiderName = ConfigOfSpiders.LatestSpiderConfigName; if (ChangeCurrentSpider(ConfigOfSpiders.LatestSpiderConfigName).ResultCode != EResultCode.Success) { new Result <bool>() { ResultCode = EResultCode.Error, Message = "更改当前的TSpider时出错" }; } return(new Result <bool>() { ResultCode = EResultCode.Success, }); }