public static void RunEmbeddedFile(NpgsqlConnection connection, NpgsqlTransaction transaction, string resourceFileName, List <KeyValuePair <Guid, string> > failedScripts, List <Guid> successOrderScripts, nHydrateDbObjectList _databaseItems, InstallSetup setup) { var timer = Stopwatch.StartNew(); var tempFolder = string.Empty; var scripts = ReadSQLFileSectionsFromResource(resourceFileName, setup); Log.Verbose(TheDate + " Start File=" + Extensions.StripResourceAssem(resourceFileName)); #region Load script hashes var runScript = !setup.UseHash; var current = _databaseItems.FirstOrDefault(x => x.name.ToLower() == resourceFileName.ToLower()); var hashValue = string.Join("\r\n--GO\r\n", ReadSQLFileSectionsFromResource(resourceFileName, setup)).CalculateMD5Hash(); if (current != null) { //if (current.Hash != hashValue) { runScript = true; current.ModifiedDate = DateTime.Now; current.Hash = hashValue; current.Status = "applied"; } } else { runScript = true; current = new nHydrateDbObject() { name = resourceFileName, Hash = hashValue, ModelKey = new Guid(UpgradeInstaller.MODELKEY), type = "FILE", Status = "applied", Changed = true, }; _databaseItems.Add(current); } #endregion if (runScript && !setup.CheckOnly) { foreach (var sql in scripts) { ExecuteSQL(connection, transaction, sql, setup, failedScripts, successOrderScripts); } } timer.Start(); Log.Verbose(TheDate + " End File=" + Extensions.StripResourceAssem(resourceFileName) + ", Elapsed=" + timer.FormattedTime()); }
public static nHydrateDbObjectList Load(string connectionString, string modelKey, NpgsqlTransaction transaction) { var retval = new nHydrateDbObjectList(); NpgsqlConnection conn = null; if (transaction == null) { conn = new NpgsqlConnection(connectionString); conn.Open(); } else { conn = transaction.Connection; } try { using (var command2 = new NpgsqlCommand("select 1 from pg_tables where tablename = '__nhydrateobjects'", conn)) { command2.Transaction = transaction; var da = new NpgsqlDataAdapter(command2); var ds = new DataSet(); da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { using (var command = new NpgsqlCommand($"SELECT * FROM \"__nhydrateobjects\" where \"ModelKey\" = '{modelKey}'", conn)) { command.Transaction = transaction; da = new NpgsqlDataAdapter(command); ds = new DataSet(); da.Fill(ds); var t = ds.Tables[0]; foreach (DataRow row in t.Rows) { var newItem = new nHydrateDbObject(); newItem.rowid = (long)row["rowid"]; if (row["id"] != System.DBNull.Value) { newItem.id = (Guid)row["id"]; } newItem.name = (string)row["name"]; newItem.ModelKey = (Guid)row["ModelKey"]; newItem.type = (string)row["type"]; if (row["schema"] != System.DBNull.Value) { newItem.schema = (string)row["schema"]; } newItem.CreatedDate = (DateTime)row["CreatedDate"]; newItem.ModifiedDate = (DateTime)row["ModifiedDate"]; if (row["Hash"] != System.DBNull.Value) { newItem.Hash = (string)row["Hash"]; } if (t.Columns.Contains("status") && row["status"] != System.DBNull.Value) { newItem.Status = (string)row["status"]; } newItem.Changed = false; retval.Add(newItem); } } } } } catch (Exception ex) { throw; } finally { if (transaction == null && conn != null) { conn.Close(); conn.Dispose(); } } return(retval); }