示例#1
0
        public void Execute()
        {
            VKWebClient client  = new VKWebClient();
            string      request = String.Format(@"act=a_check&key={0}&ts={1}&wait=25&mode={2}", _key, _ts, (int)_mode);

            client.SendRequest(_server, request, _ParseResponse);
        }
示例#2
0
        private void _LoadCaptcha()
        {
            try
            {
                if (!string.IsNullOrEmpty(_captchaImg))
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        try
                        {
                            var client = new VKWebClient();
                            client.GetByteData(_captchaImg, _ShowCaptcha);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine("_LoadCaptcha failed in AuthPage: " + ex.Message);
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("_LoadCaptcha failed " + ex.Message);

                MessageBox.Show(AppResources.InternalApiError);
            }
        }
示例#3
0
 private void _LoadCaptcha(string captchaImg)
 {
     try
     {
         if (!string.IsNullOrEmpty(captchaImg))
         {
             Deployment.Current.Dispatcher.BeginInvoke(() =>
             {
                 try
                 {
                     var client = new VKWebClient();
                     client.GetByteData(captchaImg, _ShowCaptcha);
                 }
                 catch (Exception ex)
                 {
                     Debug.WriteLine("_LoadCaptcha failed in CaptchaPage: " + ex.Message);
                 }
             });
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("_LoadCaptcha failed " + ex.Message);
     }
 }
示例#4
0
 public void Execute()
 {
     try
     {
         VKWebClient client = new VKWebClient();
         client.SendPostRequest(@"https://api.vk.com/method/" + _parameters["method"], _CreateRequestString(), _ParseResponse);
     }
     catch
     {
         _ParseResponse(null);
     }
 }
示例#5
0
        private void _Authorize(string login, string password, string captchaSid, string captchaKey)
        {
            login    = HttpUtility.UrlEncode(login);
            password = HttpUtility.UrlEncode(password);
            string request = string.Format(
                @"grant_type=password&scope=nohttps,notify,friends,photos,audio,video,docs,status,messages,notification&client_id={0}&client_secret={1}&username={2}&password={3}",
                AuthorizeHelper.ClientId, AuthorizeHelper.ClientSecret, login, password);

            // Check if need to show captcha...
            if (captchaSid != null && captchaKey != null)
            {
                request = request + "&captcha_sid=" +
                          HttpUtility.UrlEncode(captchaSid) + "&captcha_key=" +
                          HttpUtility.UrlEncode(captchaKey);
            }

            VKWebClient client = new VKWebClient();

            client.SendRequest(@"https://oauth.vk.com/token", request, _ParseResponse);
        }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        /// <returns>Request string to send attachments with API method messages.Send.</returns>
        private void _UploadCurrentPhotoAttachments()
        {
            if (App.Current.EntityService.AttachmentPhotos.Count == 0)
            {
                _UploadCompleted();
            }
            else
            {
                //////////////////////////////////// GET UPLOAD SERVER
                if (string.IsNullOrEmpty(_uploadServer))
                {
                    var getUploadServer = new PhotosGetMessagesUploadServer(uploadServer =>
                    {
                        _uploadServer = uploadServer;
                        _UploadCurrentPhotoAttachments();
                    });
                    getUploadServer.Execute();
                }
                else
                {
                    foreach (var photo in App.Current.EntityService.AttachmentPhotos)
                    {
                        /////////////////////////// READ FILE DATA
                        var data = new byte[photo.Value.Length];
                        photo.Value.Read(data, 0, (int)photo.Value.Length);

                        if (data != null)
                        {
                            //////////////////////////////////// SEND DATA
                            var client  = new VKWebClient();
                            var handler = new ManualResetEvent(false);

                            client.SendPhoto(_uploadServer, "photo", data, response =>
                            {
                                try
                                {
                                    SentPhoto sentPhoto = SerializeHelper.Deserialise <SentPhoto>(response);

                                    //////////////////////////////////// SAVE ATTACHMENT PHOTO
                                    PhotosSaveMessagesPhoto op = new PhotosSaveMessagesPhoto(sentPhoto.Server,
                                                                                             sentPhoto.Photo, sentPhoto.Hash, att =>
                                    {
                                        if (att != null)
                                        {
                                            //////////////////////////////////// REMEMBER ATTACHMENT ID
                                            _currentAttachmentsRequest += att.Id.ToString() + ",";
                                        }
                                        handler.Set();
                                    });
                                    op.Execute();
                                }
                                catch (Exception ex)
                                {
                                    _UploadCurrentPhotoAttachments();
                                    _uploadServer = string.Empty;
                                    //handler.Set();
                                    Debug.WriteLine("Parse response from _SavePhotoAttach failed." + ex.Message);
                                }
                            });
                            handler.WaitOne();
                        }
                    }

                    //_uploadServer = string.Empty;
                    _UploadCompleted();
                }
            }
        }
示例#7
0
        private void PhotoGallery_Completed(object sender, PhotoResult e)
        {
            try
            {
                if (e.ChosenPhoto != null)
                {
                    GlobalIndicator.Instance.Text      = AppResources.UploadingPhoto;
                    GlobalIndicator.Instance.IsLoading = true;

                    //////////////////////////////////// GET UPLOAD SERVER
                    var getUploadServer = new PhotosGetProfileUploadServer(uploadServer =>
                    {
                        if (!string.IsNullOrEmpty(uploadServer))
                        {
                            /////////////////////////// READ FILE DATA
                            var data = new byte[e.ChosenPhoto.Length];
                            e.ChosenPhoto.Read(data, 0, (int)e.ChosenPhoto.Length);

                            if (data != null)
                            {
                                //////////////////////////////////// SEND DATA
                                var client  = new VKWebClient();
                                var handler = new ManualResetEvent(false);

                                client.SendPhoto(uploadServer, "photo", data, response =>
                                {
                                    try
                                    {
                                        var sentPhoto = SerializeHelper.Deserialise <SentPhoto>(response);

                                        //////////////////////////////////// SAVE ATTACHMENT PHOTO
                                        var op = new PhotosSaveProfilePhoto(sentPhoto.Server,
                                                                            sentPhoto.Photo, sentPhoto.Hash, photo =>
                                        {
                                            if (photo != null)
                                            {
                                                //////////////////////////////////// RELOAD AVATAR
                                                App.Current.EntityService.CurrentUser.UserInfo.Photo       = photo.SourceSmall;
                                                App.Current.EntityService.CurrentUser.UserInfo.PhotoMedium = photo.Source;
                                                App.Current.EntityService.CurrentUser.UserInfo.PhotoBig    = photo.SourceBig;
                                                App.Current.EntityService.LoadAvatars();
                                            }
                                            else
                                            {
                                                MessageBox.Show(AppResources.UploadPhotoError);
                                            }

                                            handler.Set();
                                        });
                                        op.Execute();
                                    }
                                    catch (Exception)
                                    {
                                        Debug.WriteLine("Parse response from PhotosSaveMessagesPhoto failed.");
                                        handler.Set();
                                    }
                                });
                                handler.WaitOne();

                                Dispatcher.BeginInvoke(() =>
                                {
                                    GlobalIndicator.Instance.Text      = string.Empty;
                                    GlobalIndicator.Instance.IsLoading = false;
                                });
                            }
                            else
                            {
                                Dispatcher.BeginInvoke(() =>
                                {
                                    GlobalIndicator.Instance.Text      = string.Empty;
                                    GlobalIndicator.Instance.IsLoading = false;
                                });
                            }
                        }
                    });
                    getUploadServer.Execute();
                }
            }
            catch (Exception ex)
            {
                GlobalIndicator.Instance.Text      = string.Empty;
                GlobalIndicator.Instance.IsLoading = false;
                Debug.WriteLine("PhotoGallery_Completed failed and couched in UI! WTF! " + ex.Message);
            }
        }