void RequestFriendConnections(int depth = 1, string parameters = null) { _socialGraph = new Graph <string>(); _socialGraph.AddNode(_superUserID, _superUserPrimaryInfo); int socialGraphMark = 0; for (int i = 0; i < depth; i++) { List <string> targetIDs = new List <string>(); List <Dictionary <string, object> > targetData = new List <Dictionary <string, object> >(); var executeParameters = new List <Dictionary <string, string> >(); Dictionary <string, string> queryParameters = new Dictionary <string, string>(); List <string> sourceIDs = new List <string>(); int ArrayFringe = _socialGraph.Count; for (int j = socialGraphMark; j < ArrayFringe; j++) { executeParameters.Add(Utils.ExecuteRequestGeneration("friends.get", _socialGraph, j, sourceIDs, true, parameters)); if (j % 25 == 0 || _socialGraph.Count - 1 == j) { Thread.Sleep(350); var data = Methods.Execute(executeParameters); int c = 0; try { foreach (Dictionary <string, dynamic> items in data) { targetIDs = new List <string>(); targetData = new List <Dictionary <string, object> >(); foreach (var response in items["items"]) { targetIDs.Add(response["id"].ToString()); if (response.Count > 1) { response.Remove("id"); response.Remove("last_name"); response.Remove("first_name"); try { string[] year = response["bdate"].Split('.'); response.Remove("bdate"); response.Add("bdate", year[2]); } catch { } try { int sex = Convert.ToInt32(response["sex"]); response.Remove("sex"); if (sex == 1) { response.Add("sex", "женский"); } else if (sex == 2) { response.Add("sex", "мужской"); } } catch { } targetData.Add(response); } } if (targetData.Count == 0) { targetData = null; } GraphUtils.AddNodesAndConnections(_socialGraph, targetIDs, sourceIDs[c], targetData); //TODO: восстановить соответствующий getMutual c++; } } catch { c++; } executeParameters = new List <Dictionary <string, string> >(); socialGraphMark = j == 0 ? 1 : j; //для корректного чтения нод при глубине больше 1 } } } }
void RequestGroupsAndLikes() { int socialGraphMark = 0; List <string> targetIDs = new List <string>(); List <Dictionary <string, object> > targetData = new List <Dictionary <string, object> >(); var executeParameters = new List <Dictionary <string, string> >(); Dictionary <string, string> queryParameters = new Dictionary <string, string>(); List <string> sourceIDs = new List <string>(); int ArrayFringe = _socialGraph.Count; for (int j = socialGraphMark; j < ArrayFringe; j++) { executeParameters.Add(Utils.ExecuteRequestGeneration("groups.get", _socialGraph, j, sourceIDs)); if (j % 25 == 0 || _socialGraph.Count - 1 == j) { Thread.Sleep(350); var data = Methods.Execute(executeParameters); int c = 0; try { foreach (Dictionary <string, dynamic> items in data) { targetIDs = new List <string>(); targetData = new List <Dictionary <string, object> >(); foreach (var response in items["items"]) { if (_socialGraph.GroupsMembership.ContainsKey(response.ToString())) { _socialGraph.GroupsMembership[response.ToString()].Add(sourceIDs[c]); } else if (j == 0) { _socialGraph.GroupsMembership.Add(response.ToString(), new List <string> { sourceIDs[c] }); } var node = _socialGraph.FindNode(sourceIDs[c]); node.GroupsList.Add(response.ToString()); } //if (targetData.Count == 0) targetData = null; //GraphUtils.AddNodesAndConnections(_socialGraph, targetIDs, sourceIDs[c], targetData); c++; } } catch { } executeParameters = new List <Dictionary <string, string> >(); } } var keys = new List <string>(_socialGraph.GroupsMembership.Keys); foreach (var group in keys) { foreach (var user in _socialGraph.GroupsMembership[group]) { for (int i = 0; i < 1; i++) { try { if (_socialGraph.GroupsMembership[group].Contains(user)) { Thread.Sleep(350); if (user != null && user != "" && group != null && group != "") { var data = Methods.Execute(WebUtility.UrlEncode("var response={};\nvar posts = API.wall.get({\"owner_id\":\"" + "-" + group + "\",\"count\":24});\nif(posts.items!=null){\nvar b = 0;\nvar s = posts.items.length;\nwhile (s != 0){\nvar data = API.likes.isLiked({ \"user_id\":\"" + user + "\",\"type\":\"post\",\"owner_id\":\"" + "-" + group + "\",\"item_id\":posts.items[b].id});\nresponse=response+[{\"item_id\":posts.items[b].id, \"liked\":data.liked, \"body\":posts.items[b].text}];\nb =b+1;\ns=s-1;\n}\nreturn [{\"count\":posts.items.length,\"items\":response}];}\nelse{return [{\"items\":0}];}\n")); GraphUtils.AddLikesAndPublications(_socialGraph, group, user, (Dictionary <string, dynamic>)data[0]); } } } catch { } } } } }