private void UpdateUsers() { var acos = new List <_Update013.User>(); using (var cmd = new DbCommandRedundant("SELECT idACO, Config FROM aco WHERE typACO=@typACO", Connection)) { cmd.Parameters.AddWithValue("@typACO", (int)SecurityObjectType.User); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var sr = new StringReader(reader.GetString("Config")); var serializer = new XmlSerializer(typeof(_Update013.User)); var aco = (_Update013.User)serializer.Deserialize(sr); aco.Id = reader.GetUInt64("idACO"); acos.Add(aco); } } } foreach (var aco in acos) { using (var cmd = new DbCommandRedundant("UPDATE aco SET Config=@Config WHERE idACO=@idACO", Connection)) { cmd.Parameters.AddWithValue("@idACO", aco.Id); cmd.Parameters.AddWithValue("@Config", JsonConvert.SerializeObject(aco)); if (cmd.ExecuteNonQuery() != 1) { throw new ApplicationException($"Update failed for user {aco.Id}"); } } } }
private void UpdateEngines() { var engines = new List <_Update013.Engine>(); using (var cmd = new DbCommandRedundant("SELECT idEngine, Config FROM engine", Connection)) using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var sr = new StringReader(reader.GetString("Config")); var serializer = new XmlSerializer(typeof(_Update013.Engine)); var engine = (_Update013.Engine)serializer.Deserialize(sr); engine.Id = reader.GetUInt64("idEngine"); engines.Add(engine); } } foreach (var engine in engines) { using (var cmd = new DbCommandRedundant("UPDATE engine SET Config=@Config where idEngine=@idEngine", Connection)) { cmd.Parameters.AddWithValue("@idEngine", engine.Id); cmd.Parameters.AddWithValue("@Config", JsonConvert.SerializeObject(engine)); if (cmd.ExecuteNonQuery() != 1) { throw new ApplicationException($"Update failed for engine {engine.Id}"); } } } using (var cmd = new DbCommandRedundant("ALTER TABLE engine CHANGE COLUMN Config Config JSON", Connection)) cmd.ExecuteNonQuery(); }
private void UpdateServers() { var servers = new List <_Update013.CasparServer>(); using (var cmd = new DbCommandRedundant("SELECT idServer, Config FROM server", Connection)) using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var sr = new StringReader(reader.GetString("Config")); var serializer = new XmlSerializer(typeof(_Update013.CasparServer)); var server = (_Update013.CasparServer)serializer.Deserialize(sr); server.Id = reader.GetUInt64("idServer"); servers.Add(server); } } foreach (var server in servers) { using (var cmd = new DbCommandRedundant("UPDATE server SET Config=@Config WHERE idServer=@idServer", Connection)) { cmd.Parameters.AddWithValue("@idServer", server.Id); cmd.Parameters.AddWithValue("@Config", JsonConvert.SerializeObject(server)); if (cmd.ExecuteNonQuery() != 1) { throw new ApplicationException($"Update failed for server {server.Id}"); } } } using (var cmd = new DbCommandRedundant("ALTER TABLE server CHANGE COLUMN Config Config JSON", Connection)) cmd.ExecuteNonQuery(); }
public override void Update() { BeginTransaction(); try { UpdateEngines(); UpdateServers(); UpdateUsers(); UpdateGroups(); using (var cmd = new DbCommandRedundant("ALTER TABLE aco CHANGE COLUMN Config Config JSON", Connection)) cmd.ExecuteNonQuery(); CommitTransaction(); } catch { RollbackTransaction(); throw; } }