/// <summary> /// Refreshes the <see cref="MetadataProviderBase.Metadata"/> from a REST web service. /// </summary> /// <exception cref="ArgumentNullException"><see cref="ServiceUri"/> is set to a null or empty string.</exception> protected override void RefreshMetadata() { if (string.IsNullOrEmpty(m_serviceUri)) throw new ArgumentNullException("ServiceUri"); // Update existing metadata with retrieved metadata. WebResponse response = null; Stream responseStream = null; try { response = WebRequest.Create(m_serviceUri).GetResponse(); responseStream = response.GetResponseStream(); MetadataUpdater metadataUpdater = new MetadataUpdater(Metadata); metadataUpdater.UpdateMetadata(responseStream, m_serviceDataFormat); } finally { if (response != null) response.Close(); if (responseStream != null) responseStream.Dispose(); } }
/// <summary> /// Refreshes the <see cref="MetadataProviderBase.Metadata"/> from an ADO.NET based data store. /// </summary> /// <exception cref="ArgumentNullException"><see cref="ConnectionString"/> or <see cref="SelectString"/> is set to a null or empty string.</exception> protected override void RefreshMetadata() { if (string.IsNullOrEmpty(m_connectionString)) throw new ArgumentNullException("ConnectionString"); if (string.IsNullOrEmpty(m_selectString)) throw new ArgumentNullException("SelectString"); // Attempt to load configuration from an ADO.NET database connection IDbConnection connection = null; Dictionary<string, string> settings; string assemblyName, connectionTypeName, adapterTypeName; Assembly assembly; Type connectionType, adapterType; try { settings = m_dataProviderString.ParseKeyValuePairs(); assemblyName = settings["AssemblyName"].ToNonNullString(); connectionTypeName = settings["ConnectionType"].ToNonNullString(); adapterTypeName = settings["AdapterType"].ToNonNullString(); if (string.IsNullOrEmpty(connectionTypeName)) throw new InvalidOperationException("Database connection type was not defined"); if (string.IsNullOrEmpty(adapterTypeName)) throw new InvalidOperationException("Database adapter type was not defined"); assembly = Assembly.Load(new AssemblyName(assemblyName)); connectionType = assembly.GetType(connectionTypeName); adapterType = assembly.GetType(adapterTypeName); // Open ADO.NET provider connection connection = (IDbConnection)Activator.CreateInstance(connectionType); connection.ConnectionString = m_connectionString; connection.Open(); // Update existing metadata MetadataUpdater metadataUpdater = new MetadataUpdater(Metadata); metadataUpdater.UpdateMetadata(connection.ExecuteReader(m_selectString)); } finally { if (connection != null) connection.Dispose(); } }
/// <summary> /// Refreshes the <see cref="MetadataProviderBase.Metadata"/> from an OLE DB data store. /// </summary> /// <exception cref="ArgumentNullException"><see cref="ConnectionString"/> or <see cref="SelectString"/> is set to a null or empty string.</exception> protected override void RefreshMetadata() { if (string.IsNullOrEmpty(m_connectionString)) throw new ArgumentNullException("ConnectionString"); if (string.IsNullOrEmpty(m_selectString)) throw new ArgumentNullException("SelectString"); OleDbConnection connection = new OleDbConnection(m_connectionString); try { // Open OleDb connection. connection.Open(); // Update existing metadata. MetadataUpdater metadataUpdater = new MetadataUpdater(Metadata); metadataUpdater.UpdateMetadata(connection.ExecuteReader(m_selectString)); } finally { if (connection != null) connection.Dispose(); } }
/// <summary> /// Refreshes the <see cref="MetadataProviderBase.Metadata"/> from an OLE DB data store. /// </summary> /// <exception cref="ArgumentNullException"><see cref="ConnectString"/> or <see cref="SelectString"/> is set to a null or empty string.</exception> protected override void RefreshMetadata() { if (string.IsNullOrEmpty(m_connectString)) throw new ArgumentNullException("ConnectString"); if (string.IsNullOrEmpty(m_selectString)) throw new ArgumentNullException("SelectString"); // Update existing metadata with retrieved metadata. OleDbDataReader reader = null; OleDbConnection connection = new OleDbConnection(m_connectString); OleDbCommand command = new OleDbCommand(m_selectString, connection); try { connection.Open(); reader = command.ExecuteReader(); MetadataUpdater metadataUpdater = new MetadataUpdater(Metadata); metadataUpdater.UpdateMetadata(reader); } finally { if (reader != null) reader.Dispose(); if (command != null) command.Dispose(); if (connection != null) connection.Dispose(); } }