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

Flexible and Plug-in-based .NET Application using Provider Pattern

, , 1 Dec 2005
This paper demonstrates creating a flexible, extensible, plug-in-based .NET application (JOM - Smart Job Manager). JOM is an asynchronous job processing engine built using the MS Provider design pattern and the .NET technology available today.
smartjobmanager.zip
Code
Bin
ClientApplication.exe
EntLibHelper.dll
log
exceptions
SmartJobManager.log
Microsoft.Practices.EnterpriseLibrary.Caching.dll
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Configuration.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Security.ActiveDirectory.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cache.CachingStore.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
Microsoft.Practices.EnterpriseLibrary.Security.Database.Authentication.dll
Microsoft.Practices.EnterpriseLibrary.Security.Database.dll
Microsoft.Practices.EnterpriseLibrary.Security.dll
Providers.dll
SampleProviders.dll
ScreencaptureJobManagerProvider.dll
SimpleJobManagerProvider.dll
SmartJobManager.BusinessLogicLayer.dll
SmartJobManagerService.exe
ClientApplication
App.ico
bin
ClientApplication.csproj.user
EntLibHelper
bin
EntLibHelper.csproj.user
Library
Microsoft.Practices.EnterpriseLibrary.Caching.dll
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Configuration.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Security.ActiveDirectory.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cache.CachingStore.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
Microsoft.Practices.EnterpriseLibrary.Security.Database.Authentication.dll
Microsoft.Practices.EnterpriseLibrary.Security.Database.dll
Microsoft.Practices.EnterpriseLibrary.Security.dll
Objects
bin
Release
SmartJobManager.BusinessLogicLayer.dll
SmartJobManager.csproj.user
Providers
bin
Configuration
Providers.csproj.user
System
Configuration
Providers
Providers
SampleProviders
bin
SampleProviders.csproj.user
ScreencaptureJobManagerProvider
bin
ScreencaptureJobManagerProvider.csproj.user
SimpleJobManagerProvider
bin
SimpleJobManagerProvider.csproj.user
SmartJobManagerService
bin
SmartJobManagerService.csproj.user
// =====================================================================================
// Copyright � 2005 by . All rights are reserved.
// 
// If you like this code then feel free to go ahead and use it.
// The only thing I ask is that you don't remove or alter my copyright notice.
//
// Your use of this software is entirely at your own risk. I make no claims or
// warrantees about the reliability or fitness of this code for any particular purpose.
// If you make changes or additions to this code please mark your code as being yours.
// 
// website , email shahed.khan@gmail.com
// =====================================================================================


using System;
using System.Collections.Specialized;
using System.Data.SqlClient;
using SmartJobManager.Providers;
using SmartJobManager;
using System.IO;
using System.Drawing;
using System.Drawing.Text;


namespace SmartJobManager {

	public class TextToImageJobManagerProvider : JobManagerProvider {

		public TextToImageJobManagerProvider  () 
		{
		}

		#region JobManager specific behaviors
		string OutputFilePath = @"c:\tmp\";
		public override bool DoJob(Job job) 
		{
			//DoJob			
			//Write  to file
			try
			{			
				foreach(JobDetail jobDetail in job.JobDetailCollection)
				{
					if (jobDetail.ElementDesc == "TextToWrite")
					GenerateImage(jobDetail.ElementData.ToString());				
				}
				
				return true;
			}
			catch{}
			return false;
		}

		
		#endregion

		#region Provider specific behaviors
		public override void Initialize(string name, NameValueCollection configValue) {

		}

		public override string Name {
			get {
				return null;
			}
		}
		#endregion

		#region Image Generation from Text
		//Code originally written by http://www.thecodebehind.com/code/dotnet/aspnet/creating-an-image-from-text-with-c-and.aspx
		//I modified it to fit my purpose
		protected void GenerateImage(string imageText)
		{
			// we initialise these here because it's needed to calculate the width
			// and height of the provided text.  the 1,1 is only a temporary 
			// measurement
			Bitmap bmp = new Bitmap(1, 1);
			Graphics graphic = System.Drawing.Graphics.FromImage(bmp);

			// our font for the writing
			Font font = new Font("Arial", 14, FontStyle.Bold);

			// measure the text
			StringFormat stringformat = new StringFormat(StringFormat.GenericTypographic);
			int height = Convert.ToInt32(graphic.MeasureString(imageText, font, new PointF(0,0), stringformat).Height) + 6;
			int width = Convert.ToInt32(graphic.MeasureString(imageText, font, new PointF(0,0), stringformat).Width);

			// add some padding for the width - i think the kerning is throwing
			// it off by a little.  5% seems to work well, and the +10 is necessary
			// if the string is only a few letters
			width += Convert.ToInt32(0.05 * width) + 10;

			// recreate our bmp and graphic objects with the new measurements
			bmp = new Bitmap(width, height);

			graphic = System.Drawing.Graphics.FromImage(bmp);

			// our background colour
			graphic.Clear(Color.FromArgb(153, 204, 229));

			// aliasing mode
			graphic.TextRenderingHint = TextRenderingHint.SystemDefault;

			/* 
			the different aliasing modes:
			---------------------------------------------------------------------------------
			graphic.TextRenderingHint = TextRenderingHint.SystemDefault;
			- each character is drawn using its glyph bitmap, with the system default rendering hint

			graphic.TextRenderingHint = TextRenderingHint.AntiAlias;
			- each character is drawn using its antialiased glyph bitmap without hinting

			graphic.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
			- each character is drawn using its antialiased glyph bitmap with hinting

			graphic.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
			- each character is drawn using its glyph CT bitmap with hinting

			graphic.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
			- each character is drawn using its glyph bitmap

			graphic.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;
			- each character is drawn using its glyph bitmap
			*/

			// our brush which is the writing colour
			SolidBrush brush = new SolidBrush(Color.White);

			/*
			alternate brushes
			-------------------------------------------------------------------------------
			System.Drawing.Drawing2D.HatchBrush
			System.Drawing.Drawing2D.LinearGradientBrush
			System.Drawing.Drawing2D.PathGradientBrush
			System.Drawing.SolidBrush
			System.Drawing.TextureBrush
			*/

			// create our graphic
			graphic.DrawString(imageText, font, brush, new Rectangle(0, 0, width, height));

			// Set the content type and return the image
			
			bmp.Save(string.Format("{0}{1}{2}{3}", OutputFilePath, "TransferImageJob",DateTime.Now.Ticks.ToString(), ".jpg"),System.Drawing.Imaging.ImageFormat.Jpeg);

			// dispose of our objects
			font.Dispose();
			stringformat.Dispose();
			graphic.Dispose();
			bmp.Dispose();

		}
		#endregion Image Generation from Text

	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Authors

Shahed.Khan
Web Developer
Australia Australia
I have been awarded MVP (Visual C#) for year 2007, 2008, 2009. I am a Microsoft Certified Application Developer (C# .Net). I currently live in Melbourne, Australia. I am a co-founder and core developer of Pageflakes www.pageflakes.com and Founder of Simplexhub, a highly experienced software development company based in Melbourne Australia and Dhaka, Bangladesh. Simplexhub.
My BLOG http://www.geekswithblogs.net/shahed
http://msmvps.com/blogs/shahed/Default.aspx.

David.Grinberg

Australia Australia
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.141022.2 | Last Updated 1 Dec 2005
Article Copyright 2005 by Shahed.Khan, David.Grinberg
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid