Skip to content
Browse files

mergy merge merge

  • Loading branch information...
2 parents 10da91a + cc0b5a0 commit 62557d9b4452a7cc85e08da4f52c4c4dcaee4787 @averyj averyj committed
View
7 src/DaemonMaster.Tests/DaemonMaster.Tests.csproj
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -12,6 +12,10 @@
<AssemblyName>DaemonMaster.Tests</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <UpgradeBackupLocation />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -44,6 +48,7 @@
<HintPath>..\..\lib\Quartz.dll</HintPath>
</Reference>
<Reference Include="System" />
+ <Reference Include="System.configuration" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
View
4 src/DaemonMaster.Tests/TestJobs/LongRunningJobLoader.cs
@@ -5,9 +5,9 @@ namespace DaemonMaster.Tests.TestJobs
{
public class LongRunningJobLoader: ITypeLoader
{
- public IEnumerable<Type> LoadTypes()
+ public IEnumerable<FoundType> LoadTypes()
{
- yield return typeof(LongRunningJobIntervalDaemon);
+ yield return new FoundType(typeof(LongRunningJobIntervalDaemon), null);
}
}
}
View
4 src/DaemonMaster.Tests/TestJobs/MultipleInstanceJobLoader.cs
@@ -5,9 +5,9 @@ namespace DaemonMaster.Tests.TestJobs
{
public class MultipleInstanceJobLoader: ITypeLoader
{
- public IEnumerable<Type> LoadTypes()
+ public IEnumerable<FoundType> LoadTypes()
{
- yield return typeof(MultipleInstanceJobIntervalDaemon);
+ yield return new FoundType(typeof(MultipleInstanceJobIntervalDaemon), null);
}
}
}
View
10 src/DaemonMaster.sln
@@ -1,6 +1,6 @@

-Microsoft Visual Studio Solution File, Format Version 10.00
-# Visual Studio 2008
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DaemonMasterService", "DaemonMasterService\DaemonMasterService.csproj", "{050FBCE0-699C-4B07-8057-E320C617F954}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DaemonMaster", "DaemonMaster\DaemonMaster.csproj", "{EF438EE5-1D28-4005-95DD-70DEACE41A7B}"
@@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DaemonMaster.Tests", "Daemo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DaemonMasterConsole", "DaemonMasterConsole\DaemonMasterConsole.csproj", "{F8B80C80-D7D2-407C-84B0-090C7E97122D}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestDaemons", "TestDaemons\TestDaemons.csproj", "{D4D2D16B-6995-41CB-AD77-7FF89FCF63F8}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -31,6 +33,10 @@ Global
{F8B80C80-D7D2-407C-84B0-090C7E97122D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F8B80C80-D7D2-407C-84B0-090C7E97122D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F8B80C80-D7D2-407C-84B0-090C7E97122D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D4D2D16B-6995-41CB-AD77-7FF89FCF63F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D4D2D16B-6995-41CB-AD77-7FF89FCF63F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D4D2D16B-6995-41CB-AD77-7FF89FCF63F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D4D2D16B-6995-41CB-AD77-7FF89FCF63F8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
19 src/DaemonMaster/DaemonMaster.cs
@@ -26,15 +26,16 @@ public void Execute()
scheduler = schedulerFactory.GetScheduler();
scheduler.Start();
- var types = typeLoader.LoadTypes();
- foreach (var type in types)
+ var foundTypes = typeLoader.LoadTypes();
+ foreach (var foundType in foundTypes)
{
- if (type.IsInterface)
+ if (foundType.Type.IsInterface)
continue;
- if (typeof(IIntervalDaemon).IsAssignableFrom(type))
+ if (typeof(IIntervalDaemon).IsAssignableFrom(foundType.Type))
{
- var intervalDaemon = (IIntervalDaemon)Activator.CreateInstance(type);
+
+ var intervalDaemon = (IIntervalDaemon)Activator.CreateInstance(foundType.Type);
for (var i = 1; i <= intervalDaemon.NumberOfInstances; i++)
{
@@ -43,13 +44,14 @@ public void Execute()
var trigger = TriggerUtils.MakeSecondlyTrigger(intervalDaemon.interval);
trigger.StartTimeUtc = DateTime.UtcNow;
trigger.Name = jobName + "Trigger";
- scheduler.ScheduleJob(jobDetail, trigger);
+ trigger.JobDataMap.Add("configuration", foundType.Configuration);
+ scheduler.ScheduleJob(jobDetail, trigger);
}
}
- if (typeof(IScheduledDaemon).IsAssignableFrom(type))
+ if (typeof(IScheduledDaemon).IsAssignableFrom(foundType.Type))
{
- var scheduledDaemon = (IScheduledDaemon)Activator.CreateInstance(type);
+ var scheduledDaemon = (IScheduledDaemon)Activator.CreateInstance(foundType.Type);
var jobDetail = new JobDetail(scheduledDaemon.Name, null, scheduledDaemon.Job.GetType());
foreach (var cronString in scheduledDaemon.CronStrings)
{
@@ -57,6 +59,7 @@ public void Execute()
trigger.CronExpressionString = cronString;
trigger.StartTimeUtc = DateTime.UtcNow;
trigger.Name = scheduledDaemon.Name + "Trigger";
+ trigger.JobDataMap.Add("configuration", foundType.Configuration);
scheduler.ScheduleJob(jobDetail, trigger);
}
View
9 src/DaemonMaster/DaemonMaster.csproj
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -12,6 +12,10 @@
<AssemblyName>DaemonMaster</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <UpgradeBackupLocation />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -40,6 +44,7 @@
<HintPath>..\..\lib\Quartz.dll</HintPath>
</Reference>
<Reference Include="System" />
+ <Reference Include="System.configuration" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
@@ -53,6 +58,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="DaemonMasterJob.cs" />
+ <Compile Include="FoundType.cs" />
<Compile Include="TypeLoader.cs" />
<Compile Include="DaemonMaster.cs" />
<Compile Include="Email.cs" />
View
22 src/DaemonMaster/DaemonMasterJob.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Quartz;
+using System.Configuration;
+
+namespace DaemonMaster
+{
+ public abstract class DaemonMasterJob: IJob
+ {
+ protected Configuration Configuration { get; private set; }
+
+ void IJob.Execute(JobExecutionContext context)
+ {
+ Configuration = (Configuration)context.MergedJobDataMap["configuration"];
+ Execute(context);
+ }
+
+ protected abstract void Execute(JobExecutionContext context);
+ }
+}
View
20 src/DaemonMaster/FoundType.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Configuration;
+
+namespace DaemonMaster
+{
+ public class FoundType
+ {
+ public Type Type { get; protected set; }
+ public Configuration Configuration { get; protected set; }
+
+ public FoundType(Type type, Configuration configuration)
+ {
+ Type = type;
+ Configuration = configuration;
+ }
+ }
+}
View
2 src/DaemonMaster/ITypeLoader.cs
@@ -5,6 +5,6 @@ namespace DaemonMaster
{
public interface ITypeLoader
{
- IEnumerable<Type> LoadTypes();
+ IEnumerable<FoundType> LoadTypes();
}
}
View
24 src/DaemonMaster/TypeLoader.cs
@@ -3,12 +3,13 @@
using System.Collections.Generic;
using System.IO;
using System.Reflection;
+using System.Configuration;
namespace DaemonMaster
{
public class TypeLoader: ITypeLoader
{
- public IEnumerable<Type> LoadTypes()
+ public IEnumerable<FoundType> LoadTypes()
{
var files = new List<string>();
files.AddRange(Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll"));
@@ -16,11 +17,30 @@ public IEnumerable<Type> LoadTypes()
foreach (var file in files)
{
var asm = Assembly.LoadFrom(file);
+
+ Configuration configuration = LoadConfiguration(file);
foreach (var type in asm.GetTypes())
{
- yield return type;
+ yield return new FoundType(type, configuration);
+ }
+ }
+ }
+
+ private Configuration LoadConfiguration(string file)
+ {
+ string configFile = file + ".config";
+
+ if (file.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) && File.Exists(configFile))
+ {
+ var exeFileMap = new ExeConfigurationFileMap();
+ exeFileMap.ExeConfigFilename = file + ".config";
+ var configuration = ConfigurationManager.OpenMappedExeConfiguration(exeFileMap, ConfigurationUserLevel.None);
+ if (configuration.HasFile)
+ {
+ return configuration;
}
}
+ return null;
}
}
}
View
11 src/DaemonMasterConsole/DaemonMasterConsole.csproj
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -12,6 +12,10 @@
<AssemblyName>DaemonMasterConsole</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <UpgradeBackupLocation />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -64,13 +68,16 @@
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="TestJob.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DaemonMaster\DaemonMaster.csproj">
<Project>{EF438EE5-1D28-4005-95DD-70DEACE41A7B}</Project>
<Name>DaemonMaster</Name>
</ProjectReference>
+ <ProjectReference Include="..\TestDaemons\TestDaemons.csproj">
+ <Project>{D4D2D16B-6995-41CB-AD77-7FF89FCF63F8}</Project>
+ <Name>TestDaemons</Name>
+ </ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
View
39 src/DaemonMasterConsole/TestJob.cs
@@ -1,39 +0,0 @@
-using System;
-using System.Diagnostics;
-using DaemonMaster;
-using Quartz;
-
-namespace DaemonMasterConsole
-{
- public class TestJobDaemon: IIntervalDaemon
- {
- public int interval
- {
- get { return 1; }
- }
-
- public int NumberOfInstances
- {
- get { return 5; }
- }
-
- public IJob Job
- {
- get { return new TestJob(); }
- }
-
- public string Name
- {
- get { return "TestJob"; }
- }
- }
-
- public class TestJob: IJob
- {
- public void Execute(JobExecutionContext context)
- {
- Console.WriteLine(context.JobDetail.FullName);
- Debug.WriteLine("test");
- }
- }
-}
View
6 src/DaemonMasterService/DaemonMasterService.csproj
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -12,6 +12,10 @@
<AssemblyName>DaemonMasterService</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <UpgradeBackupLocation />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
View
6 src/TestDaemons/App.config
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <appSettings>
+ <add key="somevalue" value="my value!"/>
+ </appSettings>
+</configuration>
View
36 src/TestDaemons/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("TestDaemons")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("TestDaemons")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("1152a131-3cdb-4ad4-b6fe-a500f7eb22c2")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
View
78 src/TestDaemons/TestDaemons.csproj
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{D4D2D16B-6995-41CB-AD77-7FF89FCF63F8}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>TestDaemons</RootNamespace>
+ <AssemblyName>TestDaemons</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <UpgradeBackupLocation />
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Quartz, Version=1.0.1.3, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\Quartz.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.configuration" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Xml.Linq">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data.DataSetExtensions">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="TestIntervalDaemon.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\DaemonMaster\DaemonMaster.csproj">
+ <Project>{EF438EE5-1D28-4005-95DD-70DEACE41A7B}</Project>
+ <Name>DaemonMaster</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config">
+ </None>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
View
42 src/TestDaemons/TestIntervalDaemon.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using DaemonMaster;
+using Quartz;
+using System.Configuration;
+
+namespace TestDaemons
+{
+ public class TestIntervalDaemon : IIntervalDaemon
+ {
+ public int interval
+ {
+ get { return 1; }
+ }
+
+ public int NumberOfInstances
+ {
+ get { return 5; }
+ }
+
+ public IJob Job
+ {
+ get { return new TestJob(); }
+ }
+
+ public string Name
+ {
+ get { return "TestJob"; }
+ }
+ }
+
+ public class TestJob : DaemonMasterJob
+ {
+ protected override void Execute(JobExecutionContext context)
+ {
+ var someValue = Configuration.AppSettings.Settings["somevalue"].Value;
+ Console.WriteLine(context.JobDetail.FullName + " " + someValue);
+ }
+ }
+}

0 comments on commit 62557d9

Please sign in to comment.
Something went wrong with that request. Please try again.