private async void OnAddChannel(object obj) { await Task.Run(async() => { string res = ""; try { res = InputUriChannel.Split('/').Last().Split('@').Last(); } catch (Exception) { } try { var id = await _telegramLogic.JoinCannel(res); _tLChannelFull = await _telegramLogic.GetFullInfoCannelsAsync(); _tLChannels = await _telegramLogic.GetInfoChannelsAsync(); var tLChannelFullinfo = _tLChannelFull.Where(p => p.Id == id).FirstOrDefault(); var tLChannels = _tLChannels.Where(p => p.Id == id).FirstOrDefault(); var channelsInfo = new ChannelsInfo() { SubscribersChannel = (int)tLChannelFullinfo.ParticipantsCount, UriChannel = tLChannels.Username, NameChannel = tLChannels.Title, IdChannel = tLChannels.Id, AccessHashChannel = (long)tLChannels.AccessHash, FullUriCannel = InputUriChannel }; channelsInfo.AvatarChannel = tLChannelFullinfo.ChatPhoto is TLPhoto tLPhoto ? DateTimeOffset.FromUnixTimeSeconds(tLPhoto.Date).DateTime : new DateTime(2000, 1, 1); InfoChannels.Add(_channelsService.Create(channelsInfo)); AddChannels addChannels = new AddChannels { UriChannel = InputUriChannel }; UriList.Add(addChannels); } catch (Exception) { } }); }
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..."; } }); }