Beispiel #1
0
 public static Boolean FilterGroups(VK.VKMan vkman, string condition)
 {
     if (vkman.city.Contains(condition))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #2
0
 public static Boolean FilterUni(VK.VKMan vkman, string condition)
 {
     if (vkman.university_name.Contains(condition))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #3
0
 public static Boolean FilterInterests(VK.VKMan vkman, string condition)
 {
     if (vkman.interests.Contains(condition))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #4
0
        public void writeRecursiveUsers(VK.VKMan rootUser, VK.VKObjects vkInstance, int currDepth, int depth, List <MainWindow.conditionArr> listConditions)
        {
            using (ODatabase database = new ODatabase(opts))
            {
                var Users = vkInstance.getFriendsListFromXML(rootUser.id, listConditions);
                Statistic.Statistic.LogVertex(depth, Users.Count);
                foreach (VK.VKMan User in Users)
                {
                    string queryString = String.Format("UPDATE user set first_name='{0}', last_name='{1}', sex='{2}',bday='{3}',country='{4}'," +
                                                       "city='{5}',interests='{6}',music='{7}',movies='{8}',games='{9}',about='{10}', vkid='{11}'" +
                                                       " UPSERT WHERE vkid='{11}'",
                                                       User.first_name, User.last_name, User.sex, DateTimeAdapter(User.bday), User.country, User.city, User.interests,
                                                       User.music, User.movies, User.games, "", User.id);

                    string queryStringSelectORID = string.Format("SELECT FROM user WHERE vkid={0}", User.id);

                    try
                    {
                        OCommandResult commandResult           = database.Command(queryString);
                        OCommandResult commandSelectORIDResult = database.Command(queryStringSelectORID);
                        User.ORID = commandSelectORIDResult.ToDocument().GetField <ODocument>("Content").GetField <ORID>("@ORID").ToString();

                        List <ODocument> result = database.Query(queryStringSelectORID);
                        foreach (ODocument document in result)
                        {
                            User.ORID = document.ORID.ToString();
                        }
                        //Логируем
                        var comupsert = string.Format("CREATE EDGE Friend FROM {0} TO {1} SET weight={2}", rootUser.ORID, User.ORID, User.rootEdgeWeigth);
                        database.Command(string.Format("CREATE EDGE Friend FROM {0} TO {1} SET weight={2}", rootUser.ORID, User.ORID, User.rootEdgeWeigth));
                        //Statistic.Statistic.LogEdge(depth,);//Логгируем
                        if (currDepth < depth)
                        {
                            currDepth++;
                            writeRecursiveUsers(User, vkInstance, currDepth, depth, listConditions);
                            currDepth--;
                        }
                    }
                    catch (OException ex)
                    {
                        Statistic.Statistic.logError(ex.ToString());
                        Console.WriteLine(String.Format("There are problems with {0} {1}", User.first_name, User.last_name));
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Записать в базу друзей пользователя
        /// </summary>
        /// <param name="rootUser">Главнвый пользователь</param>
        /// <param name="Users">Его друзья</param>
        /// <returns></returns>
        public bool WriteVKUserFriends(VK.VKMan rootUser, List <VK.VKMan> Users)
        {
            using (ODatabase database = new ODatabase(opts))
            {
                foreach (VK.VKMan User in Users)
                {
                    /*
                     * byte[] bytes = Encoding.C.GetBytes();
                     * Encoding win1251 = Encoding.GetEncoding(1251);
                     * string text = win1251.GetString(bytes);
                     */
                    /*
                     * string queryString = String.Format("INSERT INTO user (first_name,last_name,sex,bday,country," +
                     *      "city,interests,music,movies,games,about)" +
                     *      " values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}')",
                     *      User.first_name, User.last_name, User.sex, DateTimeAdapter(User.bday), User.country, User.city, User.interests,
                     *      User.music, User.movies, User.games, "");
                     */

                    string queryString = String.Format("UPDATE user set first_name='{0}', last_name='{1}', sex='{2}',bday='{3}',country='{4}'," +
                                                       "city='{5}',interests='{6}',music='{7}',movies='{8}',games='{9}',about='{10}', vkid='{11}'" +
                                                       " UPSERT WHERE vkid='{11}'",
                                                       User.first_name, User.last_name, User.sex, DateTimeAdapter(User.bday), User.country, User.city, User.interests,
                                                       User.music, User.movies, User.games, "", User.id);

                    string queryStringSelectORID = string.Format("SELECT FROM user WHERE vkid={0}", User.id);

                    try {
                        /* OCommandResult commandResult = database.Command(queryString);
                         * OCommandResult commandSelectORIDResult = database.Command(queryStringSelectORID);
                         * User.ORID = commandSelectORIDResult.ToDocument().GetField<ODocument>("Content").GetField<ORID>("@ORID").ToString();
                         * database.Command(string.Format("CREATE EDGE FROM {0} TO {1} SET weight={2}", rootUser.ORID, User.ORID, calculateWeigth()));
                         */
                        List <ODocument> result = database.Query(queryStringSelectORID);
                        foreach (ODocument document in result)
                        {
                            User.ORID = document.ORID.ToString();
                        }
                    } catch (OException ex)
                    {
                        Console.WriteLine(String.Format("There are problems with {0} {1}", User.first_name, User.last_name));
                    }
                }
                return(true);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Записать в базу друзей пользователя
        /// </summary>
        /// <param name="rootUser">Главнвый пользователь</param>
        /// <param name="Users">Его друзья</param>
        /// <returns></returns>
        public bool WriteVKUserFriends(VK.VKMan rootUser, List <VK.VKMan> Users)
        {
            using (ODatabase database = new ODatabase(databaseAlias))
            {
                foreach (VK.VKMan User in Users)
                {
                    Console.WriteLine("User has been added");
                    OCommandResult commandResult = database.Command(String.Format("INSERT INTO user (first_name,last_name,sex,bday,country," +
                                                                                  "city,interests,music,movies,games,about)" +
                                                                                  "values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}')",
                                                                                  User.first_name, User.last_name, User.sex, "1900-10-10 00:00:00", User.country, User.city, User.interests,
                                                                                  User.music, User.movies, User.games, User.about)
                                                                    );
                    var test = commandResult.ToDocument()["ORID"];
                    User.ORID = commandResult.ToDocument().ORID.ToString();
                    database.Command(string.Format("CREATE EDGE FROM {0} TO {1} SET weight={2}", rootUser.ORID, User.ORID, calculateWeigth()));

                    var i = 0;
                }
                return(true);
            }
        }
Beispiel #7
0
        public List <VKMan> getFriendsListFromXML(int id, List <MainWindow.conditionArr> listConditions)
        {
            XmlDocument  XMLMen = getFriends(id, 500, 0, "hints", VKMan.fieldNeededList);
            List <VKMan> VKMen  = new List <VKMan>();
            DateTime     dateTemp;
            int          temp_int;
            string       UserIdList = "";

            //Перебираем users
            foreach (XmlNode userXML in XMLMen.DocumentElement?.ChildNodes[1]?.ChildNodes)
            {
                //Обработка ошибок
                if (userXML.Name != "error_code" && userXML.Name != "error_msg" && userXML.Name != "request_params" && userXML.InnerText != "Too many requests per second")
                {
                    XmlNodeList userNodes = userXML.ChildNodes;
                    //Обработка даты

                    //dateTemp = Convert.ToDateTime(userNodes[4].InnerText);
                    var bdate = userXML.SelectSingleNode("bdate")?.LastChild.Value;
                    try
                    {
                        dateTemp = (bdate is null) ? DateTime.MinValue : Convert.ToDateTime(bdate);
                    } catch
                    {
                        try
                        {
                            dateTemp = DateTime.ParseExact(bdate + ".2999", "dd.m.yyyy", System.Globalization.CultureInfo.InvariantCulture); //Convert.ToDateTime(bdate + ".2999");
                        }
                        catch { dateTemp = DateTime.MinValue; }
                    }



                    //TODO Надо выбирать по называнию узла, т.к. если там ниче нет, узел не передается
                    //Пометка: вроде передается пустой тег, так что все норм
                    //List<VKGroup> UserGroups = getUserGroups(Convert.ToInt32(userNodes[0].InnerText), "city");
                    List <VKGroup> UserGroups = new List <VKGroup>();

                    //Отсеиваем удаленных
                    char[] charsToTrim = { '*', ' ', '\'' };

                    //if (userXML.SelectSingleNode("first_name")?.InnerText != "DELETED" && userXML.SelectSingleNode("first_name")?.InnerText != "BANNED")
                    if (userXML.SelectSingleNode("deactivated") is null)
                    {
                        VKMan vkman_tmp = new VKMan
                                              (id: Convert.ToInt32(userXML.SelectSingleNode("id")?.InnerText),
                                              first_name: (userXML.SelectSingleNode("first_name")?.InnerText).Replace("'", ""),
                                              last_name: (userXML.SelectSingleNode("last_name")?.InnerText).Replace("'", ""),
                                              sex: relateSex(userXML.SelectSingleNode("sex")?.InnerText),
                                              bday: dateTemp,
                                              country: (userXML.SelectSingleNode("country")?.InnerText)?.Replace("'", "") ?? "",
                                              //city: getCityById(userNodes[5].InnerText) ?? "",
                                              city: "null",
                                              interests: (userXML.SelectSingleNode("interests")?.InnerText)?.Replace("'", "") ?? "",
                                              music: (userXML.SelectSingleNode("music")?.InnerText)?.Replace("'", "") ?? "",
                                              movies: (userXML.SelectSingleNode("movies")?.InnerText)?.Replace("'", "") ?? "",
                                              games: (userXML.SelectSingleNode("games")?.InnerText)?.Replace("'", "") ?? "",
                                              university_name: (userXML.SelectSingleNode("university_name")?.InnerText)?.Replace("'", "") ?? "",
                                              faculty_name: (userXML.SelectSingleNode("faculty_name")?.InnerText)?.Replace("'", "") ?? "",
                                              about: (userXML.SelectSingleNode("about")?.InnerText)?.Replace("'", "") ?? "",
                                              rootEdgeWeigth: 0,
                                              userGroups: UserGroups
                                              );

                        //Проверяем все фильтры
                        Boolean condResult = true;
                        foreach (MainWindow.conditionArr codition in listConditions)
                        {
                            condResult = codition.delegate_(vkman_tmp, codition.condition_);
                        }
                        if (condResult)
                        {
                            VKMen.Add(vkman_tmp);
                            UserIdList += VKMen.Last().id.ToString() + ',';
                        }
                    }
                }
                else
                {
                    Console.WriteLine(userXML.InnerText);
                }
            }
            //TODO: ошибка при большом (?) количестве друзей
            try {
                //Теперь задаем количество общих друзей. Для этого собрали ранее список id
                UserIdList = UserIdList.Substring(0, UserIdList.Length - 1);
                XmlDocument XMLMutualFriends = firendsGetMutual(id, null, UserIdList);
                foreach (XmlNode mutualFriends in XMLMutualFriends.DocumentElement.ChildNodes)
                {
                    XmlNodeList mutualNodes = mutualFriends.ChildNodes;
                    int.TryParse(mutualNodes[2].InnerText, out temp_int);

                    VKMen.Find(x => x.id.ToString() == mutualNodes[0].InnerText).rootEdgeWeigth = temp_int;
                }
            } catch (Exception ex)
            {
                Console.WriteLine("Ошибка веса графа");
            }


            //Группы пользователей очень сильно грузят api

            /*foreach(VKMan vkmen in VKMen)
             * {
             *  vkmen.userGroups = getUserGroups(Convert.ToInt32(vkmen.id), "city");
             * }
             */
            return(VKMen);
        }