private async void OnAuthenticate(object obj) { await Task.Run(async() => { IsAuthorisation = false; IsSetCode = false; _telegramLogic = new TelegramLogic(NumberPhone); _path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sessions"); var tmpfiles = Directory.GetFiles(_path, "*", SearchOption.AllDirectories).ToList(); foreach (var item in tmpfiles) { _files.Add(Path.GetFileName(item)); } foreach (var item in _files) { if (item.Equals(NumberPhone + ".dat")) { await _telegramLogic.LogInAsync(); LoginResult = "Вы вошли успешно!!! "; return; } } await _telegramLogic.GetCodeAuthenticateAsync(); LoginResult = "Ждите код для подтверждения"; IsSetCode = true; }); }
public async void OnLoginCommandExecute(object obj) { await Task.Run(async() => { Regex regex = new Regex(@"^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$"); if (regex.IsMatch(PhoneNumber)) { IsLoggEnabled = false; TeleStatus = "Загрузка..."; TelegramContext = new TelegramLogic(PhoneNumber); string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sessions"); var tmpfiles = Directory.GetFiles(path, "*", SearchOption.AllDirectories).ToList(); foreach (var item in tmpfiles) { FileSessionStore.Add(Path.GetFileName(item)); } foreach (var item in FileSessionStore) { if (item.Equals(PhoneNumber + ".dat")) { await TelegramContext.LogInAsync(); TLChannelFulls = await TelegramContext.GetFullInfoCannelsAsync(); foreach (var channel in TLChannelFulls) { ChannelsNames.Add(channel.About); } MySelectedItem = ChannelsNames?[0]; IsProgramStarted = true; IsStartEnabled = true; IsCanChangeNumber = false; TeleStatus = "Вы вошли успешно!!! "; TelegramContext.LogOut(); return; } } try { await TelegramContext.GetCodeAuthenticateAsync(); TeleStatus = "Ждите код для подтверждения"; IsSetCode = true; } catch (Exception ex) { TeleStatus = ex.Message; File.Delete(PhoneNumber + ".dat"); IsLoggEnabled = true; } } else { TeleStatus = "Некорректный номер!\nПопробуйте: +1234..."; } }); }