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); } }
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); } }
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); } }
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)); } }
/// <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); } }
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)); } }
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); } }
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); } } }
public void CreateLevel(Level level) { try { using (var ctx = new ucsdbEntities(m_vConnectionString)) { var newPlayer = new player { PlayerId = level.GetPlayerAvatar().GetId(), AccountStatus = level.GetAccountStatus(), AccountPrivileges = level.GetAccountPrivileges(), LastUpdateTime = level.GetTime(), IPAddress = level.GetIPAddress(), Avatar = level.GetPlayerAvatar().SaveToJson(), GameObjects = level.SaveToJson() }; ctx.player.Add(newPlayer); ctx.SaveChanges(); } } catch (Exception ex) { ExceptionLogger.Log(ex, "Exception while trying to create a new player account in database."); } }
/// <summary> /// This function create a new player in the database, with default parameters. /// </summary> /// <param name="l">The level of the player.</param> public void CreateAccount(Level l) { try { using (ucsdbEntities db = new ucsdbEntities(m_vConnectionString)) { db.player.Add( new player { PlayerId = l.GetPlayerAvatar().GetId(), AccountStatus = l.GetAccountStatus(), AccountPrivileges = l.GetAccountPrivileges(), LastUpdateTime = l.GetTime(), IPAddress = l.GetIPAddress(), Avatar = l.GetPlayerAvatar().SaveToJSON(), GameObjects = l.SaveToJSON() } ); db.SaveChanges(); } } catch (Exception ex) { //Debugger.WriteLine("[UCS] An exception occured during CreateAccount processing :", ex); } }
public void CreateAccount(Level l) { try { Debugger.WriteLine("Saving new account to database (player id: " + l.GetPlayerAvatar().GetId() + ")", null, 0); using (var db = new ucsdbEntities(m_vConnectionString)) { db.player.Add( new player { PlayerId = l.GetPlayerAvatar().GetId(), AccountStatus = l.GetAccountStatus(), AccountPrivileges = l.GetAccountPrivileges(), LastUpdateTime = l.GetTime(), Avatar = l.GetPlayerAvatar().SaveToJSON(), GameObjects = l.SaveToJSON() } ); db.SaveChanges(); } } catch (Exception ex) { Debugger.WriteLine("An exception occured during CreateAccount processing:", ex); } }
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(); } }
/// <summary> /// This function create a new player in the database, with default parameters. /// </summary> /// <param name="l">The level of the player.</param> public void CreateAccount(Level l) { try { using (ucsdbEntities db = new ucsdbEntities(m_vConnectionString)) { db.player.Add( new player { PlayerId = l.GetPlayerAvatar().GetId(), AccountStatus = l.GetAccountStatus(), AccountPrivileges = l.GetAccountPrivileges(), LastUpdateTime = l.GetTime(), IPAddress = l.GetIPAddress(), Avatar = l.GetPlayerAvatar().SaveToJSON(), GameObjects = l.SaveToJSON() } ); db.SaveChanges(); } } catch (Exception ex) { Logger.Write("Error when try to Create an Account " + ex); } }
/// <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 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); } }
public void RemoveAlliance(Alliance alliance) { using (var db = new ucsdbEntities(m_vConnectionString)) { db.clan.Remove(db.clan.Find((int)alliance.GetAllianceId())); db.SaveChanges(); } }
/// <summary> /// This function remove an alliance from database. /// </summary> /// <param name="alliance">The Alliance of the alliance.</param> public void RemoveAlliance(Alliance alliance) { long id = alliance.GetAllianceId(); using (ucsdbEntities db = new ucsdbEntities(m_vConnectionString)) { db.clan.Remove(db.clan.Find((int)id)); db.SaveChanges(); } ObjectManager.RemoveInMemoryAlliance(id); }
public void RemoveAlliance(Alliance alliance) { long allianceId = alliance.GetAllianceId(); using (ucsdbEntities ucsdbEntities = new ucsdbEntities(this.m_vConnectionString)) { ucsdbEntities.clan.Remove(ucsdbEntities.clan.Find(new object[] { (int)allianceId })); ucsdbEntities.SaveChanges(); } ObjectManager.RemoveInMemoryAlliance(allianceId); }
public void Save(Level avatar) { Debugger.WriteLine( "Starting saving player " + avatar.GetPlayerAvatar().GetAvatarName() + " from memory to database at " + DateTime.Now, null, 5, ConsoleColor.DarkGreen); var context = new ucsdbEntities(m_vConnectionString); context.Configuration.AutoDetectChangesEnabled = false; context.Configuration.ValidateOnSaveEnabled = false; context = avatar.SaveToDatabse(context); context.SaveChanges(); Debugger.WriteLine( "Finished saving player " + avatar.GetPlayerAvatar().GetAvatarName() + " from memory to database at " + DateTime.Now, null, 5, ConsoleColor.DarkGreen); }
public void CreateAlliance(Clan a) { try { Debug.Write("Saving new Alliance to database (alliance id: " + a.GetAllianceId() + ")"); using (var db = new ucsdbEntities(m_vConnectionString)) { db.Clans.Add(new clan { ClanId = a.GetAllianceId(), LastUpdateTime = DateTime.Now, Data = a.SaveToJSON() }); db.SaveChanges(); } } catch (Exception ex) { Debug.Write("An exception occured during CreateAlliance processing:" + Debug.FlattenException(ex)); } }
public void CreateAlliance(Alliance a) { try { using (ucsdbEntities ucsdbEntities = new ucsdbEntities(this.m_vConnectionString)) { ucsdbEntities.clan.Add(new clan { ClanId = a.GetAllianceId(), LastUpdateTime = DateTime.Now, Data = a.SaveToJSON() }); ucsdbEntities.SaveChanges(); } } catch (Exception ex) { Debugger.WriteLine("[CRS] An exception occured during CreateAlliance processing :", ex, 4); } }
/// <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); }
/// <summary> /// This function create a new alliance in the database, with default parameters. /// </summary> /// <param name="a">The alliance data.</param> public void CreateAlliance(Alliance a) { try { using (ucsdbEntities db = new ucsdbEntities(m_vConnectionString)) { db.clan.Add( new clan { ClanId = a.GetAllianceId(), LastUpdateTime = DateTime.Now, Data = a.SaveToJSON() } ); db.SaveChanges(); } } catch (Exception ex) { _Logger.Print(" An exception occured during CreateAlliance processing :", Types.ERROR); } }
/// <summary> /// This function create a new alliance in the database, with default parameters. /// </summary> /// <param name="a">The alliance data.</param> public void CreateAlliance(Alliance a) { try { using (ucsdbEntities db = new ucsdbEntities(m_vConnectionString)) { db.clan.Add( new clan { ClanId = a.GetAllianceId(), LastUpdateTime = DateTime.Now, Data = a.SaveToJSON() } ); db.SaveChanges(); } } catch (Exception ex) { Logger.Write("Error when try to Create an Alliance " + ex); } }
public void CreateAlliance(Alliance alliance) { try { using (var ctx = new ucsdbEntities(m_vConnectionString)) { var newClan = new clan { ClanId = alliance.GetAllianceId(), LastUpdateTime = DateTime.Now, Data = alliance.SaveToJson() }; ctx.clan.Add(newClan); ctx.SaveChanges(); } } catch (Exception ex) { ExceptionLogger.Log(ex, "Exception while trying to create a new alliance in database."); } }
/// <summary> /// This function create a new alliance in the database, with default parameters. /// </summary> /// <param name="a">The alliance data.</param> public void CreateAlliance(Alliance a) { try { using (var db = new ucsdbEntities(m_vConnectionString)) { db.clan.Add( new clan { ClanId = a.GetAllianceId(), LastUpdateTime = DateTime.Now, Data = a.SaveToJSON() } ); db.SaveChanges(); } } catch (Exception ex) { Debugger.WriteLine("[UCS][UCSDB] An exception occured during CreateAlliance processing :", ex); } }
public void CreateAlliance(Alliance a) { try { Debugger.WriteLine("Saving new Alliance to database (alliance id: " + a.GetAllianceId() + ")", null, 0); using (var db = new ucsdbEntities(m_vConnectionString)) { db.clan.Add( new clan { ClanId = a.GetAllianceId(), LastUpdateTime = DateTime.Now, Data = a.SaveToJSON() } ); db.SaveChanges(); } } catch (Exception ex) { Debugger.WriteLine("An exception occured during CreateAlliance processing:", ex, 0, ConsoleColor.DarkRed); } }
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(); } }
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(); }