/// <summary> /// 按价格随机筛选一个元素 /// </summary> /// <param name="count">数量</param> /// <param name="type">广告类型</param> /// <param name="cid">分类id</param> /// <returns></returns> public List <Advertisement> GetsByWeightedPrice(int count, AdvertiseType type, int?cid = null) { Expression <Func <Advertisement, bool> > where = a => a.Types.Contains(type.ToString("D")) && a.Status == Status.Available; if (cid.HasValue) { var scid = cid.ToString(); if (ValueCacheManager.GetOrAdd(scid, s => Any(a => a.CategoryIds.Contains(scid)))) { where = where.And(a => a.CategoryIds.Contains(scid) || string.IsNullOrEmpty(a.CategoryIds)); } else { where = where.And(a => string.IsNullOrEmpty(a.CategoryIds)); } } return(CacheManager.GetOrAdd($"{count}{type}{cid}", _ => { var list = GetQuery(@where).AsEnumerable().Select(a => new WeightedItem <Advertisement>(a, (int)a.Price)).WeightedItems(count); foreach (var item in list) { item.DisplayCount += 1; } SaveChanges(); return list; })); }
public List <int> GetAdvCountInSpecialMounthAsync(int dayCount, AdvertiseType type) { try { var lstReturn = new List <int>(); var firstDate = DateTime.Now.AddDays(-dayCount); var secondDate = DateTime.Now; using (var contex = new dbContext()) { for (var i = firstDate; i <= secondDate; i = i.AddDays(1)) { var counter = 0; var strI = DateConvertor.M2SH(i); if (type != AdvertiseType.All) { counter = contex.AdvertiseLog.AsNoTracking() .Count(q => q.DateSabt == strI && q.AdvType == type); } else { counter = contex.AdvertiseLog.AsNoTracking() .Count(q => q.DateSabt == strI); } lstReturn.Add(counter); } } return(lstReturn); } catch (Exception ex) { WebErrorLog.ErrorInstence.StartErrorLog(ex); return(null); } }
private async Task LoadData(AdvertiseType type, string search = "") { try { if (type == AdvertiseType.Divar) { var list = await DivarCityBussines.GetAllAsync(search); DivarBindingSource.DataSource = list.OrderBy(q => q.Name).Where(q => q.Status).ToList(); lblCounter.Text = DivarBindingSource.Count.ToString(); } else if (type == AdvertiseType.Sheypoor) { var list = await SheypoorCityBussines.GetAllAsync(search); SheypoorBindingSource.DataSource = list.OrderBy(q => q.Name).Where(q => q.Status).ToList(); lblCounter.Text = SheypoorBindingSource.Count.ToString(); } } catch (Exception e) { WebErrorLog.ErrorInstence.StartErrorLog(e); } }
private static List <AdvertiseViewModel> ConvertToViewModel(List <Advertise> entities) { List <AdvertiseViewModel> viewModels = new List <AdvertiseViewModel>(); List <string> idtypes = entities.Select(mod => { return(mod.idat); }).ToList(); idtypes = idtypes.Distinct().ToList(); TN db = new TN(); List <AdvertiseType> advertiseTypes = db.AdvertiseTypes.Where(en => idtypes.Contains(en.idat)).ToList(); viewModels = entities.Select(mod => { AdvertiseViewModel viewModel = new AdvertiseViewModel(); viewModel.CopyFromBase(mod); if (advertiseTypes != null && advertiseTypes.Count > 0) { List <AdvertiseType> tempAdvertiseTypes = advertiseTypes.Where(en => en.idat == viewModel.idat).ToList(); AdvertiseType tempAdvertiseType = (tempAdvertiseTypes != null && tempAdvertiseTypes.Count > 0) ? tempAdvertiseTypes.First() : null; AdvertiseTypeViewModel tempAdvertiseTypeModel = new AdvertiseTypeViewModel(); if (tempAdvertiseType != null) { tempAdvertiseTypeModel.CopyFromBase(tempAdvertiseType); viewModel.AdvertiseType = tempAdvertiseTypeModel; } } return(viewModel); }).ToList(); return(viewModels); }
/// <summary> /// 按价格随机筛选一个元素 /// </summary> /// <param name="count">数量</param> /// <param name="type">广告类型</param> /// <param name="cid">分类id</param> /// <returns></returns> public List <Advertisement> GetsByWeightedPrice(int count, AdvertiseType type, IPLocation ipinfo, int?cid = null) { var(location, _, _) = ipinfo; return(CacheManager.GetOrAdd($"Advertisement:{location.Crc32()}:{type}:{count}-{cid}", _ => { var atype = type.ToString("D"); Expression <Func <Advertisement, bool> > where = a => a.Types.Contains(atype) && a.Status == Status.Available; var catCount = CategoryRepository.Count(_ => true); where = where.And(a => a.RegionMode == RegionLimitMode.All || (a.RegionMode == RegionLimitMode.AllowRegion ? Regex.IsMatch(location, a.Regions) : !Regex.IsMatch(location, a.Regions))); if (cid.HasValue) { var scid = cid.ToString(); if (Any(a => a.CategoryIds.Contains(scid))) { where = where.And(a => a.CategoryIds.Contains(scid) || string.IsNullOrEmpty(a.CategoryIds)); } } var list = GetQuery(where).OrderBy(a => - Math.Log(DataContext.Random()) / ((double)a.Price / a.Types.Length * catCount / (string.IsNullOrEmpty(a.CategoryIds) ? catCount : (a.CategoryIds.Length + 1)))).Take(count).ToList(); var ids = list.Select(a => a.Id).ToArray(); GetQuery(a => ids.Contains(a.Id)).UpdateFromQuery(a => new Advertisement() { DisplayCount = a.DisplayCount + 1 }); return list; })); }
public async Task SaveAsync(AdvertiseType type, long number) { try { using (var _context = new UnitOfWorkLid()) { var all = GetAllAsync(type, number); if (all.Count > 0) { if (!RemoveAll(all)) { return; } } var a = Mappings.Default.Map <AdvTokens>(this); var res = _context.AdvTokens.Save(a); _context.Set_Save(); _context.Dispose(); } } catch (Exception exception) { WebErrorLog.ErrorInstence.StartErrorLog(exception); } }
public static async Task SaveAsync(AdvertiseType type, List <RegionBussiness> lst) { try { using (var _context = new UnitOfWorkLid()) { var all = await GetAllAsync(); all = all.Where(q => q.Type == type).ToList(); if (all.Count > 0) { if (!RemoveAll(all)) { return; } } foreach (var item in lst) { var a = Mappings.Default.Map <Region>(item); var res = _context.Region.Save(a); } _context.Set_Save(); _context.Dispose(); } } catch (Exception exception) { WebErrorLog.ErrorInstence.StartErrorLog(exception); } }
public void CopyFromBase(AdvertiseType advertiseType) { this.idat = advertiseType.idat; this.typename = advertiseType.typename; this.sortno = advertiseType.sortno; this.createtime = advertiseType.createtime; this.inuse = advertiseType.inuse; }
public void CopyToBase(AdvertiseType advertiseType) { advertiseType.idat = this.idat; advertiseType.typename = this.typename; advertiseType.sortno = this.sortno; advertiseType.createtime = this.createtime; advertiseType.inuse = this.inuse; }
public static AdvertiseType Add(AdvertiseType advertiseType) { TN db = new TN(); db.AdvertiseTypes.Add(advertiseType); db.SaveChanges(); return(advertiseType); }
public static AdvTokensBussines GetToken(long number, AdvertiseType type) { using (var _context = new UnitOfWorkLid()) { var a = _context.AdvTokens.GetToken(number, type); return(Mappings.Default.Map <AdvTokensBussines>(a)); } }
public static List <AdvTokensBussines> GetAllAsync(AdvertiseType type, long number) { using (var _context = new UnitOfWorkLid()) { var a = _context.AdvTokens.GetAll(type, number); return(Mappings.Default.Map <List <AdvTokensBussines> >(a)); } }
public static List <ChatNumberBussines> GetAll(AdvertiseType type) { using (var _context = new UnitOfWorkLid()) { var a = _context.ChatNumbers.GetAll(type); return(Mappings.Default.Map <List <ChatNumberBussines> >(a)); } }
/// <summary> /// 按价格随机筛选一个元素 /// </summary> /// <param name="count">数量</param> /// <param name="type">广告类型</param> /// <param name="cid">分类id</param> /// <returns></returns> public List <Advertisement> GetsByWeightedPrice(int count, AdvertiseType type, int?cid = null) { Expression <Func <Advertisement, bool> > where = a => a.Types.Contains(type.ToString("D")) && a.Status == Status.Available; if (cid.HasValue) { where = where.And(a => a.CategoryId == cid || a.CategoryId == null); } return(CacheManager.GetOrAdd($"{count}{type}{cid}", _ => GetQuery(where).AsEnumerable().Select(a => new WeightedItem <Advertisement>(a, (int)a.Price)).WeightedItems(count))); }
/// <summary> /// 按权重随机筛选一个元素 /// </summary> /// <param name="count">数量</param> /// <param name="type">广告类型</param> /// <param name="cid">分类id</param> /// <returns></returns> public List <Advertisement> GetsByWeightedRandom(int count, AdvertiseType type, int?cid = null) { Expression <Func <Advertisement, bool> > where = a => a.Types.Contains(type.ToString("D")) && a.Status == Status.Available; if (cid.HasValue) { where = where.And(a => a.CategoryId == cid || a.CategoryId == null); } return(GetRandomWeightList(GetQueryFromCache(where).ToList(), count)); }
public static SimcardBussines GetAsync(AdvertiseType type) { using (var _context = new UnitOfWorkLid()) { switch (type) { case AdvertiseType.Divar: var a = _context.Simcard.GetAsync(type); return(Mappings.Default.Map <SimcardBussines>(a)); } return(null); } }
public static AdvertiseType Edit(AdvertiseType advertiseType) { TN db = new TN(); AdvertiseType oldAdvertiseType = db.AdvertiseTypes.Where(en => en.idat == advertiseType.idat).FirstOrDefault(); oldAdvertiseType.idat = advertiseType.idat; oldAdvertiseType.typename = advertiseType.typename; oldAdvertiseType.sortno = advertiseType.sortno; oldAdvertiseType.inuse = advertiseType.inuse; db.SaveChanges(); return(oldAdvertiseType); }
public frmShowCity(AdvertiseType type) { InitializeComponent(); Type = type; if (Type == AdvertiseType.Divar) { dgDivar.Visible = true; dgSheypoor.Visible = false; lblDesc.Text = "شهرهای دیوار"; } else if (Type == AdvertiseType.Sheypoor) { dgSheypoor.Visible = true; dgDivar.Visible = false; lblDesc.Text = "شهرهای شیپور"; } }
public List <ChatNumbers> GetAll(AdvertiseType type) { try { using (var context = new dbContext()) { var list = context.ChatNumbers.AsNoTracking() .Where(q => q.Type == type) .ToList(); return(list); } } catch (Exception e) { WebErrorLog.ErrorInstence.StartErrorLog(e); return(null); } }
/// <summary> /// 按权重随机筛选一个元素 /// </summary> /// <param name="count">数量</param> /// <param name="type">广告类型</param> /// <param name="cid">分类id</param> /// <returns></returns> public List <Advertisement> GetsByWeightedRandom(int count, AdvertiseType type, int?cid = null) { Expression <Func <Advertisement, bool> > where = a => a.Types.Contains(type.ToString("D")) && a.Status == Status.Available; if (cid.HasValue) { var scid = cid.ToString(); if (ValueCacheManager.GetOrAdd(scid, s => Any(a => a.CategoryIds.Contains(scid)))) { where = where.And(a => a.CategoryIds.Contains(scid) || string.IsNullOrEmpty(a.CategoryIds)); } else { where = where.And(a => string.IsNullOrEmpty(a.CategoryIds)); } } return(CacheManager.GetOrAdd($"{count}{type}{cid}", _ => GetQuery(where).AsEnumerable().Select(a => new WeightedItem <Advertisement>(a, a.Weight)).WeightedItems(count))); }
public List <AdvCategory> GetAllAsync(Guid guid, AdvertiseType type) { try { using (var context = new dbContext()) { var list = context.AdvCategory.AsNoTracking() .Where(q => q.ParentGuid == guid && q.Type == type) .ToList(); return(list); } } catch (Exception e) { WebErrorLog.ErrorInstence.StartErrorLog(e); return(null); } }
public List <Region> GetAllAsync(Guid cityGuid, AdvertiseType type) { try { using (var context = new dbContext()) { var list = context.Region.AsNoTracking() .Where(q => (q.CityGuid == cityGuid) && q.Type == type)? .ToList(); return(list); } } catch (Exception e) { WebErrorLog.ErrorInstence.StartErrorLog(e); return(null); } }
public static async Task <ReturnedSaveFuncInfo> SaveAdv(AdvertiseType type, string fCat, string sCat, string thCat, string state, string city, string region, string title, string content, long number, decimal price1, decimal price2, string url) { var res = new ReturnedSaveFuncInfo(); try { var log = new AdvertiseLogBussines() { Guid = Guid.NewGuid(), Region = region, Title = title, Content = content, City = city, State = state, SimcardNumber = number, Price2 = price2, Price1 = price1, DateM = DateTime.Now, SubCategory2 = thCat, Category = fCat, SubCategory1 = sCat, AdvType = type, IP = Utilities.GetIp(), LastUpdate = DateTime.Now, StatusCode = StatusCode.InPublishQueue, URL = url, UpdateDesc = "آگهی در صف انتشار قرارداد", VisitCount = 0 }; res.AddReturnedValue(await log.SaveAsync()); } catch (Exception ex) { WebErrorLog.ErrorInstence.StartErrorLog(ex); res.AddReturnedValue(ex); } return(res); }
public AdvTokens GetToken(long number, AdvertiseType type) { try { using (var contex = new dbContext()) { var acc = contex.AdvTokens.AsNoTracking() .SingleOrDefault(q => q.Number == number && q.Type == type); return(acc); } } catch (ThreadAbortException) { return(null); } catch (Exception exception) { WebErrorLog.ErrorInstence.StartErrorLog(exception); return(null); } }
public Simcard GetAsync(AdvertiseType type) { try { using (var contex = new dbContext()) { if (type == AdvertiseType.Divar) { var acc = contex.Simcard.AsNoTracking().OrderBy(q => q.NextUse).FirstOrDefault(); return(acc); } return(null); } } catch (Exception exception) { WebErrorLog.ErrorInstence.StartErrorLog(exception); return(null); } }
/// <summary> /// 按价格随机筛选一个元素 /// </summary> /// <param name="count">数量</param> /// <param name="type">广告类型</param> /// <param name="cid">分类id</param> /// <returns></returns> public List <Advertisement> GetsByWeightedPrice(int count, AdvertiseType type, int?cid = null) { return(CacheManager.GetOrAdd($"{count}{type}{cid}", _ => { Expression <Func <Advertisement, bool> > where = a => a.Types.Contains(type.ToString("D")) && a.Status == Status.Available; if (cid.HasValue) { var scid = cid.ToString(); if (Any(a => a.CategoryIds.Contains(scid))) { where = where.And(a => a.CategoryIds.Contains(scid) || string.IsNullOrEmpty(a.CategoryIds)); } } var list = GetQuery(where).AsEnumerable().Select(a => new WeightedItem <Advertisement>(a, a.CategoryIds is { Length: > 0 } ? (int)a.Price * 2 : (int)a.Price)).WeightedItems(count); var ids = list.Select(a => a.Id).ToArray(); GetQuery(a => ids.Contains(a.Id)).UpdateFromQuery(a => new Advertisement() { DisplayCount = a.DisplayCount + 1 }); return list; }));
/// <summary> /// 按价格随机筛选一个元素 /// </summary> /// <param name="count">数量</param> /// <param name="type">广告类型</param> /// <param name="ipinfo"></param> /// <param name="cid">分类id</param> /// <param name="keywords"></param> /// <returns></returns> public List <Advertisement> GetsByWeightedPrice(int count, AdvertiseType type, IPLocation ipinfo, int?cid = null, string keywords = "") { var(location, _, _) = ipinfo; return(CacheManager.GetOrAdd($"Advertisement:{location.Crc32()}:{type}:{count}-{cid}-{keywords}", _ => { var atype = type.ToString("D"); Expression <Func <Advertisement, bool> > where = a => a.Types.Contains(atype) && a.Status == Status.Available; var catCount = CategoryRepository.Count(_ => true); where = where.And(a => a.RegionMode == RegionLimitMode.All || (a.RegionMode == RegionLimitMode.AllowRegion ? Regex.IsMatch(location, a.Regions) : !Regex.IsMatch(location, a.Regions))); if (cid.HasValue) { var pids = CategoryRepository.GetQuery(c => c.Id == cid).Select(c => c.ParentId + "|" + c.Parent.ParentId).Cacheable().ToArray(); var scid = pids.Select(s => s.Trim('|')).Where(s => !string.IsNullOrEmpty(s)).Append(cid + "").Join("|"); if (Any(a => Regex.IsMatch(a.CategoryIds, scid))) { where = where.And(a => Regex.IsMatch(a.CategoryIds, scid) || string.IsNullOrEmpty(a.CategoryIds)); } } if (!keywords.IsNullOrEmpty()) { var regex = _luceneIndexSearcher.CutKeywords(keywords).Select(Regex.Escape).Join("|"); where = where.And(a => Regex.IsMatch(a.Title + a.Description, regex)); } var list = GetQuery(where).OrderBy(a => - Math.Log(DataContext.Random()) / ((double)a.Price / a.Types.Length * catCount / (string.IsNullOrEmpty(a.CategoryIds) ? catCount : (a.CategoryIds.Length + 1)))).Take(count).ToList(); if (list.Count == 0 && keywords is { Length: > 0 }) { return GetsByWeightedPrice(count, type, ipinfo, cid); } var ids = list.Select(a => a.Id).ToArray(); GetQuery(a => ids.Contains(a.Id)).UpdateFromQuery(a => new Advertisement { DisplayCount = a.DisplayCount + 1 }); return list; }));
public static async Task <List <RegionBussiness> > GetAllAsync(Guid cityGuid, AdvertiseType type) { using (var _context = new UnitOfWorkLid()) { var a = _context.Region.GetAllAsync(cityGuid, type); return(Mappings.Default.Map <List <RegionBussiness> >(a)); } }
/// <summary> /// 按价格随机筛选一个元素 /// </summary> /// <param name="type">广告类型</param> /// <param name="cid">分类id</param> /// <returns></returns> public Advertisement GetByWeightedPrice(AdvertiseType type, int?cid = null) { return(GetsByWeightedPrice(1, type, cid).FirstOrDefault()); }
public static async Task <bool> GoToNextSite(AdvertiseType type, short mode) { try { //mode 0 => حرکت رو به جلو //mode 1 => از سر گیری سایت ها بعد از ریستارت مورم //SettingBusiness _cls; //var res = await SettingBusiness.GetAllAsync(); //_cls = res.Count == 0 ? new SettingBusiness() : res[0]; var path = Path.Combine(Application.StartupPath, "SiteRate.txt"); var lst = File.ReadAllLines(path).ToList(); if (!lst.Any()) { return(false); } var index = ""; if (mode == 0) { for (var i = 0; i < lst.Count; i++) { if (lst[i] != type.ToString()) { continue; } if (i + 1 == lst.Count) { index = null; break; } index = lst[i + 1]; break; } } else { CloseAllChromeWindows(); index = lst[0]; } switch (index) { case "Divar": //if (_cls.DivarSetting.CountAdvInIp != 0) //{ // var divar = await DivarAdv.GetInstance(); // await divar.StartRegisterAdv(); // return true; //} break; case "Sheypoor": //if (_cls.SheypoorSetting.CountAdvInIp != 0) //{ // var sheypoor = await SheypoorAdv.GetInstance(); // await sheypoor.StartRegisterAdv(); // return true; //} break; } return(false); } catch (Exception ex) { WebErrorLog.ErrorInstence.StartErrorLog(ex); return(false); } }