Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        private async Task <IAccountData> Demo(ServiceCode serviceCode, SmsServiceCode?smsServiceCode = null, CountryCode?countryCode = null, bool byPhone = true)
        {
            try
            {
                var useChromiumSettings = cmbBrowserProfile.SelectedIndex == 0;
                var folder = ((BrowserProfileItem)cmbBrowserProfile.SelectedItem).Folder;

                ISmsService smsService = null;
                if (byPhone)
                {
                    if (smsServiceCode == null)
                    {
                        smsService = _smsServices.GetSmsService(((SmsServiceItem)cmbSmsService.SelectedItem).SmsServiceCode);
                    }
                    else
                    {
                        smsService = _smsServices.GetSmsService(smsServiceCode.Value);
                    }
                }
                textBox1.AppendText($@"{Enum.GetName(typeof(ServiceCode), serviceCode)} start... - {DateTime.Now} {Environment.NewLine}");
                IBot iBot        = null;
                var  accountData = CreateAccountDataFromUi();
                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);
                var chromiumSettings = CompositionRoot.Resolve <IChromiumSettings>();
                chromiumSettings.Proxy = $"{_oneProxyControl.ProxyRecord}";
                switch (serviceCode)
                {
                case ServiceCode.MailRu:
                    iBot = new MailRuRegistration(accountData, smsService, chromiumSettings);
                    //iBot = new MailRuRegistration(accountData, smsService, _browserProfileService);
                    break;

                case ServiceCode.Yandex:
                    iBot = new YandexRegistration(accountData, smsService, chromiumSettings);
                    break;

                case ServiceCode.Gmail:
                    iBot = new GmailRegistration(accountData, smsService, chromiumSettings);
                    break;

                case ServiceCode.Facebook:
                    accountData.Firstname = Transliteration.CyrillicToLatin(accountData.Firstname, Language.Russian);
                    accountData.Firstname = accountData.Firstname.Replace("`", "");
                    accountData.Lastname  = Transliteration.CyrillicToLatin(accountData.Lastname, Language.Russian);
                    accountData.Lastname  = accountData.Lastname.Replace("`", "");
                    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;

                case ServiceCode.Instagram:
                    iBot = useChromiumSettings ?
                           new InstagramRegistration(accountData, smsService, chromiumSettings) :
                           new InstagramRegistration(accountData, smsService, _browserProfileService, folder);
                    break;

                case ServiceCode.Twitter:
                    iBot = useChromiumSettings ?
                           new TwitterRegistration(accountData, smsService, chromiumSettings) :
                           new TwitterRegistration(accountData, smsService, _browserProfileService, folder);
                    break;
                }
                if (countryCode == null)
                {
                    countryCode = ((CountryItem)cmbCountry.SelectedItem).CountryCode;
                }
                if (iBot != null)
                {
                    textBox1.AppendText($@"{Enum.GetName(typeof(ServiceCode), serviceCode)}... {JsonConvert.SerializeObject(accountData)} {Environment.NewLine}");
                    accountData = await iBot.Registration(countryCode.Value);
                }
                StoreAccountData(accountData);
                textBox1.AppendText($@"{Enum.GetName(typeof(ServiceCode), serviceCode)}... {JsonConvert.SerializeObject(accountData)} {Environment.NewLine}");
                textBox1.AppendText($@"{Enum.GetName(typeof(ServiceCode), serviceCode)} finish... - {DateTime.Now} {Environment.NewLine}");
                return(accountData);
            }
            catch (Exception exception)
            {
                textBox1.AppendText($"{exception}");
            }
            return(null);
        }