Ejemplo n.º 1
0
        public static TChannelWritter GetChannelWriter(string phone, string apiID, string apiHash)
        {
            _phone = phone;
            bool converted = int.TryParse(apiID, out _apiID);

            _apiHash       = apiHash;
            channelWritter = new TChannelWritter(_phone, _apiID, _apiHash);
            return(channelWritter);
        }
Ejemplo n.º 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string safePhone = phoneTextBox.Text.Replace("+", "");

            channelWritter = Worker.GetChannelWriter(phoneTextBox.Text, apiIDTextBox.Text, apiHashTextBox.Text);
            Task           = new Task(() =>
            {
                try
                {
                    Application.Current.Dispatcher.Invoke((() =>
                    {
                        channelsListView.Visibility = Visibility.Collapsed;
                        progress1.IsActive = true;
                        progress1.Visibility = Visibility.Visible;
                    }));

                    var connectTask = Connect();
                    connectTask.Wait();

                    if (!channelWritter.IsAuthorized)
                    {
                        Task.Wait(10000);
                        var authTask = AuthorizeRequest();
                        authTask.Wait();

                        Application.Current.Dispatcher.Invoke((() =>
                        {
                            authorizeDialog = new AuthorizeDialog();
                            authorizeDialog.ShowDialog();
                            if (authorizeDialog.DialogResult == true)
                            {
                                authCode = authorizeDialog.ResponseText;
                            }
                        }));

                        Task.Wait(10000);
                        AuthorizeConfirm(authCode).Wait();
                    }

                    if (channelWritter.IsAuthorized)
                    {
                        var task = channelWritter.GetUserDialogs();
                        task.Wait();
                        channels = channelWritter.GetChannelList(task.Result);

                        Application.Current.Dispatcher.Invoke((() =>
                        {
                            channelsListView.ItemsSource = channels;
                        }));
                    }

                    Application.Current.Dispatcher.Invoke((() =>
                    {
                        channelsListView.Visibility = Visibility.Visible;
                        progress1.IsActive = false;
                        progress1.Visibility = Visibility.Collapsed;
                        saveButton.IsEnabled = true;
                    }));
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            });

            Task.Start();
        }