Example #1
0
 public void Save(Alliance alliance)
 {
     using (ucsdbEntities context = new ucsdbEntities(m_vConnectionString))
     {
         context.Configuration.AutoDetectChangesEnabled = false;
         context.Configuration.ValidateOnSaveEnabled    = false;
         clan 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()
             }
                 );
         }
         context.SaveChanges();
     }
 }
Example #2
0
 public void Save(Alliance alliance)
 {
     Debugger.WriteLine("Starting saving clan " + alliance.GetAllianceName() + " from memory to database at " + DateTime.Now);
     using (var context = new ucsdbEntities(m_vConnectionString))
     {
         context.Configuration.AutoDetectChangesEnabled = false;
         context.Configuration.ValidateOnSaveEnabled    = false;
         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()
             }
                 );
         }
         context.SaveChanges();
         Debugger.WriteLine("Finished saving clan " + alliance.GetAllianceName() + " from memory to database at " + DateTime.Now);
     }
 }
Example #3
0
        /// <summary>
        ///     This function save a specific player in the database.
        /// </summary>
        /// <param name="avatar">The level of the player.</param>
        public void Save(Level avatar)
        {
            ucsdbEntities context = new ucsdbEntities(m_vConnectionString);

            context.Configuration.AutoDetectChangesEnabled = false;
            context.Configuration.ValidateOnSaveEnabled    = false;
            player p = context.player.Find(avatar.GetPlayerAvatar().GetId());

            if (p != null)
            {
                p.LastUpdateTime       = avatar.GetTime();
                p.AccountStatus        = avatar.GetAccountStatus();
                p.AccountPrivileges    = avatar.GetAccountPrivileges();
                p.IPAddress            = avatar.GetIPAddress();
                p.Avatar               = avatar.GetPlayerAvatar().SaveToJSON();
                p.GameObjects          = avatar.SaveToJSON();
                context.Entry(p).State = EntityState.Modified;
            }
            else
            {
                context.player.Add(
                    new player
                {
                    PlayerId          = avatar.GetPlayerAvatar().GetId(),
                    AccountStatus     = avatar.GetAccountStatus(),
                    AccountPrivileges = avatar.GetAccountPrivileges(),
                    LastUpdateTime    = avatar.GetTime(),
                    IPAddress         = avatar.GetIPAddress(),
                    Avatar            = avatar.GetPlayerAvatar().SaveToJSON(),
                    GameObjects       = avatar.SaveToJSON()
                }
                    );
            }
            context.SaveChanges();
        }
        public async Task Save(Alliance alliance)
        {
            using (ucsdbEntities ctx = new ucsdbEntities(m_vConnectionString))
            {
                ctx.Configuration.AutoDetectChangesEnabled = false;
                ctx.Configuration.ValidateOnSaveEnabled    = false;
                clan c = await ctx.clan.FindAsync((int)alliance.GetAllianceId());

                if (c != null)
                {
                    c.LastUpdateTime   = DateTime.Now;
                    c.Data             = alliance.SaveToJson();
                    ctx.Entry(c).State = EntityState.Modified;
                }
                //else
                //{
                //    context.clan.Add(
                //        new clan
                //        {
                //            ClanId = alliance.GetAllianceId(),
                //            LastUpdateTime = DateTime.Now,
                //            Data = alliance.SaveToJSON()
                //        });
                //}
                await ctx.SaveChangesAsync();
            }
        }
Example #5
0
        public ucsdbEntities SaveToDatabse(ucsdbEntities context)
        {
            var p = context.player.Find(GetPlayerAvatar().GetId());

            if (p != null)
            {
                p.LastUpdateTime       = GetTime();
                p.AccountStatus        = GetAccountStatus();
                p.AccountPrivileges    = GetAccountPrivileges();
                p.Avatar               = GetPlayerAvatar().SaveToJSON();
                p.GameObjects          = SaveToJSON();
                context.Entry(p).State = EntityState.Modified;
            }
            else
            {
                context.player.Add(
                    new player
                {
                    PlayerId          = GetPlayerAvatar().GetId(),
                    AccountStatus     = GetAccountStatus(),
                    AccountPrivileges = GetAccountPrivileges(),
                    LastUpdateTime    = GetTime(),
                    Avatar            = GetPlayerAvatar().SaveToJSON(),
                    GameObjects       = SaveToJSON()
                }
                    );
            }
            return(context);
        }
Example #6
0
 public void Save(List <Level> avatars)
 {
     try
     {
         using (ucsdbEntities ucsdbEntities = new ucsdbEntities(this.m_vConnectionString))
         {
             ucsdbEntities.Configuration.AutoDetectChangesEnabled = false;
             ucsdbEntities.Configuration.ValidateOnSaveEnabled    = false;
             int num = 0;
             foreach (Level current in avatars)
             {
                 Level obj = current;
                 lock (obj)
                 {
                     player player = ucsdbEntities.player.Find(new object[]
                     {
                         current.GetPlayerAvatar().GetId()
                     });
                     if (player != null)
                     {
                         player.LastUpdateTime    = current.GetTime();
                         player.AccountStatus     = current.GetAccountStatus();
                         player.AccountPrivileges = current.GetAccountPrivileges();
                         player.IPAddress         = current.GetIPAddress();
                         player.Avatar            = current.GetPlayerAvatar().SaveToJSON();
                         player.GameObjects       = current.SaveToJSON();
                         ucsdbEntities.Entry <player>(player).State = System.Data.Entity.EntityState.Modified;
                     }
                     else
                     {
                         ucsdbEntities.player.Add(new player
                         {
                             PlayerId          = current.GetPlayerAvatar().GetId(),
                             AccountStatus     = current.GetAccountStatus(),
                             AccountPrivileges = current.GetAccountPrivileges(),
                             LastUpdateTime    = current.GetTime(),
                             IPAddress         = current.GetIPAddress(),
                             Avatar            = current.GetPlayerAvatar().SaveToJSON(),
                             GameObjects       = current.SaveToJSON()
                         });
                     }
                 }
             }
             num++;
             if (num >= 500)
             {
                 ucsdbEntities.SaveChanges();
                 num = 0;
             }
             ucsdbEntities.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Debugger.WriteLine("[CRS]    An exception occured during Save processing for avatars :", ex, 4);
     }
 }
Example #7
0
 public void Save(List <Level> avatars)
 {
     try
     {
         using (ucsdbEntities context = new ucsdbEntities(m_vConnectionString))
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             context.Configuration.ValidateOnSaveEnabled    = false;
             int transactionCount = 0;
             foreach (Level pl in avatars)
             {
                 lock (pl)
                 {
                     player p = context.player.Find(pl.GetPlayerAvatar().GetId());
                     if (p != null)
                     {
                         p.LastUpdateTime       = pl.GetTime();
                         p.AccountStatus        = pl.GetAccountStatus();
                         p.AccountPrivileges    = pl.GetAccountPrivileges();
                         p.IPAddress            = pl.GetIPAddress();
                         p.Avatar               = pl.GetPlayerAvatar().SaveToJSON();
                         p.GameObjects          = pl.SaveToJSON();
                         context.Entry(p).State = EntityState.Modified;
                     }
                     else
                     {
                         context.player.Add(
                             new player
                         {
                             PlayerId          = pl.GetPlayerAvatar().GetId(),
                             AccountStatus     = pl.GetAccountStatus(),
                             AccountPrivileges = pl.GetAccountPrivileges(),
                             LastUpdateTime    = pl.GetTime(),
                             IPAddress         = pl.GetIPAddress(),
                             Avatar            = pl.GetPlayerAvatar().SaveToJSON(),
                             GameObjects       = pl.SaveToJSON()
                         }
                             );
                     }
                 }
             }
             transactionCount++;
             if (transactionCount >= 500)
             {
                 context.SaveChanges();
                 transactionCount = 0;
             }
             context.SaveChanges();
         }
         //Debugger.WriteLine("[UCS]    All players in memory has been saved to database at " + DateTime.Now);
     }
     catch (Exception ex)
     {
         //Debugger.WriteLine("[UCS]    An exception occured during Save processing for avatars :", ex);
     }
 }
Example #8
0
        public static void Save(List <Level> avatars)
        {
            Debug.Write("Starting saving players from memory to database at " + DateTime.Now.ToString());
            try
            {
                using (var context = new ucsdbEntities(m_vConnectionString))
                {
                    context.Configuration.AutoDetectChangesEnabled = false;
                    context.Configuration.ValidateOnSaveEnabled    = false;
                    int transactionCount = 0;
                    foreach (Level pl in avatars)
                    {
                        lock (pl)
                        {
                            var p = context.Players.Find(pl.GetPlayerAvatar().GetId());
                            if (p != null)
                            {
                                p.LastUpdateTime       = pl.GetTime();
                                p.AccountStatus        = pl.GetAccountStatus();
                                p.AccountPrivileges    = pl.GetAccountPrivileges();
                                p.Avatar               = pl.GetPlayerAvatar().SaveToJSON();
                                p.GameObjects          = pl.SaveToJSON();
                                context.Entry(p).State = EntityState.Modified;
                            }
                            else
                            {
                                context.Players.Add(new player {
                                    PlayerId          = pl.GetPlayerAvatar().GetId(),
                                    AccountStatus     = pl.GetAccountStatus(),
                                    AccountPrivileges = pl.GetAccountPrivileges(),
                                    LastUpdateTime    = pl.GetTime(),
                                    Avatar            = pl.GetPlayerAvatar().SaveToJSON(),
                                    GameObjects       = pl.SaveToJSON()
                                });
                            }
                        }

                        transactionCount++;
                        if (transactionCount >= 500)
                        {
                            context.SaveChanges();
                            transactionCount = 0;
                        }
                    }

                    context.SaveChanges();
                }

                Debug.Write("Finished saving players from memory to database at " + DateTime.Now.ToString());
            }
            catch (Exception ex)
            {
                Debug.Write("An exception occured during Save processing for avatars:" + Debug.FlattenException(ex));
            }
        }
Example #9
0
 /// <summary>
 ///     This function save a specific alliance in the database.
 /// </summary>
 /// <param name="alliances">The Alliance of the alliance.</param>
 public void Save(List <Alliance> alliances)
 {
     try
     {
         using (ucsdbEntities context = new ucsdbEntities(m_vConnectionString))
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             context.Configuration.ValidateOnSaveEnabled    = false;
             int transactionCount = 0;
             foreach (Alliance alliance in alliances)
             {
                 lock (alliance)
                 {
                     clan 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();
                 context.SaveChanges();
                 context.SaveChanges();
                 transactionCount = 0;
             }
             context.SaveChanges();
         }
         //Debugger.WriteLine("[UCS]    All alliances in memory has been saved to database at " + DateTime.Now);
     }
     catch (Exception ex)
     {
         //Debugger.WriteLine("[UCS]    An exception occured during Save processing for alliances :", ex);
     }
 }
Example #10
0
        public void Save(List <Clan> alliances)
        {
            Debug.Write("Starting saving alliances from memory to database at " + DateTime.Now.ToString());
            try
            {
                using (var context = new ucsdbEntities(m_vConnectionString))
                {
                    context.Configuration.AutoDetectChangesEnabled = false;
                    context.Configuration.ValidateOnSaveEnabled    = false;
                    int transactionCount = 0;
                    foreach (Clan alliance in alliances)
                    {
                        lock (alliance)
                        {
                            var c = context.Clans.Find((int)alliance.GetAllianceId());
                            if (c != null)
                            {
                                c.LastUpdateTime       = DateTime.Now;
                                c.Data                 = alliance.SaveToJSON();
                                context.Entry(c).State = EntityState.Modified;
                            }
                            else
                            {
                                context.Clans.Add(new clan {
                                    ClanId         = alliance.GetAllianceId(),
                                    LastUpdateTime = DateTime.Now,
                                    Data           = alliance.SaveToJSON()
                                });
                            }
                        }

                        transactionCount++;
                        if (transactionCount >= 500)
                        {
                            context.SaveChanges();
                            transactionCount = 0;
                        }
                    }

                    context.SaveChanges();
                }

                Debug.Write("Finished saving alliances from memory to database at " + DateTime.Now);
            }
            catch (Exception ex)
            {
                Debug.Write("An exception occured during Save processing for alliances:" + Debug.FlattenException(ex));
            }
        }
Example #11
0
 public void Save(List <Alliance> alliances)
 {
     try
     {
         using (ucsdbEntities ucsdbEntities = new ucsdbEntities(this.m_vConnectionString))
         {
             ucsdbEntities.Configuration.AutoDetectChangesEnabled = false;
             ucsdbEntities.Configuration.ValidateOnSaveEnabled    = false;
             int num = 0;
             foreach (Alliance current in alliances)
             {
                 Alliance obj = current;
                 lock (obj)
                 {
                     clan clan = ucsdbEntities.clan.Find(new object[]
                     {
                         (int)current.GetAllianceId()
                     });
                     if (clan != null)
                     {
                         clan.LastUpdateTime = DateTime.Now;
                         clan.Data           = current.SaveToJSON();
                         ucsdbEntities.Entry <clan>(clan).State = System.Data.Entity.EntityState.Modified;
                     }
                     else
                     {
                         ucsdbEntities.clan.Add(new clan
                         {
                             ClanId         = current.GetAllianceId(),
                             LastUpdateTime = DateTime.Now,
                             Data           = current.SaveToJSON()
                         });
                     }
                 }
             }
             num++;
             if (num >= 500)
             {
                 ucsdbEntities.SaveChanges();
                 num = 0;
             }
             ucsdbEntities.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Debugger.WriteLine("[CRS]    An exception occured during Save processing for alliances :", ex, 4);
     }
 }
Example #12
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);
         }
     }
 }
Example #13
0
 public async Task Save(List <Level> avatars)
 {
     try
     {
         using (ucsdbEntities context = new ucsdbEntities(m_vConnectionString))
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             context.Configuration.ValidateOnSaveEnabled    = false;
             foreach (Level pl in avatars)
             {
                 lock (pl)
                 {
                     player p = context.player.Find(pl.GetPlayerAvatar().GetId());
                     if (p != null)
                     {
                         p.LastUpdateTime       = pl.GetTime();
                         p.AccountStatus        = pl.GetAccountStatus();
                         p.AccountPrivileges    = pl.GetAccountPrivileges();
                         p.IPAddress            = pl.GetIPAddress();
                         p.Avatar               = pl.GetPlayerAvatar().SaveToJSON();
                         p.GameObjects          = pl.SaveToJSON();
                         context.Entry(p).State = EntityState.Modified;
                     }
                     else
                     {
                         context.player.Add(
                             new player
                         {
                             PlayerId          = pl.GetPlayerAvatar().GetId(),
                             AccountStatus     = pl.GetAccountStatus(),
                             AccountPrivileges = pl.GetAccountPrivileges(),
                             LastUpdateTime    = pl.GetTime(),
                             IPAddress         = pl.GetIPAddress(),
                             Avatar            = pl.GetPlayerAvatar().SaveToJSON(),
                             GameObjects       = pl.SaveToJSON()
                         });
                     }
                 }
             }
             await context.SaveChangesAsync();
         }
     }
     catch
     {
     }
 }
 public async Task Save(List <Level> levels)
 {
     try
     {
         using (var ctx = new ucsdbEntities(m_vConnectionString))
         {
             ctx.Configuration.AutoDetectChangesEnabled = false;
             ctx.Configuration.ValidateOnSaveEnabled    = false;
             foreach (Level pl in levels)
             {
                 lock (pl)
                 {
                     player p = ctx.player.Find(pl.GetPlayerAvatar().GetId());
                     if (p != null)
                     {
                         p.LastUpdateTime    = pl.GetTime();
                         p.AccountStatus     = pl.GetAccountStatus();
                         p.AccountPrivileges = pl.GetAccountPrivileges();
                         p.IPAddress         = pl.GetIPAddress();
                         p.Avatar            = pl.GetPlayerAvatar().SaveToJson();
                         p.GameObjects       = pl.SaveToJson();
                         ctx.Entry(p).State  = EntityState.Modified;
                     }
                     //else
                     //    context.player.Add(
                     //        new player
                     //        {
                     //            PlayerId = pl.GetPlayerAvatar().GetId(),
                     //            AccountStatus = pl.GetAccountStatus(),
                     //            AccountPrivileges = pl.GetAccountPrivileges(),
                     //            LastUpdateTime = pl.GetTime(),
                     //            IPAddress = pl.GetIPAddress(),
                     //            Avatar = pl.GetPlayerAvatar().SaveToJSON(),
                     //            GameObjects = pl.SaveToJSON()
                     //        });
                 }
             }
             await ctx.SaveChangesAsync();
         }
     }
     catch
     {
         // 0 Actual f***s given.
     }
 }
Example #15
0
        /// <summary>
        ///     This function save a specific player in the database.
        /// </summary>
        /// <param name="avatar">The level of the player.</param>
        public void Save(Level avatar)
        {
            Debugger.WriteLine(
                "Starting saving player " + avatar.GetPlayerAvatar().GetAvatarName() + " from memory to database at " +
                DateTime.Now, null, 4);
            var context = new ucsdbEntities(m_vConnectionString);

            context.Configuration.AutoDetectChangesEnabled = false;
            context.Configuration.ValidateOnSaveEnabled    = false;
            var p = context.player.Find(avatar.GetPlayerAvatar().GetId());

            if (p != null)
            {
                p.LastUpdateTime       = avatar.GetTime();
                p.AccountStatus        = avatar.GetAccountStatus();
                p.AccountPrivileges    = avatar.GetAccountPrivileges();
                p.IPAddress            = avatar.GetIPAddress();
                p.Avatar               = avatar.GetPlayerAvatar().SaveToJSON();
                p.GameObjects          = avatar.SaveToJSON();
                context.Entry(p).State = EntityState.Modified;
            }
            else
            {
                context.player.Add(
                    new player
                {
                    PlayerId          = avatar.GetPlayerAvatar().GetId(),
                    AccountStatus     = avatar.GetAccountStatus(),
                    AccountPrivileges = avatar.GetAccountPrivileges(),
                    LastUpdateTime    = avatar.GetTime(),
                    IPAddress         = avatar.GetIPAddress(),
                    Avatar            = avatar.GetPlayerAvatar().SaveToJSON(),
                    GameObjects       = avatar.SaveToJSON()
                }
                    );
            }
            context.SaveChanges();
            Debugger.WriteLine(
                "Finished saving player " + avatar.GetPlayerAvatar().GetAvatarName() + " from memory to database at " +
                DateTime.Now, null, 4);
        }
        public async Task Save(List <Alliance> alliances)
        {
            try
            {
                using (ucsdbEntities ctx = new ucsdbEntities(m_vConnectionString))
                {
                    ctx.Configuration.AutoDetectChangesEnabled = false;
                    ctx.Configuration.ValidateOnSaveEnabled    = false;
                    foreach (Alliance alliance in alliances)
                    {
                        lock (alliance)
                        {
                            clan c = ctx.clan.Find((int)alliance.GetAllianceId());
                            if (c != null)
                            {
                                c.LastUpdateTime   = DateTime.Now;
                                c.Data             = alliance.SaveToJson();
                                ctx.Entry(c).State = EntityState.Modified;
                            }
                            //else
                            //{
                            //    context.clan.Add(
                            //        new clan
                            //        {
                            //            ClanId = alliance.GetAllianceId(),
                            //            LastUpdateTime = DateTime.Now,
                            //            Data = alliance.SaveToJSON(),

                            //        });
                            //}
                        }
                    }
                    await ctx.SaveChangesAsync();
                }
            }
            catch
            {
                // 0 Actual f***s given.
            }
        }
Example #17
0
 public async Task Save(List <Alliance> alliances)
 {
     try
     {
         using (ucsdbEntities context = new ucsdbEntities(m_vConnectionString))
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             context.Configuration.ValidateOnSaveEnabled    = false;
             foreach (Alliance alliance in alliances)
             {
                 lock (alliance)
                 {
                     clan 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(),
                         });
                     }
                 }
             }
             await context.SaveChangesAsync();
         }
     }
     catch
     {
     }
 }
Example #18
0
        public void Save(Level avatar)
        {
            ucsdbEntities ucsdbEntities = new ucsdbEntities(this.m_vConnectionString);

            ucsdbEntities.Configuration.AutoDetectChangesEnabled = false;
            ucsdbEntities.Configuration.ValidateOnSaveEnabled    = false;
            player player = ucsdbEntities.player.Find(new object[]
            {
                avatar.GetPlayerAvatar().GetId()
            });

            if (player != null)
            {
                player.LastUpdateTime    = avatar.GetTime();
                player.AccountStatus     = avatar.GetAccountStatus();
                player.AccountPrivileges = avatar.GetAccountPrivileges();
                player.IPAddress         = avatar.GetIPAddress();
                player.Avatar            = avatar.GetPlayerAvatar().SaveToJSON();
                player.GameObjects       = avatar.SaveToJSON();
                ucsdbEntities.Entry <player>(player).State = System.Data.Entity.EntityState.Modified;
            }
            else
            {
                ucsdbEntities.player.Add(new player
                {
                    PlayerId          = avatar.GetPlayerAvatar().GetId(),
                    AccountStatus     = avatar.GetAccountStatus(),
                    AccountPrivileges = avatar.GetAccountPrivileges(),
                    LastUpdateTime    = avatar.GetTime(),
                    IPAddress         = avatar.GetIPAddress(),
                    Avatar            = avatar.GetPlayerAvatar().SaveToJSON(),
                    GameObjects       = avatar.SaveToJSON()
                });
            }
            ucsdbEntities.SaveChanges();
        }
        public void Save(Level level)
        {
            //TODO: This sometimes throws DbValidationExceptions.

            using (var ctx = new ucsdbEntities(m_vConnectionString))
            {
                ctx.Configuration.AutoDetectChangesEnabled = false;

                var player = ctx.player.Find(level.GetPlayerAvatar().GetId());
                if (player != null)
                {
                    player.LastUpdateTime    = level.GetTime();
                    player.AccountStatus     = level.GetAccountStatus();
                    player.AccountPrivileges = level.GetAccountPrivileges();
                    player.IPAddress         = level.GetIPAddress();
                    player.Avatar            = level.GetPlayerAvatar().SaveToJson();
                    player.GameObjects       = level.SaveToJson();

                    ctx.Entry(player).State = EntityState.Modified;
                }

                ctx.SaveChanges();
            }
        }