示例#1
0
        private async Task StartUploadPhoto(string name, Stream stream)
        {
            try {
                Deployment.Current.Dispatcher.BeginInvoke(() => {
                    UploadProgressBar.Visibility = Visibility.Collapsed;
                });

                InputFile file =
                    await TelegramSession.Instance.Files.UploadFile(name, stream, PhotoUploadProgressHandler);

                photos_Photo photo =
                    await
                    TelegramSession.Instance.Api.photos_uploadProfilePhoto(file, "", TL.inputGeoPointEmpty(),
                                                                           TL.inputPhotoCropAuto());

                Photos_photoConstructor photoConstructor = (Photos_photoConstructor)photo;

                foreach (var user in photoConstructor.users)
                {
                    TelegramSession.Instance.SaveUser(user);
                }

                Deployment.Current.Dispatcher.BeginInvoke(() => {
                    UploadProgressBar.Visibility = Visibility.Collapsed;
                });
            }
            catch (Exception ex) {
                logger.error("exception {0}", ex);
            }
        }
示例#2
0
        private async Task Login()
        {
            flow.NeedCodeEvent += delegate(Login login) {
                Deployment.Current.Dispatcher.BeginInvoke(
                    delegate {
                    RestartTimer();
                    ShowCodeScene();
                    HeaderBlock.Text = "Your code";
                });
            };

            flow.WrongCodeEvent += delegate(Login login) {
                Deployment.Current.Dispatcher.BeginInvoke(
                    delegate {
                    ShowCodeScene();
                    HeaderBlock.Text = "Your code";
                    codeControl.SetCodeInvalid();
                });
            };

            flow.NeedSignupEvent += delegate(Login login) {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    HeaderBlock.Text = "Your name";
                    ShowNameScene();
                });
            };

            flow.LoginSuccessEvent += delegate(Login login) {
                Deployment.Current.Dispatcher.BeginInvoke(
                    delegate {
                    HideProgress();
                    new NotificationManager().RegisterPushNotifications();
                    NavigationService.Navigate(new Uri("/UI/Pages/StartPage.xaml", UriKind.Relative));



                    ContactManager cm = new ContactManager();
                    Task.Run(() => cm.SyncContacts());

                    PhotoResult avatarSource = nameControl.GetAvatarSource();

                    if (avatarSource != null)
                    {
                        Task.Run(async delegate {
                            InputFile file =
                                await TelegramSession.Instance.Files.UploadFile(avatarSource.OriginalFileName, avatarSource.ChosenPhoto, (progress) => { });

                            photos_Photo photo =
                                await
                                TelegramSession.Instance.Api.photos_uploadProfilePhoto(file, "", TL.inputGeoPointEmpty(),
                                                                                       TL.inputPhotoCropAuto());

                            Photos_photoConstructor photoConstructor = (Photos_photoConstructor)photo;

                            foreach (var user in photoConstructor.users)
                            {
                                TelegramSession.Instance.SaveUser(user);
                            }
                        });
                    }
                });
            };

            Task.Run(() => flow.Start());
//            flow.Start();
        }