Click here to Skip to main content
13,150,607 members (38,881 online)
Click here to Skip to main content

Stats

97.7K views
1.1K downloads
159 bookmarked
Posted 1 Dec 2005

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

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.
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 Shahed Khan. 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.Messaging;
using SmartJobManager;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

namespace ClientApplication
{
	class QueuedClient
	{
		static string QueuePath = @".\Private$\jobmanagerTest";		

		public string ErrorMessage = string.Empty;
		public bool IsErrorExists = false;
		public  void QueueSimpleJob()
		{			
			Job job = new Job(0,0,DateTime.Now,DateTime.Now,"SimpleJobManagerProvider");
			JobDetailCollection jobDetails = new JobDetailCollection();
			JobDetail jobDetail = new JobDetail(0,0,"Copyright","Use at your own risk.");						
			jobDetails.Add(jobDetail);
			jobDetail = new JobDetail(0,0,"PersonName","Shahed Khan");						
			jobDetails.Add(jobDetail);
			jobDetail = new JobDetail(1,0,"Email","shahed.khan@gmail.com");
			jobDetails.Add(jobDetail);

			job.JobDetailCollection = jobDetails;
			QueueJob(job, QueuePath);
		}

		public  void QueueScreenCaptureImageJob()
		{			
			Job job = new Job(0,0,DateTime.Now,DateTime.Now,"ScreencaptureJobManagerProvider");
			JobDetailCollection jobDetails = new JobDetailCollection();
			 
			JobDetail jobDetail = new JobDetail(1,0,"CaptureImage",PerformCapture());
			jobDetails.Add(jobDetail);
			job.JobDetailCollection = jobDetails;
			QueueJob(job, QueuePath);
		}

		public  void QueueTextToFileJob(string text)
		{			
			if (text.Length < 1)
				text = "No Text Entered";
			Job job = new Job(0,0,DateTime.Now,DateTime.Now,"TextToFileJobManagerProvider");
			JobDetailCollection jobDetails = new JobDetailCollection();
			JobDetail jobDetail = new JobDetail(0,0,"TextToWrite",text);						
			jobDetails.Add(jobDetail);
			
			job.JobDetailCollection = jobDetails;
			QueueJob(job, QueuePath);
		}

		public  void QueueTextToImageJob(string text)
		{	
			if (text.Length < 1)
				text = "No Text Entered";
			Job job = new Job(0,0,DateTime.Now,DateTime.Now,"TextToImageJobManagerProvider");
			JobDetailCollection jobDetails = new JobDetailCollection();
			JobDetail jobDetail = new JobDetail(0,0,"TextToWrite",text);						
			jobDetails.Add(jobDetail);
			
			job.JobDetailCollection = jobDetails;
			QueueJob(job, QueuePath);
		}

		
		private  void QueueJob(Job job, string destinationQueue)
		{
			try
			{
				// open the queue
				MessageQueue mq = new MessageQueue(destinationQueue);
				// set the message to durable.
				mq.DefaultPropertiesToSend.Recoverable = true;
				// set the formatter to Binary, default is XML
				//mq.Formatter = new BinaryMessageFormatter();
				// send the job object
				mq.Send(job, "Job Message Test");
				mq.Close();
			}
			catch (Exception e)
			{
				//Console.WriteLine(e.ToString());
				this.ErrorMessage = e.ToString();
				this.IsErrorExists = true;
			}
			
		}

		#region Perform ScreenCapture

		//Originally written by Michael Gold 04/15/2002 
		//http://www.c-sharpcorner.com//Code/2002/April/ScreenCaptureUtility.asp
		//I modified a bit to meet my needs

		[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
		private static extern IntPtr  CreateDC(
			string lpszDriver,        // driver name
			string lpszDevice,        // device name
			string lpszOutput,        // not used; should be NULL
			IntPtr lpInitData	// optional printer data
			);
		[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
		private static extern bool BitBlt(
			IntPtr hdcDest, // handle to destination DC
			int nXDest,  // x-coord of destination upper-left corner
			int nYDest,  // y-coord of destination upper-left corner
			int nWidth,  // width of destination rectangle
			int nHeight, // height of destination rectangle
			IntPtr hdcSrc,  // handle to source DC
			int nXSrc,   // x-coordinate of source upper-left corner
			int nYSrc,   // y-coordinate of source upper-left corner
			System.Int32 dwRop  // raster operation code
			);

		private   byte[] PerformCapture()
		{ 						

			//use the GDI call and create a DC to the whole display

			IntPtr dc1 = CreateDC("DISPLAY", null, null, (IntPtr)null);

			//create a Graphics object for the screen dc

			Graphics g1 = Graphics.FromHdc(dc1);

			//  create a compatible bitmap the size of the entire screen

			//MyImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, g1);
			Bitmap image = new Bitmap(300,300,g1);
			//  use the bitmap to create another Graphics surface  so we can  BitBlast into the bitmap

			Graphics g2 = Graphics.FromImage(image);

			//  Now go retrace our steps and get the device contexts for both the bitmap and the screen
			// Note:  Apparently you have to do this, and can't go directly from the aquired dc or exceptions are thrown
			//            When you try to release the dcs

			dc1 = g1.GetHdc();

			IntPtr dc2 = g2.GetHdc();

			//  Bit Blast  the screen into the Bitmap

			BitBlt(dc2, 0, 0, 300, 300, dc1, 0, 0, 13369376);

			//   Remember to release the dc's, otherwise problems down the road

			g1.ReleaseHdc(dc1);

			g2.ReleaseHdc(dc2);
			
			//Converting to byte[]
			MemoryStream memStream = new MemoryStream();
			image.Save(memStream, System.Drawing.Imaging.ImageFormat.Jpeg);
			int ImageSize = Convert.ToInt32(memStream.Length);
			byte[] ImageBytes = new byte[ImageSize];
			memStream.Position=0;
			memStream.Read(ImageBytes, 0, ImageSize);
			memStream.Close();
			return ImageBytes;
		}

		#endregion Perform ScreenCapture


	}
}

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

You may also be interested in...

Pro
Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170924.2 | Last Updated 1 Dec 2005
Article Copyright 2005 by Shahed.Khan, David.Grinberg
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid