Acme.Northwind.Install.nHydrateSetting.Load C# (CSharp) Méthode

Load() public méthode

public Load ( string connectionString ) : void
connectionString string
Résultat void
		public void Load(string connectionString)
		{
			System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
			try
			{
				conn.ConnectionString = connectionString;
				conn.Open();

				var da = new SqlDataAdapter("select * from sys.tables where name = '__nhydrateschema'", conn);
				var ds = new DataSet();
				da.Fill(ds);
				if (ds.Tables[0].Rows.Count > 0)
				{
					da = new SqlDataAdapter("SELECT * FROM __nhydrateschema where [ModelKey] = '" + UpgradeInstaller.MODELKEY + "'", conn);
					ds = new DataSet();
					da.Fill(ds);
					var t = ds.Tables[0];
					if (t.Rows.Count > 0)
					{
						this.dbVersion = (string)t.Rows[0]["dbVersion"];
						this.LastUpdate = (DateTime)t.Rows[0]["LastUpdate"];
						this.ModelKey = (Guid)t.Rows[0]["ModelKey"];
						this.LoadHistory((string)t.Rows[0]["History"]);
						this.IsLoaded = true;
					}

					//There is an nHydrate table so empty or not we are finished
					return;
				}

				this.dbVersion = SqlServers.SelectExtendedProperty(connectionString, "dbVersion", string.Empty, string.Empty, string.Empty);
				try
				{
					this.LastUpdate = DateTime.ParseExact(SqlServers.SelectExtendedProperty(connectionString, "LastUpdate", string.Empty, string.Empty, string.Empty), "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
				}
				catch { }

				try
				{
					this.ModelKey = new Guid(SqlServers.SelectExtendedProperty(connectionString, "ModelKey", string.Empty, string.Empty, string.Empty));
				}
				catch { }

				this.LoadHistory(SqlServers.SelectExtendedProperty(connectionString, "History", string.Empty, string.Empty, string.Empty));

			}
			catch (Exception ex)
			{
				throw;
			}
			finally
			{
				if (conn != null)
					conn.Close();
			}
		}

Usage Example

Exemple #1
0
		internal static void UpdateDatabaseMetaProperty(string connectionString, string propertyName, string propertyValue)
		{
			System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
			try
			{
				var settings = new nHydrateSetting();
				settings.Load(connectionString);
				switch (propertyName)
				{
					case "dbVersion":
						settings.dbVersion = propertyValue;
						break;
					case "LastUpdate":
						settings.LastUpdate = DateTime.Parse(propertyValue);
						break;
					case "ModelKey":
						settings.ModelKey = new Guid(propertyValue);
						break;
					case "History":
						settings.LoadHistory(propertyValue);
						break;
					default:
						throw new Exception("No property found!");
				}
				settings.Save(connectionString);
			}
			catch (Exception ex)
			{
				throw;
			}
			finally
			{
				if (conn != null)
					conn.Close();
			}

			//We no longer use extended properties
			if (CanUseExtendedProperty(connectionString))
			{
				if (ExtendedPropertyExists(connectionString, propertyName, string.Empty, string.Empty, string.Empty))
				{
					//UpdateExtendedProperty(connectionString, propertyName, propertyValue, string.Empty, string.Empty, string.Empty);
					DeleteExtendedProperty(connectionString, propertyName);
				}
				else
				{
					//InsertExtendedPropery(connectionString, propertyName, propertyValue, string.Empty, string.Empty, string.Empty);
				}
			}

		}
All Usage Examples Of Acme.Northwind.Install.nHydrateSetting::Load