Skip to content

Commit

Permalink
Fixes issue #4 - adding handling for problems/exceptions that occur w…
Browse files Browse the repository at this point in the history
…hen you add test cases. Added logging through Common.Logging and replaced all Console.Write usage with the logging facade.
  • Loading branch information
blee committed Mar 24, 2014
1 parent 0725e74 commit fa948f6
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 26 deletions.
6 changes: 6 additions & 0 deletions Renderly.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 12.0.30110.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Renderly", "Renderly\Renderly.csproj", "{6C023729-658D-466F-900E-AC9696D1C7A4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simile.Core", "..\simile\Simile.Core\Simile.Core.csproj", "{4254FFE4-51D6-4240-9C1F-C70849EE85A1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{6C023729-658D-466F-900E-AC9696D1C7A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C023729-658D-466F-900E-AC9696D1C7A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C023729-658D-466F-900E-AC9696D1C7A4}.Release|Any CPU.Build.0 = Release|Any CPU
{4254FFE4-51D6-4240-9C1F-C70849EE85A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4254FFE4-51D6-4240-9C1F-C70849EE85A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4254FFE4-51D6-4240-9C1F-C70849EE85A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4254FFE4-51D6-4240-9C1F-C70849EE85A1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
14 changes: 11 additions & 3 deletions Renderly/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
12 changes: 8 additions & 4 deletions Renderly/Commands/BatchAddTestcaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Mochify.Simile.Core.Models.Csv;
using Mochify.Simile.Core.Utils;

using Common.Logging;

namespace Renderly.Commands
{
/// <summary>
Expand All @@ -17,6 +19,8 @@ namespace Renderly.Commands
/// </summary>
public class BatchAddTestCaseCommand : ConsoleCommand
{
private static readonly ILog _log = LogManager.GetCurrentClassLogger();

public string InputFile { get; set; }
public string AppendTestFile { get; set; }
public string OutputFile { get; set; }
Expand All @@ -31,16 +35,16 @@ public BatchAddTestCaseCommand()

public override int Run(string[] remainingArguments)
{
Console.WriteLine("You are generating tests from {0}", InputFile);
Console.WriteLine("You are writing out to {0}", OutputFile);
_log.InfoFormat("You are generating tests from {0}", InputFile);
_log.InfoFormat("You are writing out to {0}", OutputFile);

if (string.IsNullOrWhiteSpace(AppendTestFile))
{
Console.WriteLine("Not appending to anything.");
_log.Info("Not appending to anything because no append file specified.");
}
else
{
Console.WriteLine("Appending to {0}.", AppendTestFile);
_log.InfoFormat("Appending to {0}.", AppendTestFile);
File.Copy(AppendTestFile, OutputFile);
}

Expand Down
38 changes: 21 additions & 17 deletions Renderly/Commands/DeleteTestcaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;

using ManyConsole;
using Common.Logging;
using Mochify.Simile.Core;
using Mochify.Simile.Core.Models.Csv;
using Mochify.Simile.Core.Utils;
Expand All @@ -12,6 +13,7 @@ namespace Renderly.Commands
{
public class DeleteTestCaseCommand : ConsoleCommand
{
private static readonly ILog _log = LogManager.GetCurrentClassLogger();
private string ModelFile { get; set; }
private string OutputFile { get; set; }
private IEnumerable<DateTime> Dates { get; set; }
Expand Down Expand Up @@ -53,30 +55,32 @@ public override int Run(string[] remainingArguments)
{
if (!Dates.Any() && !Releases.Any() && !TestIds.Any())
{
Console.WriteLine("Nothing to do, please specify at least one of dates|releases|test ids");
_log.Info("Nothing to do, please specify at least one of dates|releases|test ids");
}
else
{
var predicate = PredicateBuilder.False<TestCase>();

var predicate = PredicateBuilder.False<TestCase>();
foreach (var d in Dates)
{
predicate = predicate.Or(x => x.DateAdded.Date == d.Date);
}

foreach (var d in Dates)
{
predicate = predicate.Or(x => x.DateAdded.Date == d.Date);
}
foreach (var s in Releases)
{
predicate = predicate.Or(x => x.Release == s);
}

foreach (var s in Releases)
{
predicate = predicate.Or(x => x.Release == s);
}
foreach (var t in TestIds)
{

foreach (var t in TestIds)
{
predicate = predicate.Or(x => x.TestId == t);
}

predicate = predicate.Or(x => x.TestId == t);
var deleted = model.Delete(predicate.Compile());
_log.InfoFormat("Deleted {0} test cases from {1}", deleted, ModelFile);
model.Save();
}

var deleted = model.Delete(predicate.Compile());
Console.WriteLine("Deleted {0} test cases from {1}", deleted, ModelFile);
model.Save();
}

return 0;
Expand Down
23 changes: 23 additions & 0 deletions Renderly/NLog.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<variable name="brief" value="${level} | ${logger} | ${message}" />
<variable name="verbose" value="${longdate} | ${level} | ${logger} | ${callsite} | ${message}" />
<targets>
<target name="asyncFile" xsi:type="AsyncWrapper">
<target
name="log"
xsi:type="File"
fileName="renderly.log"
layout="${verbose}"/>
</target>
<target
name="con"
xsi:type="ColoredConsole"
layout="${brief}"/>
</targets>
<rules>
<logger name="*" writeTo="con" minlevel="Trace"
layout="${brief}"/>
<logger name="*" minlevel="Debug" writeTo="asyncFile" />
</rules>
</nlog>
24 changes: 24 additions & 0 deletions Renderly/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
using Mochify.Simile.Core.Imaging;
using ManyConsole;

using Common.Logging;
using Common.Logging.Configuration;
using Common.Logging.NLog;

using Autofac;

namespace Renderly
{
class Program
{
private static readonly ILog _log = LogManager.GetCurrentClassLogger();
private static ContainerBuilder RegisterAssemblyTypes()
{
// TODO do the IoC wiring here, which probably also means
Expand All @@ -29,8 +34,27 @@ private static IEnumerable<ConsoleCommand> GetCommands()
return ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(Program));
}

static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
{
// UnhandledExceptionEventArgs.ExceptionObject can be a type of non-Exception when
// thrown from a non C#/VB.net assembly, but by default, .NET 2.0 and newer
// wrap the object in a RuntimWrappedException
// The assembly property to set to disable/enable would be:
// [assembly:RuntimeCompatibilityAttribute(WrapNonExceptionThrows = false)];
_log.Info("Something unexpected happened! Please check for updates or file an issue on github", e.ExceptionObject as Exception);
Environment.Exit(1);
}

static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;

NameValueCollection logProperties = new NameValueCollection();
logProperties["configType"] = "FILE";
logProperties["configFile"] = "~/NLog.config";

LogManager.Adapter = new NLogLoggerFactoryAdapter(logProperties);

//var containerBuilder = RegisterAssemblyTypes();
var commands = GetCommands();
ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out);
Expand Down
20 changes: 18 additions & 2 deletions Renderly/Renderly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Renderly</RootNamespace>
<AssemblyName>Renderly</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<AssemblyName>renderly</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -35,6 +36,15 @@
<Reference Include="Autofac">
<HintPath>..\packages\Autofac.3.3.0\lib\net40\Autofac.dll</HintPath>
</Reference>
<Reference Include="Common.Logging">
<HintPath>..\packages\Common.Logging.2.2.0\lib\net40\Common.Logging.dll</HintPath>
</Reference>
<Reference Include="Common.Logging.Core">
<HintPath>..\packages\Common.Logging.Core.2.2.0\lib\net40\Common.Logging.Core.dll</HintPath>
</Reference>
<Reference Include="Common.Logging.NLog20">
<HintPath>..\packages\Common.Logging.NLog20.2.2.0\lib\net40\Common.Logging.NLog20.dll</HintPath>
</Reference>
<Reference Include="ManyConsole">
<HintPath>..\packages\ManyConsole.0.4.2.17\lib\ManyConsole.dll</HintPath>
</Reference>
Expand All @@ -44,6 +54,9 @@
<Reference Include="NDesk.Options">
<HintPath>..\packages\NDesk.Options.0.2.1\lib\NDesk.Options.dll</HintPath>
</Reference>
<Reference Include="NLog">
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -63,6 +76,9 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
5 changes: 5 additions & 0 deletions Renderly/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.3.0" targetFramework="net45" />
<package id="Common.Logging" version="2.2.0" targetFramework="net40" />
<package id="Common.Logging.Core" version="2.2.0" targetFramework="net40" />
<package id="Common.Logging.NLog" version="2.0.0" targetFramework="net40" />
<package id="Common.Logging.NLog20" version="2.2.0" targetFramework="net40" />
<package id="ManyConsole" version="0.4.2.17" targetFramework="net45" />
<package id="NDesk.Options" version="0.2.1" targetFramework="net45" />
<package id="NLog" version="2.0.0.2000" targetFramework="net40" />
</packages>

0 comments on commit fa948f6

Please sign in to comment.