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..."; } }); }
public async void OnSendCodeCommandExecute(object obj) { await Task.Run(async() => { TeleStatus = "Ожидание подтверждения"; IsSetCode = false; TelegramContext.Code = AuthCode; try { await TelegramContext.AuthUserAsync(); TeleStatus = "Вы вошли успешно!!!"; IsProgramStarted = true; IsStartEnabled = true; IsCanChangeNumber = false; TLChannelFulls = await TelegramContext.GetFullInfoCannelsAsync(); foreach (var channel in TLChannelFulls) { ChannelsNames.Add(channel.About); } TelegramContext.LogOut(); MySelectedItem = ChannelsNames?[0]; } catch (Exception ex) { TeleStatus = ex.Message; if (File.Exists(PhotoPath + "dat")) { File.Delete(PhotoPath + "dat"); } } }); }