Exemple #1
0
        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());
        }
Exemple #2
0
        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);
        }
Exemple #3
0
		public static void RunEmbeddedFile(SqlConnection connection, SqlTransaction transaction, string resourceFileName, List<KeyValuePair<Guid, string>> failedScripts, List<Guid> successOrderScripts, List<nHydrateDbObject> _databaseItems, InstallSetup setup)
		{
			var tempFolder = string.Empty;
			var scripts = ReadSQLFileSectionsFromResource(resourceFileName, setup);
			System.Diagnostics.Debug.WriteLine(System.DateTime.Now.ToString("HH:mm:ss.ff") + " - Run embedded file: " + resourceFileName);

			#region Load script hashes
			var runScript = !setup.UseHash;
			var current = _databaseItems.FirstOrDefault(x => x.name.ToLower() == resourceFileName.ToLower());
			var hashValue = string.Join("\r\nGO\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);
				}
			}
		}
Exemple #4
0
		public static List<nHydrateDbObject> Load(string connectionString, string modelKey, System.Data.SqlClient.SqlTransaction transaction)
		{
			var retval = new List<nHydrateDbObject>();
			System.Data.SqlClient.SqlConnection conn = null;
			if (transaction == null)
			{
				conn = new System.Data.SqlClient.SqlConnection(connectionString);
				conn.Open();
			}
			else
			{
				conn = transaction.Connection;
			}

			try
			{
				var command2 = new SqlCommand("select * from sys.tables where name = '__nhydrateobjects'", conn);
				command2.Transaction = transaction;
				var da = new SqlDataAdapter(command2);
				var ds = new DataSet();
				da.Fill(ds);
				if (ds.Tables[0].Rows.Count > 0)
				{
					var command = new SqlCommand("SELECT * FROM __nhydrateobjects where [ModelKey] = '" + modelKey + "'", conn);
					command.Transaction = transaction;
					da = new SqlDataAdapter(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();
			}
			return retval;
		}