public override Spawn2 GetNewSpawn() { Spawn2 spawn = new Spawn2(_queryConfig); int id = 1; if (Spawns.Count > 0) { id = Spawns.Max(x => x.Id) + 1; } spawn.Zone = _zone; spawn.Version = _version; spawn.Id = id; return spawn; }
public override IEnumerable<Spawn2> GetLinkedSpawn2() { List<Spawn2> spawns = new List<Spawn2>(); var query = _getSpawn2; if (query != null) { string sql = String.Format(query.SelectQuery, new string[] { Id.ToString() }); var results = Database.QueryHelper.RunQuery(_connection, sql); foreach (var row in results) { var spawn = new Spawn2(_queryConfig); spawn.SetProperties(query, row); spawns.Add(spawn); } } return spawns; }
public override Spawn2 GetNewSpawn() { Spawn2 spawn = new Spawn2(_queryConfig); spawn.Zone = _zone; int max = 1; if (Spawns.Count > 0) max = Spawns.Max(x => x.Id) + 1; //test if this exists... if it does get the true max value from DB bool exists = false; var sql = String.Format(_getMaxZoneId.SelectQuery, max); var results = Database.QueryHelper.RunQuery(_connection, sql); if (results != null) { if (results.Count > 0) { exists = true; } if (exists) { sql = String.Format(_getMaxId.SelectQuery); results = Database.QueryHelper.RunQuery(_connection, sql); if (results != null) { if (results.Count > 0) { if (results.ElementAt(0).ContainsKey("id")) { max = Int32.Parse(results.ElementAt(0)["id"].ToString()) + 1; } } } } } spawn.Id = max; spawn.Version = _version; return spawn; }
public void RemoveSpawn(Spawn2 spawn) { RemoveObject(spawn); }
/// <summary> /// Packs all currently loaded spawn entries by id field into the specified range; modifying their identifier field. /// i.e three spawns with id's (10,35,99) existing and PackTable called with parameters (5,10) /// will result in the three spawns having their id's updated to (5,6,7) /// </summary> /// <param name="start">the first id that will be used</param> /// <param name="end">the last id that will be used</param> public void PackTable(int start, int end) { if (start == end || start > end) { throw new ArgumentOutOfRangeException("Invalid range"); } int range = end - start; if (_spawns.Count > range) { throw new ArgumentOutOfRangeException("Range specified not large enough"); } IEnumerable<Spawn2> sorted = _spawns.OrderBy(x => x.Id); int i = start; NeedsInserted.Clear(); foreach (var spawn in sorted) { //if we are going to potentially re-insert them all somewhere we might as well delete them //the update query generates the delete queries first so this works //create a spawn that keeps track of the identifier so we can delete it //we aren't really requested a new spawn ... just a dummy reference for the id Spawn2 copy = new Spawn2(_queryConfig); copy.Id = spawn.Id; copy.Zone = Zone; copy.Version = Version; NeedsDeleted.Add(copy); spawn.Id = i; i += 1; NeedsInserted.Add(spawn); } }
public void AddSpawn(Spawn2 spawn) { AddObject(spawn); }
public void Lookup(string zone, int version) { _zone = zone; _version = version; UnlockObject(); string sql = ""; if (_version == -1) { sql = String.Format(_allVersions.SelectQuery, ResolveArgs(_allVersions.SelectArgs)); } else { sql = String.Format(SelectString, SelectArgValues); } var results = Database.QueryHelper.RunQuery(_connection, sql); if (results != null) { foreach (var row in results) { Spawn2 s = new Spawn2(_queryConfig); s.SetProperties(Queries, row); s.Created(); Spawns.Add(s); } } Created(); }