コード例 #1
0
 public void OnData(object vkRestApi, OnDataEventArgs onDataArgs)
 {
     switch (onDataArgs.Function)
     {
         case VkFunction.GetProfiles:
             OnLoadUserInfo(onDataArgs.Data);
             break;
         default:
             Debug.WriteLine("Error, unknown function.");
             break;
     }
 }
コード例 #2
0
        // main data handler
        public void OnData(object vkRestApi, OnDataEventArgs onDataArgs)
        {
            switch (onDataArgs.Function)
            {
                case VkFunction.GetProfiles:
                    OnLoadUserInfo(onDataArgs.Data);
                    break;
                case VkFunction.LoadFriends:
                    OnLoadFriends(onDataArgs.Data);
                    break;
                case VkFunction.FriendsGetMutual:
                    OnGetMutual(onDataArgs.Data, onDataArgs.Cookie);
                    break;
                default:
                    Debug.WriteLine("Error, unknown function.");
                    break;
            }

            // 
            this.requestStatistics.OnSuccessfulRequest();

            // indicate that data is ready and we can continue
            readyEvent.Set();
        }
コード例 #3
0
ファイル: VKGroupsForm.cs プロジェクト: rcsir/RuNetImporter
        private void OnData(object vkRestApi, OnDataEventArgs onDataArgs)
        {
            switch (onDataArgs.Function)
            {
                case VkFunction.WallGet:
                    OnWallGet(onDataArgs.Data);
                    break;
                case VkFunction.WallGetComments:
                    OnWallGetComments(onDataArgs.Data, onDataArgs.Cookie);
                    break;
                case VkFunction.GroupsGetMembers:
                    OnGroupsGetMembers(onDataArgs.Data, onDataArgs.Cookie);
                    break;
                case VkFunction.FriendsGet:
                    OnGetFriends(onDataArgs.Data, onDataArgs.Cookie);
                    break;
                case VkFunction.GroupsGetById:
                    OnGroupsGetById(onDataArgs.Data, onDataArgs.Cookie);
                    break;
                case VkFunction.GetProfiles:
                    OnLoadUserInfo(onDataArgs.Data);
                    break;
                case VkFunction.LikesGetList:
                    OnLikesGetList(onDataArgs.Data);
                    break;
                case VkFunction.UsersGet:
                    OnUsersGet(onDataArgs.Data);
                    break;
                case VkFunction.LoadFriends:
                    OnLoadFriends(onDataArgs.Data);
                    break;
                case VkFunction.FriendsGetMutual:
                    OnGetMutual(onDataArgs.Data, onDataArgs.Cookie);
                    break;
                case VkFunction.StatsGet:
                    OnStatsGet(onDataArgs.Data);
                    break;
                default:
                    Debug.WriteLine("Error, unknown function.");
                    break;
            }

            // indicate that data is ready and we can continue
            ReadyEvent.Set();
        }
コード例 #4
0
ファイル: VKContentForm.cs プロジェクト: rcsir/RuNetImporter
        private void OnData(object restApi, OnDataEventArgs onDataArgs)
        {
            switch (onDataArgs.Function)
            {
                case VkFunction.WallGet:
                    OnWallGet(onDataArgs.Data);
                    break;
                case VkFunction.WallGetComments:
                    OnWallGetComments(onDataArgs.Data, onDataArgs.Cookie);
                    break;
                case VkFunction.GroupsGetById:
                    OnGroupsGetById(onDataArgs.Data, onDataArgs.Cookie);
                    break;
                case VkFunction.GetProfiles:
                    //OnLoadUserInfo(onDataArgs.data);
                    break;
                case VkFunction.LikesGetList:
                    OnLikesGetList(onDataArgs.Data, onDataArgs.Cookie);
                    break;
                case VkFunction.UsersGet:
                    OnUsersGet(onDataArgs.Data);
                    break;
                case VkFunction.BoardGetTopics:
                    OnBoardGetTopics(onDataArgs.Data, onDataArgs.Cookie);
                    break;
                case VkFunction.BoardGetComments:
                    OnBoardGetComments(onDataArgs.Data, onDataArgs.Cookie);
                    break;
                case VkFunction.PhotosSearch:
                    // OnPhotosSearch(onDataArgs.Data, onDataArgs.Cookie);
                    break;
                case VkFunction.StatsGet:
                    //OnStatsGet(onDataArgs.data);
                    break;
                default:
                    Debug.WriteLine("Error, unknown function.");
                    break;
            }

            // indicate that data is ready and we can continue
            ReadyEvent.Set();
        }
コード例 #5
0
ファイル: VKRestApi.cs プロジェクト: rcsir/RuNetImporter
        // make REST call to VK services
        private void MakeRestCall(VkFunction function, String uri, VkRestContext context)
        {
            if (OnData == null || OnError == null) 
                throw new ArgumentException("OnData and OnError handlers must be provided");

            try
            {
                // Create URI 
                var address = new Uri(uri);
                Debug.WriteLine("REST call: " + address);

                // Create the web request 
                var request = WebRequest.Create(address) as HttpWebRequest;

                if (request == null)
                {
                    var args = new OnErrorEventArgs(function, context, CriticalErrorCode, CriticalErrorText, "Request object is null");
                    OnError(this, args);
                    return;
                }

                // Set type to Get 
                request.Method = GetMethod;
                request.ContentType = ContentType;
                request.Accept = ContentAccept;

                // Get response 
                using (var response = request.GetResponse() as HttpWebResponse)
                {
                    if (response == null)
                    {
                        var args = new OnErrorEventArgs(function, context, CriticalErrorCode, CriticalErrorText, "Response object is null");
                        OnError(this, args);
                        return;
                    }

                    var responseStream = response.GetResponseStream();
                    if (responseStream == null)
                    {
                        var args = new OnErrorEventArgs(function, context, CriticalErrorCode, CriticalErrorText, "Response stream is null");
                        OnError(this, args);
                        return;
                    }

                    var responseCode = (int)response.StatusCode;
                    if (responseCode < 300)
                    {

                        string responseBody;

                        try
                        {
                            responseBody = ((new StreamReader(responseStream)).ReadToEnd());
                        }
                        catch (IOException e)
                        {
                            var args = new OnErrorEventArgs(function, context, CriticalErrorCode, 
                                CriticalErrorText, e.Message);
                            OnError(this, args);
                            return;                            
                        }

                        //var contentType = response.ContentType;
                        var o = JObject.Parse(responseBody);
                        if (o[ResponseBody] != null)
                        {
                            var args = new OnDataEventArgs(function, o, context.Cookie);
                            OnData(this, args);
                        }
                        else if (o[ErrorBody] != null)
                        {
                            long code = 0;
                            var error = "";
                            if (o[ErrorBody]["error_code"] != null)
                            {
                                code = o[ErrorBody]["error_code"].ToObject<long>();
                            }
                            if (o[ErrorBody]["error_msg"] != null)
                            {
                                error = o[ErrorBody]["error_msg"].ToString();
                            }

                            var args = new OnErrorEventArgs(function, context, code, error, o[ErrorBody].ToString());
                            OnError(this, args);
                        }
                    }
                    else
                    {
                        var args = new OnErrorEventArgs(function, context, CriticalErrorCode, CriticalErrorText, "Unexpected response code: " + responseCode);
                        OnError(this, args);
                    }
                }
            }
            catch (WebException exception)
            {
                HandleWebException(function, exception, context);
            }
        }
コード例 #6
0
ファイル: VKFinderForm.cs プロジェクト: rcsir/RuNetImporter
        private void OnData(object vkRestApi, OnDataEventArgs onDataArgs)
        {
            switch (onDataArgs.Function)
            {
                case VkFunction.UsersSearch:
                    OnUsersSearch(onDataArgs.Data);
                    break;
                case VkFunction.DatabaseGetCountries:
                    OnGetCountries(onDataArgs.Data);
                    break;
                case VkFunction.DatabaseGetRegions:
                    OnGetRegions(onDataArgs.Data);
                    break;
                case VkFunction.DatabaseGetCities:
                    OnGetCities(onDataArgs.Data);
                    break;
                default:
                    Debug.WriteLine("Error, unknown function.");
                    break;
            }

            // indicate that data is ready and we can continue
            readyEvent.Set();
        }