Click here to Skip to main content
15,892,537 members
Articles / Programming Languages / XML

Learn How to Build a Provider Framework - With an Easy to Understand Example Towards Applying the Provider Pattern

Rate me:
Please Sign up or sign in to vote.
4.52/5 (43 votes)
20 Jul 2007CPOL14 min read 110.6K   590   154  
After reading this article, you'll be able to: (1) Change your mindset a little bit, and start thinking about 'frameworks' instead of just 'code' (2) Understand a lot about practically applying the Provider pattern in your projects (3) Gain much knowledge regarding XML config files and providers.
using System;


namespace Sumeru.Publisher.FTPPublisher
{
	/// <summary>
	/// A Simple Plugin Class
	/// </summary>
	public class FTPPublisherPlugin : Sumeru.Publisher.Framework.IPublisher 
	{
		
		private System.Collections.Hashtable ht=new System.Collections.Hashtable();
		
		/// <summary>
		/// To publish data
		/// </summary>
		public void Put() 
		{
			//Put your data
			//Note: Implement proper error handling for invalid parameters

			string host=(string)ht["Host"];
			string port=(string)ht["Port"];
			System.Windows.Forms.MessageBox.Show("Putting File To " + host + "," + port);  

			//Write Your own ftp code to put file

		}
		/// <summary>
		/// To retreive data
		/// </summary>
		public void Get() 
		{
			//Get your data
			//Note: Implement proper error handling for invalid parameters
			string host=(string)ht["Host"];
			string port=(string)ht["Port"];
			System.Windows.Forms.MessageBox.Show("Getting File from " + host + "," + port);  
			
			//Write Your own ftp code to get file


		}
       

		/// <summary>
		/// Function called by publisher factory to pass the settings
		/// </summary>
		/// <param name="settings">
		/// </param>
		public void Init(Sumeru.Publisher.Framework.Data.SettingCollection settings)
		{
			//Keep our settings locally in a hash table
			//Implement proper error handling for duplicate keys
			foreach(Framework.Data.Setting s in settings) 
			{
				ht.Add(s.Key,s.Value);
			}
			
		}
		
	}
}

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
Architect
India India
Architect, Developer, Speaker | Wannabe GUT inventor & Data Scientist | Microsoft MVP in C#

Comments and Discussions