public int GetMaxId() { using (LiGatherContext _db = new LiGatherContext()) { return(_db.ProxyEntities.Max(t => t.Id)); } }
public TaskStateDic Get(Expression <Func <TaskStateDic, bool> > expression) { using (LiGatherContext _db = new LiGatherContext()) { return(_db.TaskStateDics.SingleOrDefault(expression)); } }
public int GetMaxId() { using (LiGatherContext _db = new LiGatherContext()) { return _db.ProxyEntities.Max(t => t.Id); } }
public List <CrawlerEntity> Get(Expression <Func <CrawlerEntity, bool> > expression) { using (LiGatherContext db = new LiGatherContext()) { return(db.CrawlerEntities.Where(expression).ToList()); } }
/// <summary> /// 按照条件获取数据和 /// </summary> /// <param name="where"></param> /// <returns></returns> public int GetInt(Expression<Func<TargeCompanyEntity, bool>> where) { using (LiGatherContext _db = new LiGatherContext()) { return _db.TrCompanyEntities.Count(where); } }
public TaskStateDic Get(Expression<Func<TaskStateDic, bool>> expression) { using (LiGatherContext _db = new LiGatherContext()) { return _db.TaskStateDics.SingleOrDefault(expression); } }
public bool IsExist(ProxyEntity model) { using (LiGatherContext _db = new LiGatherContext()) { return _db.ProxyEntities.Any(t => t.IpAddress == model.IpAddress); } }
public bool IsExist(ProxyEntity model) { using (LiGatherContext _db = new LiGatherContext()) { return(_db.ProxyEntities.Any(t => t.IpAddress == model.IpAddress)); } }
public ProxyEntity GetById(int id) { using (LiGatherContext _db = new LiGatherContext()) { return(_db.ProxyEntities.OrderBy(t => t.LastUseTime).SingleOrDefault(t => t.Id == id)); } }
public ProxyEntity GetById(int id) { using (LiGatherContext _db = new LiGatherContext()) { return _db.ProxyEntities.OrderBy(t => t.LastUseTime).SingleOrDefault(t => t.Id == id); } }
/// <summary> /// 按照条件获取数据和 /// </summary> /// <param name="where"></param> /// <returns></returns> public int GetInt(Expression <Func <TargeCompanyEntity, bool> > where) { using (LiGatherContext _db = new LiGatherContext()) { return(_db.TrCompanyEntities.Count(where)); } }
public ProxyEntity Get(ProxyEntity model) { using (LiGatherContext _db = new LiGatherContext()) { return _db.ProxyEntities.SingleOrDefault(t => t.Id == model.Id); } }
public List<CrawlerEntity> Get(Expression<Func<CrawlerEntity, bool>> expression) { using (LiGatherContext db = new LiGatherContext()) { return db.CrawlerEntities.Where(expression).ToList(); } }
public ProxyEntity Get(ProxyEntity model) { using (LiGatherContext _db = new LiGatherContext()) { return(_db.ProxyEntities.SingleOrDefault(t => t.Id == model.Id)); } }
public void Add(ProxyEntity model) { using (LiGatherContext _db = new LiGatherContext()) { _db.ProxyEntities.Add(model); _db.SaveChanges(); } }
public void Add(TaskEntity model) { using (LiGatherContext _db = new LiGatherContext()) { _db.TaskEntities.Add(model); _db.SaveChanges(); } }
public void Update(ProxyEntity model) { using (LiGatherContext _db = new LiGatherContext()) { _db.ProxyEntities.AddOrUpdate(model); _db.SaveChanges(); } }
public void Update(TargeCompanyEntity model) { using (LiGatherContext _db = new LiGatherContext()) { _db.TrCompanyEntities.AddOrUpdate(model); _db.SaveChanges(); } }
public List<QgOrgCodeEntity> Get(Expression<Func<QgOrgCodeEntity, bool>> expression) { lock (_obj) { using (LiGatherContext db = new LiGatherContext()) { return db.QgOrgCodeEntities.Where(expression).ToList(); } } }
public List <QgOrgCodeEntity> Get(Expression <Func <QgOrgCodeEntity, bool> > expression) { lock (_obj) { using (LiGatherContext db = new LiGatherContext()) { return(db.QgOrgCodeEntities.Where(expression).ToList()); } } }
public List<TaskEntity> Get(Expression<Func<TaskEntity, bool>> expression = null) { using (LiGatherContext _db = new LiGatherContext()) { if (expression != null) return _db.TaskEntities.Include(t => t.TaskStateDic).Where(expression).ToList(); else return _db.TaskEntities.Include(t => t.TaskStateDic).ToList(); } }
public ProxyEntity GetByRandom() { using (LiGatherContext db = new LiGatherContext()) { //随机取 //var idLists = _db.ProxyEntities.Where(t => t.CanUse == true).Select(t => t.Id).ToList(); //var id = new Random().Next(0, idLists.Count); return(db.ProxyEntities.Where(t => t.CanUse.Value).OrderByDescending(t => t.LastUseTime).FirstOrDefault()); } }
public ProxyEntity GetByRandom() { using (LiGatherContext db = new LiGatherContext()) { //随机取 //var idLists = _db.ProxyEntities.Where(t => t.CanUse == true).Select(t => t.Id).ToList(); //var id = new Random().Next(0, idLists.Count); return db.ProxyEntities.Where(t => t.CanUse.Value).OrderByDescending(t => t.LastUseTime).FirstOrDefault(); } }
/// <summary> /// 写入新内容,若是存在就不写入 /// </summary> /// <param name="model"></param> public void Add(CrawlerEntity model) { using (LiGatherContext db = new LiGatherContext()) { if (!db.CrawlerEntities.Any(t => t.搜索名称.Equals(model.搜索名称))) { db.CrawlerEntities.Add(model); db.SaveChanges(); } } }
public void Add(LogEntity model) { lock (_obj) { using (LiGatherContext db = new LiGatherContext()) { db.LogEntities.AddOrUpdate(model); db.SaveChanges(); } } }
/// <summary> /// 获取一个非以查询,非异常状态的企业实体,同时更新为已搜索状态 /// </summary> /// <returns></returns> public TargeCompanyEntity GetSingel(Expression<Func<TargeCompanyEntity, bool>> where) { using (LiGatherContext _db = new LiGatherContext()) { var model = _db.TrCompanyEntities.Where(where).FirstOrDefault(t => t.IsSearched == false); if (model != null) { model.IsSearched = true; Update(model); } return model; } }
/// <summary> /// 获取一个非以查询,非异常状态的企业实体,同时更新为已搜索状态 /// </summary> /// <returns></returns> public TargeCompanyEntity GetSingel(Expression <Func <TargeCompanyEntity, bool> > where) { using (LiGatherContext _db = new LiGatherContext()) { var model = _db.TrCompanyEntities.Where(where).FirstOrDefault(t => t.IsSearched == false); if (model != null) { model.IsSearched = true; Update(model); } return(model); } }
public List <TaskEntity> Get(Expression <Func <TaskEntity, bool> > expression = null) { using (LiGatherContext _db = new LiGatherContext()) { if (expression != null) { return(_db.TaskEntities.Include(t => t.TaskStateDic).Where(expression).ToList()); } else { return(_db.TaskEntities.Include(t => t.TaskStateDic).ToList()); } } }
public void Add(QgOrgCodeEntity entity) { lock (_obj) { using (LiGatherContext db = new LiGatherContext()) { if (!db.QgOrgCodeEntities.Any(t => t.companyName.Equals(entity.companyName))) { db.QgOrgCodeEntities.Add(entity); db.SaveChanges(); } } } }
public void LockUpdate(ProxyEntity model) { using (LiGatherContext _db = new LiGatherContext()) { var proxyEntity = _db.ProxyEntities.Where(t => t.Id == model.Id && t.CanUse == true).ToList(); if (!proxyEntity.Any()) return; _db.ProxyEntities.AddOrUpdate(model); var i = _db.SaveChanges(); if (i == 0) { Console.WriteLine("EF 内存泄露,启动清扫策略。"); //日志记录 new LogDomain().Add(new LogEntity { ErrorDetails = "EF 内存泄露,启动清扫策略。", TriggerTime = DateTime.Now }); _db.Database.ExecuteSqlCommand("update ProxyEntity set CanUse=0 where CanUse!=0"); } Console.WriteLine("移除失效代理:{0}:{1}", model.IpAddress, model.Port); } }
public void LockUpdate(ProxyEntity model) { using (LiGatherContext _db = new LiGatherContext()) { var proxyEntity = _db.ProxyEntities.Where(t => t.Id == model.Id && t.CanUse == true).ToList(); if (!proxyEntity.Any()) { return; } _db.ProxyEntities.AddOrUpdate(model); var i = _db.SaveChanges(); if (i == 0) { Console.WriteLine("EF 内存泄露,启动清扫策略。"); //日志记录 new LogDomain().Add(new LogEntity { ErrorDetails = "EF 内存泄露,启动清扫策略。", TriggerTime = DateTime.Now }); _db.Database.ExecuteSqlCommand("update ProxyEntity set CanUse=0 where CanUse!=0"); } Console.WriteLine("移除失效代理:{0}:{1}", model.IpAddress, model.Port); } }