Esempio n. 1
0
    private void SaveProcess(List <Level> avatars)
    {
        var context = new ucsdbEntities(m_vConnectionString);

        context.Configuration.AutoDetectChangesEnabled = false;
        context.Configuration.ValidateOnSaveEnabled    = false;
        var transactionCount = 0;

        try
        {
            foreach (var pl in avatars)
            {
                lock (pl)
                {
                    context = pl.SaveToDatabse(context);
                }
                transactionCount++;
                if (transactionCount >= 100)
                {
                    context.SaveChanges();
                    transactionCount = 0;
                }
            }
            context.SaveChanges();
            context.Dispose();
        }
        catch (Exception ex)
        {
            MainWindow.RemoteWindow.WriteConsole("Exception when saving: " + ex, (int)MainWindow.level.FATAL);
        }
    }
Esempio n. 2
0
        public List <long> GetAllPlayerIds()
        {
            var           ids = new List <long>();
            List <player> players;

            using (var db = new ucsdbEntities(m_vConnectionString))
            {
                players = db.player.ToList();
                db.Dispose();
            }
            players.ForEach(p => ids.Add(p.PlayerId));
            return(ids);
        }
Esempio n. 3
0
 private void SaveProcess(List <Alliance> alliances)
 {
     using (var context = new ucsdbEntities(m_vConnectionString))
     {
         context.Configuration.AutoDetectChangesEnabled = false;
         context.Configuration.ValidateOnSaveEnabled    = false;
         var transactionCount = 0;
         try
         {
             foreach (var alliance in alliances)
             {
                 lock (alliance)
                 {
                     var c = context.clan.Find((int)alliance.GetAllianceId());
                     if (c != null)
                     {
                         c.LastUpdateTime       = DateTime.Now;
                         c.Data                 = alliance.SaveToJSON();
                         context.Entry(c).State = EntityState.Modified;
                     }
                     else
                     {
                         context.clan.Add(
                             new clan
                         {
                             ClanId         = alliance.GetAllianceId(),
                             LastUpdateTime = DateTime.Now,
                             Data           = alliance.SaveToJSON()
                         }
                             );
                     }
                 }
                 transactionCount++;
                 if (transactionCount >= 500)
                 {
                     context.SaveChanges();
                     transactionCount = 0;
                 }
             }
             context.SaveChanges();
             context.Dispose();
         }
         catch (Exception ex)
         {
             MainWindow.RemoteWindow.WriteConsole("Exception when saving Alliances: " + ex, (int)MainWindow.level.FATAL);
         }
     }
 }