Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Create Custom Application Block Using .NET Enterprise Library

, 21 Oct 2009 CPOL
This white paper is written in a view to help developer to create custom application block using .NET Enterprise Library.
CustomAppBlock.zip
CustomAppBlock
SampleCustomBlock
SampleCustomBlock
bin
Debug
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.ObjectBuilder.dll
Project.Practice.DB.dll
Configuration
Project.Practice.DB.csproj.user
Properties
sn.snk
SampleCustomBlock.suo
WebSite2
App_Data
Bin
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.ObjectBuilder.dll
Project.Practice.DB.dll
WebSite2 (2).suo
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;

using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Project.Practice.DB.Configuration;
namespace Project.Practice.DB
{
    [ConfigurationElementType(typeof(DBData))]
    public class DBProvider : IDBProvider
    {
        protected string m_UserId = string.Empty;
        protected string m_Password = string.Empty;
        protected string m_Server = string.Empty;
        protected string m_DirectoryPath = string.Empty;

        private bool m_Disposed = false;

        public DBProvider() { }
        public DBProvider(string userId, string password, string server, string directoryPath)
        {
            m_UserId    = userId;
            m_Password  = password;
            m_Server    = server;
            m_DirectoryPath = directoryPath;
        }

        #region IFTPProvider Interface

        bool IDBProvider.UploadFile(string filePath)
        {
            //Using configurable parameter one can connect to military zone server and can upload file
            //credential to access Server to upload file
            //m_UserID,m_password,m_Server get this values from DBprovider 
            //which in turns set from web.config custom configuration section.
            return true;
        }

        #endregion

        #region IDisposable Interface

        /// <summary>
        /// Dispose method releases all resources for this instance.
        /// </summary>
        /// <remarks>Calling GC.SupressFinalize to
        /// take this object off the finalization queue 
        /// and prevent finalization code for this object
        /// from executing a second time
        /// </remarks>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// Private method used to actually dispose of resources.
        /// </summary>
        /// <param name="disposing">bool</param>
        /// <remarks> Dispose(bool disposing) executes in two distinct scenarios.
        /// If disposing equals true, the method has been called directly
        /// or indirectly by a user's code. Managed and unmanaged resources
        /// can be disposed.
        /// If disposing equals false, the method has been called by the 
        /// runtime from inside the finalizer and you should not reference 
        /// other objects. Only unmanaged resources can be disposed.
        ///</remarks>
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this.m_Disposed)
            {
                // If disposing equals true, dispose all managed resources.
                if (disposing)
                {
                    // Dispose managed resources.
                }

                //
                // Call the appropriate methods to clean up unmanaged resources here.
                // If disposed is false, only the following code is executed.
                //

                if (Environment.HasShutdownStarted == false)
                    Trace.WriteLine("FTPProvider finalizer called.");
            }
            m_Disposed = true;
        }

        /// <summary>
        /// Finalizer for <see cref="FTPProvider"/>
        /// </summary>
        /// <remarks>This destructor will run only if the Dispose method does not get called.</remarks>
        ~DBProvider()
        {
            Dispose(false);
        }
        #endregion
    }
}

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)

Share

About the Author

santosh poojari
Technical Lead
India India
Whatsup-->Exploring--> MVC/HTML5/Javascript & Virtualization.......!
www.santoshpoojari.blogspot.com

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150326.1 | Last Updated 21 Oct 2009
Article Copyright 2009 by santosh poojari
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid