- smartjobmanager.zip
- Code
- Bin
- App.config
- cachingconfiguration.config
- ClientApplication.exe
- EntLibHelper.dll
- exceptionhandlingconfiguration.config
- install.bat
- InvokerSample.exe.config
- log
- exceptions
- SmartJobManager.log
- loggingconfiguration.config
- loggingdistributorconfiguration.config
- 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
- SmartJobManagerService.exe.config
- uninstall.bat
- ClientApplication
- EntLibHelper
- 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
- Providers
- bin
- Configuration
- Providers.csproj
- Providers.csproj.user
- System
- Configuration
- Providers
- Providers
- Readme.txt
- SampleProviders
- ScreencaptureJobManagerProvider
- SimpleJobManagerProvider
- SmartJobManager.sln
- SmartJobManagerService
|
// =====================================================================================
// 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.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using SmartJobManager.Providers;
using SmartJobManager;
using System.Messaging;
using System.Configuration.Install;
namespace SmartJobManagerService
{
public class SmartJobManagerWindowsService : System.ServiceProcess.ServiceBase
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
string QueuePath = System.Configuration.ConfigurationSettings.AppSettings["QueuePath"].ToString();
MessageQueue mqReceive=null;
public SmartJobManagerWindowsService()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();
// TODO: Add any initialization after the InitComponent call
}
/// <summary>
/// Runs the service.
/// </summary>
private static void Run()
{
// instantiate and run service
ServiceBase.Run(
new ServiceBase[] { new SmartJobManagerWindowsService() });
}
// The main entry point for the process
static void Main(string[] args)
{
string opt = null;
// check for arguments
if (args.Length > 0)
{
opt = args[0];
if(opt!=null && opt.ToLower()=="/install")
{
TransactedInstaller ti= new TransactedInstaller();
ProjectInstaller pi = new ProjectInstaller();
ti.Installers.Add(pi);
String path=String.Format("/assemblypath={0}",
System.Reflection.Assembly.GetExecutingAssembly().Location);
String[] cmdline={path};
InstallContext ctx = new InstallContext("",cmdline);
ti.Context =ctx;
ti.Install(new Hashtable());
}
else if (opt !=null && opt.ToLower()=="/uninstall")
{
TransactedInstaller ti=new TransactedInstaller();
ProjectInstaller mi=new ProjectInstaller();
ti.Installers.Add(mi);
String path = String.Format("/assemblypath={0}",
System.Reflection.Assembly.GetExecutingAssembly().Location);
String[] cmdline={path};
InstallContext ctx = new InstallContext("",cmdline);
ti.Context=ctx;
ti.Uninstall(null);
}
if(opt==null) // e.g. ,nothing on the command line
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new SmartJobManagerWindowsService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
}
else // no arguments, just run
Run();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.ServiceName = "SmartJobManagerWindowsService";
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <summary>
/// Set things in motion so your service can do its work.
/// </summary>
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
OnStartService();
}
/// <summary>
/// Stop this service.
/// </summary>
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
OnStopService();
}
void OnStartService()
{
// create queue, if it doesn't exist
if (!MessageQueue.Exists(QueuePath))
MessageQueue.Create(QueuePath);
// open the queue
mqReceive = new MessageQueue(QueuePath);
MessageQueue.EnableConnectionCache = false;
// Control Queue permissions here:
mqReceive.SetPermissions("Everyone",
MessageQueueAccessRights.FullControl, AccessControlEntryType.Allow);
Type[] paramTypes = new Type[1];
paramTypes[0] = typeof(SmartJobManager.Job);
mqReceive.Formatter = new XmlMessageFormatter(paramTypes);
//mqReceive.Formatter = new BinaryMessageFormatter();
try
{
IAsyncResult ar = mqReceive.BeginReceive(TimeSpan.FromSeconds(5),
mqReceive,new AsyncCallback(OnMessageArrival));
}
catch (MessageQueueException e)
{
if (e.MessageQueueErrorCode != MessageQueueErrorCode.IOTimeout)
{
EntLibHelper.Exception("OnStartService",e);
}
}
catch (Exception e)
{
EntLibHelper.Exception("OnStartService",e);
}
}
private void OnMessageArrival(IAsyncResult ar)
{
MessageQueue mq = (MessageQueue)ar.AsyncState;
Job job = new Job();
try
{
Message msg=mq.EndReceive(ar);
job = (Job) msg.Body;
if (job != null)
{
//Log Recieve of a Job
EntLibHelper.JobInfo("Recieved New Job",job);
if (!JobManager.DoJob(job))
{
//Log Error
EntLibHelper.JobError("JobError Occured",job);
}
}
}
catch(MessageQueueException e)
{
if (e.MessageQueueErrorCode != MessageQueueErrorCode.IOTimeout)
{
//Log Error
EntLibHelper.Exception("OnMessageArrival",e);
}
}
catch(Exception e)
{
EntLibHelper.JobException("OnMessageArrival",job,e);
}
finally
{
mq.BeginReceive(TimeSpan.FromSeconds(5),mq,new AsyncCallback(OnMessageArrival));
}
}
private void OnStopService()
{
try
{
mqReceive.Close();
}
catch(Exception e)
{
EntLibHelper.Exception("OnStopService",e);
}
}
}
}
|
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.
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
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.