Click here to Skip to main content
15,885,633 members
Articles / Programming Languages / C#

Microsoft Enterprise Library Data Access Block [DAAB] on Oracle Provider [ODP.NET]

Rate me:
Please Sign up or sign in to vote.
4.88/5 (32 votes)
4 Feb 2010CPOL11 min read 360.8K   4.3K   106  
Microsoft Enterprise Library Data Access Block [DAAB] on Oracle Provider [ODP.NET]
//===============================================================================
// Microsoft patterns & practices Enterprise Library
// Data Access Application Block
//===============================================================================
// Copyright � Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================

using System;
using System.Configuration;
using System.Windows.Forms;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.Data.Configuration.Design.Properties;
using System.Diagnostics;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data.Oracle.Configuration;
using System.Runtime.InteropServices;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

namespace Microsoft.Practices.EnterpriseLibrary.Data.Configuration.Design
{
	/// <summary>
	/// Represents the design manager for the oracle connection configuration section.
	/// </summary>    
    public sealed class OracleConnectionConfigurationDesignManager : ConfigurationDesignManager
    {
        /// <summary>
        /// Initialize a new instance of the <see cref="OracleConnectionConfigurationDesignManager"/> class.
        /// </summary>
		public OracleConnectionConfigurationDesignManager()
        {
        }

		/// <summary>
		/// Register the commands and node maps needed for the design manager into the design time.
		/// </summary>
		/// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
        public override void Register(IServiceProvider serviceProvider)
        {
			OracleConnectionCommandRegistrar registrar = new OracleConnectionCommandRegistrar(serviceProvider);
			registrar.Register();
        }

		/// <summary>
		/// Opens the oracle connection configuration section, builds the design time nodes and adds them to the application node.
		/// </summary>
		/// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
		/// <param name="rootNode">The root node of the application.</param>
		/// <param name="section">The <see cref="ConfigurationSection"/> that was opened from the <see cref="IConfigurationSource"/>.</param>
		protected override void OpenCore(IServiceProvider serviceProvider, ConfigurationApplicationNode rootNode, ConfigurationSection section)
		{
			if (null != section)
			{
				OracleConnectionNodeBuilder builder = new OracleConnectionNodeBuilder(serviceProvider, (OracleConnectionSettings)section);
				builder.Build();
			}
		}

		/// <summary>
		/// Gets the a <see cref="ConfigurationSectionInfo"/> for the oracle connection configuration section.
		/// </summary>
		/// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
		/// <returns>A <see cref="ConfigurationSectionInfo"/> for the oracle connection configuration section.</returns>
		protected override ConfigurationSectionInfo GetConfigurationSectionInfo(IServiceProvider serviceProvider)
        {
            ConfigurationNode rootNode = ServiceHelper.GetCurrentRootNode(serviceProvider);
            DatabaseSectionNode databaseSectionNode = null;
            if (rootNode != null)
            {
                databaseSectionNode = rootNode.Hierarchy.FindNodeByType(rootNode, typeof(DatabaseSectionNode)) as DatabaseSectionNode;
            }
            OracleConnectionSettings oracleConnectionSection = null;
            IList<ConfigurationNode> connections = rootNode.Hierarchy.FindNodesByType(typeof(OracleConnectionElementNode));
            if (connections.Count == 0)
            {
                oracleConnectionSection = null;
            }
            else
            {
                OracleConnectionSettingsBuilder builder = new OracleConnectionSettingsBuilder(serviceProvider);
                oracleConnectionSection = builder.Build();
            }
            string protectionProviderName = GetProtectionProviderName(databaseSectionNode);

            return new ConfigurationSectionInfo(rootNode, oracleConnectionSection, OracleConnectionSettings.SectionName, protectionProviderName);
        }		
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United Kingdom United Kingdom
Software Developer

Comments and Discussions