[tarantino] r160 committed - - Refactor of BatchJobs.Core to remove dependency on Log4Net...

0 views
Skip to first unread message

codesite...@google.com

unread,
Apr 2, 2010, 10:39:12 AM4/2/10
to tarantino...@googlegroups.com
Revision: 160
Author: ajepst
Date: Fri Apr 2 07:39:02 2010
Log: - Refactor of BatchJobs.Core to remove dependency on Log4Net
- Refactor of BatchJobs.Console to remove dependency on the main part of
Tarantino
- Some adjustment of job exceptions to get them properly logged
http://code.google.com/p/tarantino/source/detail?r=160

Added:
/trunk/src/BatchJobs.Console/LoggerProxy.cs
/trunk/src/BatchJobs.Core/AbstractFactoryBase.cs
/trunk/src/BatchJobs.Core/Logging
/trunk/src/BatchJobs.Core/Logging/BatchLoggerFactory.cs
/trunk/src/BatchJobs.Core/Logging/ILogger.cs
/trunk/src/BatchJobs.Core/Logging/StubLogger.cs
Deleted:
/trunk/src/BatchJobs.Core/ILogger.cs
Modified:
/trunk/src/BatchJobs.Console/BatchJobs.Console.csproj
/trunk/src/BatchJobs.Console/Logger.cs
/trunk/src/BatchJobs.Console/Program.cs
/trunk/src/BatchJobs.Core/BatchJobs.Core.csproj
/trunk/src/BatchJobs.Core/JobAgentBase.cs
/trunk/src/BatchJobs.UnitTests/JobAgentBaseTester.cs
/trunk/src/BatchJobs.UnitTests/ProgramTester.cs

=======================================
--- /dev/null
+++ /trunk/src/BatchJobs.Console/LoggerProxy.cs Fri Apr 2 07:39:02 2010
@@ -0,0 +1,37 @@
+using BatchJobs.Core.Logging;
+
+namespace BatchJobs.Console
+{
+ public class LoggerProxy : ILogger
+ {
+ public string CONFIG_FILE_NAME
+ {
+ get { return Logger.CONFIG_FILE_NAME; }
+ }
+
+ public void Error(object source, object message)
+ {
+ Logger.Error(source, message);
+ }
+
+ public void Warn(object source, object message)
+ {
+ Logger.Warn(source, message);
+ }
+
+ public void Info(object source, object message)
+ {
+ Logger.Info(source, message);
+ }
+
+ public void Fatal(object source, object message)
+ {
+ Logger.Fatal(source, message);
+ }
+
+ public void Debug(object source, object message)
+ {
+ Logger.Debug(source, message);
+ }
+ }
+}
=======================================
--- /dev/null
+++ /trunk/src/BatchJobs.Core/AbstractFactoryBase.cs Fri Apr 2 07:39:02
2010
@@ -0,0 +1,12 @@
+using System;
+
+namespace BatchJobs.Core
+{
+ public class AbstractFactoryBase<T>
+ {
+ protected static T DefaultUnconfiguredState()
+ {
+ throw new Exception(typeof(T).Name + " not configured.");
+ }
+ }
+}
=======================================
--- /dev/null
+++ /trunk/src/BatchJobs.Core/Logging/BatchLoggerFactory.cs Fri Apr 2
07:39:02 2010
@@ -0,0 +1,9 @@
+using System;
+
+namespace BatchJobs.Core.Logging
+{
+ public class BatchLoggerFactory : AbstractFactoryBase<ILogger>
+ {
+ public static Func<ILogger> Default = DefaultUnconfiguredState;
+ }
+}
=======================================
--- /dev/null
+++ /trunk/src/BatchJobs.Core/Logging/ILogger.cs Fri Apr 2 07:39:02 2010
@@ -0,0 +1,14 @@
+using System;
+
+namespace BatchJobs.Core.Logging
+{
+ public interface ILogger
+ {
+ string CONFIG_FILE_NAME { get; }
+ void Error(object source, object message);
+ void Warn(object source, object message);
+ void Info(object source, object message);
+ void Fatal(object source, object message);
+ void Debug(object source, object message);
+ }
+}
=======================================
--- /dev/null
+++ /trunk/src/BatchJobs.Core/Logging/StubLogger.cs Fri Apr 2 07:39:02 2010
@@ -0,0 +1,30 @@
+namespace BatchJobs.Core.Logging
+{
+ public class StubLogger : ILogger
+ {
+ public void Info(object source, object message)
+ {
+ }
+
+ public void Warn(object source, object message)
+ {
+ }
+
+ public string CONFIG_FILE_NAME
+ {
+ get { return ""; }
+ }
+
+ public void Error(object source, object message)
+ {
+ }
+
+ public void Fatal(object source, object message)
+ {
+ }
+
+ public void Debug(object source, object message)
+ {
+ }
+ }
+}
=======================================
--- /trunk/src/BatchJobs.Core/ILogger.cs Mon Mar 1 14:48:26 2010
+++ /dev/null
@@ -1,14 +0,0 @@
-using System;
-
-namespace BatchJobs.Core
-{
- public interface ILogger
- {
- string CONFIG_FILE_NAME { get; }
- void Error(object source, object message);
- void Warn(object source, object message);
- void Info(object source, object message);
- void Fatal(object source, object message);
- void Debug(object source, object message);
- }
-}
=======================================
--- /trunk/src/BatchJobs.Console/BatchJobs.Console.csproj Wed Mar 31
15:15:37 2010
+++ /trunk/src/BatchJobs.Console/BatchJobs.Console.csproj Fri Apr 2
07:39:02 2010
@@ -69,6 +69,7 @@
<Compile Include="DebugerJobAgentFactory.cs" />
<Compile Include="LogFileToEmailSender.cs" />
<Compile Include="Logger.cs" />
+ <Compile Include="LoggerProxy.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
=======================================
--- /trunk/src/BatchJobs.Console/Logger.cs Mon Mar 1 14:48:26 2010
+++ /trunk/src/BatchJobs.Console/Logger.cs Fri Apr 2 07:39:02 2010
@@ -1,46 +1,11 @@
using System;
using System.Collections.Generic;
using System.IO;
-using BatchJobs.Core;
using log4net;
using log4net.Config;

namespace BatchJobs.Console
{
- public class LoggerProxy : ILogger
- {
- public string CONFIG_FILE_NAME
- {
- get { return Logger.CONFIG_FILE_NAME; }
- }
-
- public void Error(object source, object message)
- {
- Logger.Error(source, message);
- }
-
- public void Warn(object source, object message)
- {
- Logger.Warn(source, message);
- }
-
- public void Info(object source, object message)
- {
- Logger.Info(source, message);
- }
-
- public void Fatal(object source, object message)
- {
- Logger.Fatal(source, message);
- }
-
- public void Debug(object source, object message)
- {
- Logger.Debug(source, message);
- }
- }
-
-
public static class Logger
{
private static bool _logInitialized;
=======================================
--- /trunk/src/BatchJobs.Console/Program.cs Wed Mar 31 15:15:37 2010
+++ /trunk/src/BatchJobs.Console/Program.cs Fri Apr 2 07:39:02 2010
@@ -23,6 +23,8 @@
catch (Exception e)
{
System.Console.WriteLine(e.Message);
+ Logger.Fatal(typeof(Program), string.Format("Failure in Job, bubbled
to Batch Runner: {0}", Logger.SerializeException(e)));
+
var sender = new LogFileToEmailSender();

sender.Send(string.Join(",", args));
@@ -46,16 +48,9 @@
Logger.Info(this, string.Format("Command Line Specified Instance Name:
{0}", args[0]));
IJobAgent jobAgent = Factory().Create(args[0]);
Logger.Info(this, "Executing the Job");
- try
- {
- jobAgent.Execute();
- Logger.Info(this, string.Format("Job Execution Complete: {0}",
args[0]));
- }
- catch ( Exception e)
- {
- Logger.Fatal(typeof(Program), string.Format("Failure in Job, bubbled
to Batch Runner: {0}", Logger.SerializeException(e)));
- throw;
- }
+
+ jobAgent.Execute();
+ Logger.Info(this, string.Format("Job Execution Complete: {0}",
args[0]));
}
}

=======================================
--- /trunk/src/BatchJobs.Core/BatchJobs.Core.csproj Mon Mar 1 14:48:26 2010
+++ /trunk/src/BatchJobs.Core/BatchJobs.Core.csproj Fri Apr 2 07:39:02 2010
@@ -45,19 +45,16 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="AbstractFactoryBase.cs" />
<Compile Include="IJobAgentFactory.cs" />
- <Compile Include="ILogger.cs" />
+ <Compile Include="Logging\ILogger.cs" />
<Compile Include="JobAgentBase.cs" />
<Compile Include="IJobAgent.cs" />
<Compile Include="IStateTransitionFactory.cs" />
<Compile Include="IStateTransition.cs" />
+ <Compile Include="Logging\BatchLoggerFactory.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\Tarantino.Core\Tarantino.Core.csproj">
- <Project>{3F02EEBD-5B3B-4C5F-B2E7-4F5DFF6B3F03}</Project>
- <Name>Tarantino.Core</Name>
- </ProjectReference>
+ <Compile Include="Logging\StubLogger.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the
targets below and uncomment it.
=======================================
--- /trunk/src/BatchJobs.Core/JobAgentBase.cs Mon Mar 1 14:48:26 2010
+++ /trunk/src/BatchJobs.Core/JobAgentBase.cs Fri Apr 2 07:39:02 2010
@@ -1,10 +1,10 @@
-using System;
using System.Collections.Generic;
-using Tarantino.Core.Commons.Services.Logging;
+using BatchJobs.Core.Logging;
+

namespace BatchJobs.Core
{
- public abstract class JobAgentBase<T> : IJobAgent where T : class
+ public abstract class JobAgentBase<T> : IJobAgent where T : class
{
private readonly IStateTransitionFactory _factory;

@@ -15,20 +15,20 @@

public void Execute()
{
- Logger.Debug(this, "Getting transitions");
+ BatchLoggerFactory.Default().Debug(this, "Getting transitions");
IEnumerable<IStateTransition<T>> transitions =
_factory.GetAll<T>();
- Logger.Debug(this, "Retrieved transitions");
+ BatchLoggerFactory.Default().Debug(this, "Retrieved transitions");
T[] batches = GetNextEntites();
- Logger.Debug(this, string.Format("Found {0} batches", batches.Length));
+ BatchLoggerFactory.Default().Debug(this, string.Format("Found {0}
batches", batches.Length));

foreach (T batch in batches)
{
foreach (var transition in transitions)
{
- Logger.Debug(this, string.Format("Examining transition {0} in batch
{1}", transition, batch));
+ BatchLoggerFactory.Default().Debug(this, string.Format("Examining
transition {0} in batch {1}", transition, batch));
if (transition.IsValid(batch))
{
- Logger.Debug(this, string.Format("Transition {0} is valid for batch
{1}, executing", transition, batch));
+ BatchLoggerFactory.Default().Debug(this, string.Format("Transition
{0} is valid for batch {1}, executing", transition, batch));
transition.Execute(batch);
}
}
=======================================
--- /trunk/src/BatchJobs.UnitTests/JobAgentBaseTester.cs Wed Dec 9
12:00:36 2009
+++ /trunk/src/BatchJobs.UnitTests/JobAgentBaseTester.cs Fri Apr 2
07:39:02 2010
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using BatchJobs.Core;
+using BatchJobs.Core.Logging;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

@@ -12,6 +13,7 @@
[Test]
public void Should_loop_through_the_batches()
{
+ BatchLoggerFactory.Default = () => new StubLogger();
StateTransitions.Called = 0;
var agent = new JobAgentStub(new StubAgentFactory(1));
agent.Execute();
@@ -21,6 +23,7 @@
[Test]
public void Should_loop_through_each_transitions_for_each_batch()
{
+ BatchLoggerFactory.Default = () => new StubLogger();
StateTransitions.Called = 0;
var agent = new JobAgentStub(new StubAgentFactory(3));
agent.Execute();
=======================================
--- /trunk/src/BatchJobs.UnitTests/ProgramTester.cs Wed Mar 31 15:15:37 2010
+++ /trunk/src/BatchJobs.UnitTests/ProgramTester.cs Fri Apr 2 07:39:02 2010
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using BatchJobs.Console;
using BatchJobs.Core;
+using BatchJobs.Core.Logging;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

Reply all
Reply to author
Forward
0 new messages