public static string GetCryptoCurrencyMessage(IEnumerable <Dto.CryptoCurrency> cryptoCurrencies, MainCurrency teamMainCurrency) { var retMessage = new StringBuilder(); decimal usdSellRate = 0; if (teamMainCurrency == MainCurrency.Try) { var settingBusiness = new SettingBusiness(); usdSellRate = settingBusiness.GetUsdValue(); } foreach (var cryptoCurrency in cryptoCurrencies) { var usdValueStr = cryptoCurrency.UsdValue.ToMoneyMarketMoneyFormat(); var tryValueStr = teamMainCurrency == MainCurrency.Usd ? "" : string.Format(" ({0} {1:G})", (cryptoCurrency.UsdValue * usdSellRate).ToMoneyMarketMoneyFormat(), MainCurrency.Try); if (teamMainCurrency == MainCurrency.Try) { retMessage.Append(string.Format("{0:G} {1:G}: {2} {3:G}{4}{5}", cryptoCurrency.Provider, cryptoCurrency.Currency, usdValueStr, MainCurrency.Usd, tryValueStr, "{lf}")); } else { retMessage.Append(string.Format("{0:G} {1:G}: {2} {3:G}{4}", cryptoCurrency.Provider, cryptoCurrency.Currency, usdValueStr, teamMainCurrency, "{lf}")); } } return(retMessage.ToString()); }
public static DateTime GetSlackTeamExpirationDate(AccountType accountType) { var settingBusiness = new SettingBusiness(); var settings = settingBusiness.All().First(p => p.Id == DatabaseKey.Setting.TrialAccountExpirationDays); return(DateTime.UtcNow.AddDays(int.Parse(settings.Value))); }
private static async Task <SettingBusiness> GetDataFromSetting() { try { var res = await SettingBusiness.GetAllAsync(); _cls = res.Count == 0 ? new SettingBusiness() : res[0]; return(_cls); } catch (Exception ex) { WebErrorLog.ErrorLogInstance.StartLog(ex); return(null); } }
public Setting Add(Setting setting) { try { var bs = new SettingBusiness(); return(bs.Add(setting)); } catch (Exception ex) { var httpError = new HttpResponseMessage() { StatusCode = (HttpStatusCode)422, ReasonPhrase = ex.Message }; throw new HttpResponseException(httpError); } }
public void Remove(int id) { try { var bs = new SettingBusiness(); bs.Remove(id); } catch (Exception ex) { var httpError = new HttpResponseMessage() { StatusCode = (HttpStatusCode)422, ReasonPhrase = ex.Message }; throw new HttpResponseException(httpError); } }
private decimal GetCurrentUsdValueByMainCurrency(decimal amount, MainCurrency mainCurrency) { if (mainCurrency == MainCurrency.Usd) { return(amount); } if (mainCurrency == MainCurrency.Try) { var settingBusiness = new SettingBusiness(); var usdSellRate = settingBusiness.GetUsdValue(); return(amount / usdSellRate); } return(0); }
public FindSettingResponse Find(int id) { try { var response = new FindSettingResponse(); var bs = new SettingBusiness(); response.Result = bs.Find(id); return(response); } catch (Exception ex) { var httpError = new HttpResponseMessage() { StatusCode = (HttpStatusCode)422, ReasonPhrase = ex.Message }; throw new HttpResponseException(httpError); } }
public void Edit(Setting setting) { try { var bs = new SettingBusiness(); setting.ChangedOn = System.DateTime.Now; setting.LastChangeDate = System.DateTime.Now; bs.Edit(setting); } catch (Exception ex) { var httpError = new HttpResponseMessage() { StatusCode = (HttpStatusCode)422, ReasonPhrase = ex.Message }; throw new HttpResponseException(httpError); } }
public static string GetCryptoCurrencyBalanceMessage(IEnumerable <Dto.TeamCryptoCurrencyBalance> teamCryptoCurrencybalances, MainCurrency teamMainCurrency, IEnumerable <Dto.CryptoCurrency> cryptoCurrencies, string successText) { var retMessage = new StringBuilder(); decimal usdSellRate = 0; if (teamMainCurrency == MainCurrency.Try) { var settingBusiness = new SettingBusiness(); usdSellRate = settingBusiness.GetUsdValue(); } decimal totalUsdValueOfCryptoCurrencies = 0; foreach (var tccb in teamCryptoCurrencybalances) { tccb.UnitUsdValue = cryptoCurrencies.First(p => p.Currency == tccb.Currency).UsdValue; var balanceLine = string.Format("{0}: {1} {2:G}{3}", tccb.Name, tccb.Balance.ToMoneyMarketCryptoCurrencyFormat(), tccb.Currency, "{lf}"); retMessage.Append(balanceLine); totalUsdValueOfCryptoCurrencies += tccb.TotalUsdValue; } if (teamMainCurrency == MainCurrency.Try) { var totalTryValueOfCryptoCurrencies = totalUsdValueOfCryptoCurrencies * usdSellRate; retMessage.Append(string.Format("{0} {1} {2:G} ({3} {4:G})", successText, totalUsdValueOfCryptoCurrencies.ToMoneyMarketMoneyFormat(), MainCurrency.Usd, totalTryValueOfCryptoCurrencies.ToMoneyMarketMoneyFormat(), MainCurrency.Try)); } else { retMessage.Append(string.Format("{0} {1} {2:G}", successText, totalUsdValueOfCryptoCurrencies.ToMoneyMarketMoneyFormat(), teamMainCurrency)); } return(retMessage.ToString()); }
private async void SendPriceTrackerAlarmNotifications(IEnumerable <Dto.TeamNotification> priceTrackerAlarmNotifications) { //:bell: slack alarm emoji //BtcTurk Btc: 17,022.33323 Usd var usdSellRate = new SettingBusiness().GetUsdValue(); //get all crypto currencies var cryptoCurrencies = GetCryptoCurrencies(); foreach (var teamNotification in priceTrackerAlarmNotifications) { var keyArray = teamNotification.Key.Split(':'); var provider = Statics.GetProvider(int.Parse(keyArray[0])); var currency = Statics.GetCurrency(int.Parse(keyArray[1])); var limitAmount = keyArray[2].ToMoneyMarketDecimalFormat(); var mainCurrency = Statics.GetMainCurrency(int.Parse(keyArray[3])); var alarmType = Statics.GetAlarmType(int.Parse(keyArray[4])); IEnumerable <Dto.CryptoCurrency> alarms; if (mainCurrency == MainCurrency.Try) { switch (alarmType) { case AlarmType.Sell: alarms = cryptoCurrencies.Where(p => (p.UsdValue * usdSellRate) >= limitAmount && p.Currency == currency); break; case AlarmType.Purchase: alarms = cryptoCurrencies.Where(p => (p.UsdValue * usdSellRate) < limitAmount && p.Currency == currency); break; default: continue; } } else { switch (alarmType) { case AlarmType.Sell: alarms = cryptoCurrencies.Where(p => p.UsdValue >= limitAmount && p.Currency == currency); break; case AlarmType.Purchase: alarms = cryptoCurrencies.Where(p => p.UsdValue < limitAmount && p.Currency == currency); break; default: continue; } } if (provider != Provider.Unknown) { alarms = alarms.Where(p => p.Provider == provider); } if (!alarms.Any()) { //do nothing continue; } var successMessage = SlackMessageGenerator.GetCryptoCurrencyAlarmMessage(alarms, mainCurrency, usdSellRate); await PostMessage(GetSlackExecutionSuccessMessage(successMessage, teamNotification.Team)); Delete(teamNotification.Id); } }
public static async Task ManageAdvSend() { try { var tokenSource = new CancellationTokenSource(); var res = await SettingBusiness.GetAllAsync(); var cls = res.Count == 0 ? new SettingBusiness() : res[0]; short maxDailyCountDivar = 1; short maxMountlyCountDivar = 1; short maxAdvCountInIpInDayDivar = 1; short maxDailyCountSheypoor = 1; short maxMountlyCountSheypoor = 1; short maxAdvCountInIpInDaySheypoor = 1; short maxDailyCountNiazmandyHa = 1; short maxMountlyCountNiazmandyHa = 1; short maxAdvCountInIpInDayNiazmandyHa = 1; var filePath = Path.Combine(Application.StartupPath, "GateWay.txt"); var filelst = ReadAllLines(filePath).ToList(); var GateWayCount = 0; while (!tokenSource.IsCancellationRequested) { var isIpFull = true; for (var i = (int)AdvertiseType.Divar; i <= (int)AdvertiseType.NiazmandyHa; i++) { var lst = new List <long>(); switch (i) { case (int)AdvertiseType.Divar: maxDailyCountDivar = (short)cls.DivarSetting.AdvCountInDay; maxMountlyCountDivar = (short)cls.DivarSetting.AdvCountInMonth; maxAdvCountInIpInDayDivar = (short)cls.DivarSetting.CountAdvInIp; break; case (int)AdvertiseType.Sheypoor: maxDailyCountSheypoor = (short)cls.SheypoorSetting.AdvCountInDay; maxMountlyCountSheypoor = (short)cls.SheypoorSetting.AdvCountInMonth; maxAdvCountInIpInDaySheypoor = (short)cls.SheypoorSetting.CountAdvInIp; break; case (int)AdvertiseType.NiazKade: break; case (int)AdvertiseType.NiazmandyHa: maxDailyCountNiazmandyHa = (short)cls.NiazmandyHaSetting.AdvCountInDay; maxMountlyCountNiazmandyHa = (short)cls.NiazmandyHaSetting.AdvCountInMonth; maxAdvCountInIpInDayNiazmandyHa = (short)cls.NiazmandyHaSetting.CountAdvInIp; break; } var number = await SimCardBusiness.GetNextSimCardNumberAsync( (short)i, maxDailyCountDivar, maxDailyCountSheypoor, await GetLocalIpAddress(), maxMountlyCountDivar, maxMountlyCountSheypoor, maxAdvCountInIpInDayDivar, maxAdvCountInIpInDaySheypoor, maxDailyCountNiazmandyHa, maxMountlyCountNiazmandyHa, maxAdvCountInIpInDayNiazmandyHa); if (number != 0) { isIpFull = false; lst.Add(number); if (i == (int)AdvertiseType.Divar) { if (await PingHost("185.105.239.1")) { var divar = await DivarAdv.GetInstance(); await divar.StartRegisterAdv(lst, maxDailyCountDivar); } } else if (i == (int)AdvertiseType.Sheypoor) { if (await PingHost("185.105.239.1")) { var sheypoor = await SheypoorAdv.GetInstance(); await sheypoor.StartRegisterAdv(lst, maxDailyCountSheypoor); } } else if (i == (int)AdvertiseType.NiazKade) { isIpFull = false; continue; } else if (i == (int)AdvertiseType.DivarChat) { isIpFull = false; continue; } else if (i == (int)AdvertiseType.NiazmandyHa) { //if (await PingHost("185.105.239.1")) //{ // var niazmandyHa = await NiazmandyHaAdv.GetInstance(); // await niazmandyHa.StartRegisterAdv(lst, maxDailyCountNiazmandyHa); //} isIpFull = false; continue; } } CloseAllChromeWindows(); if (!isIpFull) { continue; } GateWayCount++; if (GateWayCount > filelst.Count) { numbers = new List <int>(); if (await FindGateWay() == IP_Store.IP_Mokhaberat.Value) { await ChangeIp(); await Wait(60); } while (await GetLocalIpAddress() == null) { await Wait(10); lstMessage.Clear(); lstMessage.Add("مودم مخابرات ریست شد. لطفا منتظر بمانید"); ShowBalloon("درحال اتصال...", lstMessage); } await UpdateAdvStatus(1); i = -1; GateWayCount = 0; continue; } var gateway = await GetRandomGeteWay(); if (gateway == null) { continue; } await SetGateway(gateway); lstMessage.Clear(); lstMessage.Add(" GateWay تعویض شد. لطفا منتظر بمانید"); ShowBalloon("درحال اتصال...", lstMessage); while (await GetLocalIpAddress() == null) { await Wait(2); lstMessage.Add(" GateWay تعویض شد. لطفا منتظر بمانید"); ShowBalloon("درحال اتصال...", lstMessage); } //GateWayCount = 0; i = -1; } } } catch (Exception ex) { WebErrorLog.ErrorLogInstance.StartLog(ex); } }
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; case "NiazKade": if (_cls.NiazSetting.CountAdvInIp != 0) { var niaz = await NiazAdv.GetInstance(); await niaz.StartRegisterAdv(); return(true); } break; case "NiazmandyHa": break; } return(false); } catch (Exception ex) { WebErrorLog.ErrorLogInstance.StartLog(ex); return(false); } }
public SettingFacade(string connectionString) : base(connectionString) { rep = new SettingBusiness(this.Connection); }