Click here to Skip to main content
15,881,882 members
Articles / Web Development / ASP.NET

Provider Pattern

Rate me:
Please Sign up or sign in to vote.
3.84/5 (14 votes)
31 Mar 2007CPOL3 min read 107.2K   1.2K   67  
Create your own custom providers
using System;
using System.Configuration;
using System.Configuration.Provider;

namespace Cli.Lsp.Provider.CurrencyProvider {
    public class WSCurrencyConversion : CurrencyProviderBase {
        private String url;

        public String URL {
            get { return url; }
            set { url = value; }
            }


        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config) {
            #region Attributes check
            if ((config == null) || (config.Count == 0))
                throw new ArgumentNullException("You must supply a valid configuration parameters.");
            this._name = name;
            #endregion

            #region Description
            if (string.IsNullOrEmpty(config["description"])) {
                throw new ProviderException("You must specify a description attribute.");
                }
            this._description = config["description"];
            config.Remove("description");
            #endregion

            #region URL
            if (String.IsNullOrEmpty(config["url"]))
                throw new ProviderException("The url is invalid.");
            this.url = config["url"];
            config.Remove("url");
            #endregion

            #region Extra Attributes validations
            if (config.Count > 0) {
                string extraAttribute = config.GetKey(0);
                if (!String.IsNullOrEmpty(extraAttribute))
                    throw new ProviderException("The following unrecognized attribute was found in " + Name + "'s configuration: '" +
                                                extraAttribute + "'");
                else
                    throw new ProviderException("An unrecognized attribute was found in the provider's configuration.");
                }
            #endregion
            }

        public override decimal Convert(Currency cur, decimal value) {
            Console.WriteLine("---- Convert method was Invoked SQL Currency conversion ----");
            Console.WriteLine("Provider Description ={0}", this.Description);
            Console.WriteLine("URL ={0}", this.URL);
            Console.WriteLine("Convert({0},{1}) ", Enum.GetName(typeof(Currency), cur), value);
            Console.ReadLine();
            return 3.4m;
            }

        public override void Add(Currency cur, DateTime date, decimal factor) {
            Console.WriteLine("---- Add method was Invoked SQL Currency conversion ----");
            Console.WriteLine("Provider Description ={0}", this.Description);
            Console.WriteLine("URL ={0}", this.URL);            
            Console.WriteLine("Add({0},{1},{2}) ", Enum.GetName(typeof(Currency), cur), date, factor);
            Console.ReadLine();
            }

        public override void Remove(Currency cur, DateTime date) {
            Console.WriteLine("---- Remove method was Invoked SQL Currency conversion ----");
            Console.WriteLine("Provider Description ={0}", this.Description);
            Console.WriteLine("URL ={0}", this.URL);            
            Console.WriteLine("Remove({0},{1}) ", Enum.GetName(typeof(Currency), cur), date);
            Console.ReadLine();
            }


        public override CurrencyConversionItem[] List(Currency cur, DateTime startDate, DateTime endDate) {
            Console.WriteLine("---- List method was Invoked SQL Currency conversion ----");
            Console.WriteLine("Provider Description ={0}", this.Description);
            Console.WriteLine("URL ={0}", this.URL);            
            Console.WriteLine("List({0},{1},{2}) ", Enum.GetName(typeof(Currency), cur), startDate, endDate);
            Console.ReadLine();
            return new CurrencyConversionItem[0];
            }
        }
    }

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
Software Developer (Senior) NSW Curriculum & Learning Innovation Centre
Australia Australia
I am a senior developer self taught,
the main study is electronics and communication engineering

I am working as senior programmer in center for learning and innovation
www.cli.nsw.edu.au

I develop Software since 1995 using Delphi with Microsoft SQL Server

before 2000, I didn’t like Microsoft tools and did many projects using all database tools and other programming tools specially Borland C++ Builder, Delphi, Power Builder
And I loved Oracle database for its stability until I was certified as Master in Database Administration from Oracle University.

I tried to work in web programming but I felt that Java is hard and slow in programming, specially I love productivity.

I began worked with .Net since 2001 , and at the same time Microsoft SQL Server 7 was very stable so I switched all my way to Microsoft Tech.
I really respect .Net Platform especially in web applications

I love database Applications too much
And built library with PowerBuilder it was very useful for me and other developers

I have a wide experience due to my work in different companies
But the best experience I like in wireless applications, and web applications.
The best Application I did in my life is Novartis Marketing System 1999 it takes 8 months developing with PowerBuilder and Borland C++, SQL Server
Performance was the key challenge in this Application.
The other 2 applications that I loved Multilingual Project in Scada company in Italy 2000 and SDP Mobile media content platform server for ChinaUnicom 2004
I hope that you enjoy any Article I post.
God bless you.

Comments and Discussions