public static async void AllImageModify(string mainPath) { try { var allAdvertise = await Advertise.GetAllAsync(mainPath); if (allAdvertise?.Count > 0) foreach (var adv in allAdvertise) if (adv.Images?.Count > 0) foreach (var img in adv.Images) { var newPath = ImageManager.ModifyImage(img); //Path.Combine(Path.GetDirectoryName(img), Guid.NewGuid() + ".jpg"); if (File.Exists(newPath)) { File.Delete(img); } } } catch (Exception ex) { WebErrorLog.ErrorLogInstance.StartLog(ex); MessageBox.Show("ImageModifier:" + ex.Message); } }
private async Task <AdvertiseLogBusiness> GetNextAdv(long simCardNumber) { var newAdvertiseLogBusiness = new AdvertiseLogBusiness(); var monitor = new PerfMonitor(); try { newAdvertiseLogBusiness.SimCardNumber = simCardNumber; #region find visitor and text replacements //پیدا کردن ویزیتور ها و متن جایگزین محتوا برای سیم کارت مورد نظر var replacements = await VisitorBusiness.GetMasterSlaveAdvReplacementsAsync(newAdvertiseLogBusiness.SimCardNumber); if (replacements?.MasterGuid == null) { return(null); } newAdvertiseLogBusiness.MasterVisitorGuid = (Guid)replacements.MasterGuid; if (replacements.SlaveGuid != null) { newAdvertiseLogBusiness.SlaveVisitorGuid = (Guid)replacements.SlaveGuid; } #endregion #region find visitorAdvs //لیست آگهی های مرتبط با ویزیتور دریافت می شود AdvertiseList = await Advertise.GetAllAsync(AdvRootPath, newAdvertiseLogBusiness.MasterVisitorGuid); AdvertiseList = AdvertiseList.Where(q => q.PishNevis == false).ToList(); if (!(AdvertiseList?.Count > 0)) { return(null); } #endregion #region findNextAdvIndex var nextAdvIndex = new Random().Next(AdvertiseList.Count); #endregion #region GetPath string path = null; path = Path.Combine(Path.Combine(_cls?.NiazSetting?.PicPath, AdvertiseList[nextAdvIndex].AdvName) == AdvertiseList[nextAdvIndex].AdvName ? AdvertiseList[nextAdvIndex].RootPath : _cls?.NiazSetting?.PicPath, AdvertiseList[nextAdvIndex].AdvName); newAdvertiseLogBusiness.Adv = path; #endregion #region FindNextTitle //تایتل آگهی دریافت می شود if (!(AdvertiseList[nextAdvIndex].Titles?.Count > 0)) { return(null); } var nextTitleIndex = new Random(DateTime.Now.Millisecond).Next(AdvertiseList[nextAdvIndex].Titles.Count); newAdvertiseLogBusiness.Title = AdvertiseList[nextAdvIndex].Titles[nextTitleIndex]; if (string.IsNullOrEmpty(newAdvertiseLogBusiness.Content)) { return(null); } #endregion #region GetContent //کانتنت آگهی دریافت می شود newAdvertiseLogBusiness.Content = AdvertiseList[nextAdvIndex].Content .Replace("<master>", replacements.AdvReplacement1) .Replace("<slave>", replacements.AdvReplacement2) .Replace("<tell>", replacements.Phone) .Replace("(", "<") .Replace(")", ">"); if (string.IsNullOrEmpty(newAdvertiseLogBusiness.Content)) { return(null); } #endregion #region FindImages //عکسهای آگهی دریافت می شود newAdvertiseLogBusiness.ImagesPathList = GetNextImages(newAdvertiseLogBusiness.Adv, _cls?.NiazSetting?.PicCountInPerAdv ?? 3); #endregion //قیمت آگهی دریافت می شود newAdvertiseLogBusiness.Price = AdvertiseList[nextAdvIndex].Price; #region GetCity var city = await CityBusiness.GetNextRandomCityAsync(newAdvertiseLogBusiness.MasterVisitorGuid, AdvertiseType.NiazKade); newAdvertiseLogBusiness.City = city?.CityName ?? "مشهد"; newAdvertiseLogBusiness.State = city?.State.StateName ?? "خراسان رضوی"; #endregion #region GetCategory if (AdvertiseList[nextAdvIndex].NiazKadeCategories != null && AdvertiseList[nextAdvIndex].NiazKadeCategories.Count > 0) { newAdvertiseLogBusiness.SubCategory1 = AdvertiseList[nextAdvIndex]?.NiazKadeCategories[0] ?? ""; newAdvertiseLogBusiness.SubCategory2 = AdvertiseList[nextAdvIndex]?.NiazKadeCategories[1] ?? ""; } else { newAdvertiseLogBusiness.SubCategory1 = null; newAdvertiseLogBusiness.SubCategory2 = null; } #endregion return(newAdvertiseLogBusiness); } catch (Exception ex) { WebErrorLog.ErrorLogInstance.StartLog(ex); return(null); } finally { monitor.Dispose(); } }