Esempio n. 1
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);
            }
        }
Esempio n. 2
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));
                    }
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Записать в базу список пользователей (без связей)
 /// </summary>
 /// <param name="Users"></param>
 /// <returns></returns>
 public bool WriteVKUsers(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, DateTimeAdapter(User.bday), User.country, User.city, User.interests,
                                                                           User.music, User.movies, User.games, User.about)
                                                             );
             User.ORID = commandResult.ToDocument().ORID.ToString();
         }
         return(true);
     }
 }