示例#1
0
		public static void RunEmbeddedFile(SqlConnection connection, SqlTransaction transaction, string resourceFileName, List<KeyValuePair<Guid, string>> failedScripts, List<Guid> successOrderScripts, IEnumerable<string> skipSections, List<nHydrateDbObject> _databaseItems, List<nHydrateDbObject> _currentItems)
		{
			var tempFolder = string.Empty;
			var scripts = ReadSQLFileSectionsFromResource(resourceFileName, skipSections);
			System.Diagnostics.Debug.WriteLine(System.DateTime.Now.ToString("HH:mm:ss.ff") + " - Run embedded file: " + resourceFileName);

			#region Load script hashes
			//var runScript = false;
			var current = _databaseItems.FirstOrDefault(x => x.name.ToLower() == resourceFileName.ToLower());
			var hashValue = string.Join("|", scripts).CalculateMD5Hash();

			if (current != null)
			{
				if (current.Hash != hashValue)
				{
					//runScript = true;
					current.ModifiedDate = DateTime.Now;
					_currentItems.RemoveAll(x => x.name.ToLower() == current.name.ToLower());
					_currentItems.Add(current);
					current.Hash = hashValue;
				}
			}
			else
			{
				//runScript = true;
				current = new nHydrateDbObject()
				{
					name = resourceFileName,
					Hash = hashValue,
					ModelKey = new Guid(UpgradeInstaller.MODELKEY),
					type = "FILE",
				};
				_currentItems.Add(current);
			}
			#endregion

			//if (runScript)
			{
				foreach (var sql in scripts)
				{
					ExecuteSQL(connection, transaction, sql, failedScripts, successOrderScripts);
				}
			}
		}
示例#2
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"];
						retval.Add(newItem);
					}
				}
			}
			catch (Exception ex)
			{
				throw;
			}
			finally
			{
				if (transaction == null && conn != null)
					conn.Close();
			}
			return retval;
		}