private async void FormLoad() { var smsServiceItems = SmsServiceItem.GetSmsServiceItems(); cmbSmsService.DataSource = smsServiceItems; cmbSmsService.DisplayMember = "Text"; cmbSmsService.SelectedIndex = 0; var browserProfileItems = BrowserProfileItem.GetItems(_browserProfileService); cmbBrowserProfile.DataSource = browserProfileItems; cmbBrowserProfile.DisplayMember = "Text"; cmbBrowserProfile.SelectedIndex = 0; var browserFetcher = new BrowserFetcher(); browserFetcher.DownloadProgressChanged += OnDownloadProgressChanged; GetBrowserLastVersion(browserFetcher); //init ServiceInfoList await _smsServices.GetServiceInfoList(ServiceCode.MailRu); foreach (SmsServiceCode smsServiceCode in Enum.GetValues(typeof(SmsServiceCode))) { var balance = await _smsServices.GetSmsService(smsServiceCode).GetBalance(); if (balance < 5) { textBox1.AppendText($@"Low balance {smsServiceCode} {balance} - {DateTime.Now} {Environment.NewLine}"); _smsServices.RemoveSmsServiceLowBalance(smsServiceCode); } } }
private async void BtnExecute_Click(object sender, EventArgs e) { var countryCode = ((CountryItem)cmbCountry.SelectedItem).CountryCode; var countryName = Enum.GetName(typeof(CountryCode), countryCode); ServiceCode serviceCode = GetServiceCodeFromUi(); var smsServiceItem = (SmsServiceItem)cmbSmsService.SelectedItem; ISmsService smsService = _smsServices.GetSmsService(smsServiceItem.SmsServiceCode); var smsServiceName = Enum.GetName(typeof(SmsServiceCode), smsServiceItem.SmsServiceCode); var serviceName = Enum.GetName(typeof(ServiceCode), serviceCode); tbLog.AppendText($"{DateTime.Now} Получение телефонного номера {smsServiceName} для сервиса {serviceName} и страны {countryName}{Environment.NewLine}"); var phoneNumberRequest = await smsService.GetPhoneNumber(countryCode, serviceCode); //var phoneNumberRequest = new PhoneNumberRequest { Id = _random.Next().ToString(), Phone = "9046214577", Created = DateTime.UtcNow, ActiveSeconds = 900, RemainSeconds = 900 }; if (phoneNumberRequest != null) { tbLog.AppendText($"{DateTime.Now} {phoneNumberRequest.Id}. Получен телефонного номер {phoneNumberRequest.Phone} {smsServiceName} для сервиса {serviceName} и страны {countryName}{Environment.NewLine}"); _phoneNumberRequestItems.Add(new PhoneNumberRequestItem { Id = phoneNumberRequest.Id, Phone = phoneNumberRequest.Phone, Created = phoneNumberRequest.Created, ActiveSeconds = phoneNumberRequest.ActiveSeconds, RemainSeconds = phoneNumberRequest.RemainSeconds, SmsServiceCode = smsServiceItem.SmsServiceCode, ServiceCode = serviceCode, CountryCode = countryCode, SmsService = smsService }); _requestsBindingSource.ResetBindings(false); if (_bw.IsBusy != true) { _bw.RunWorkerAsync(); } return; } tbLog.AppendText($"{DateTime.Now} Ошибка получения телефонного номера {smsServiceName} для сервиса {serviceName} и страны {countryName}{Environment.NewLine}"); }
protected async Task <IAccountData> Registration(IAccountData accountData, SmsServiceCode smsServiceCode, ServiceCode serviceCode, CountryCode countryCode = CountryCode.RU, ILog log = null) { try { log?.Debug($@"{Enum.GetName(typeof(ServiceCode), serviceCode)} via {Enum.GetName(typeof(SmsServiceCode), smsServiceCode)} start... - {DateTime.Now} {Environment.NewLine}"); if (string.IsNullOrEmpty(accountData.AccountName)) { accountData.AccountName = Transliteration.CyrillicToLatin($"{accountData.Firstname.ToLower()}.{accountData.Lastname.ToLower()}", Language.Russian); accountData.AccountName = accountData.AccountName.Replace("`", ""); } accountData = StoreAccountData(accountData); ISmsService smsService = _smsServices.GetSmsService(smsServiceCode); IBot iBot; switch (serviceCode) { case ServiceCode.MailRu: iBot = new MailRuRegistration(accountData, smsService, _chromiumSettings); break; case ServiceCode.Yandex: iBot = new YandexRegistration(accountData, smsService, _chromiumSettings); break; case ServiceCode.Gmail: iBot = new GmailRegistration(accountData, smsService, _chromiumSettings); break; case ServiceCode.Facebook: iBot = new FacebookRegistration(accountData, smsService, _chromiumSettings); break; case ServiceCode.Vk: iBot = new VkRegistration(accountData, smsService, _chromiumSettings); break; case ServiceCode.Ok: iBot = new OkRegistration(accountData, smsService, _chromiumSettings); break; default: throw new ArgumentOutOfRangeException(); } //var countryCode = CountryCode.RU; if (!string.IsNullOrEmpty(accountData.PhoneCountryCode)) { countryCode = (CountryCode)Enum.Parse(typeof(CountryCode), accountData.PhoneCountryCode); } accountData = await iBot.Registration(countryCode); StoreAccountData(accountData); } catch (Exception exception) { log?.Error(exception); } finally { log?.Debug($@"{Enum.GetName(typeof(ServiceCode), serviceCode)} via {Enum.GetName(typeof(SmsServiceCode), smsServiceCode)} finish... - {DateTime.Now} {Environment.NewLine}"); } return(accountData); }