Skip to content

Commit

Permalink
Massive Cleanup
Browse files Browse the repository at this point in the history
Configures Resharper, StyleCop and the SonarQube analyzers, cleaned up the solution quite a bit, tried to align the code style in a way that seems to suit most team members and aligns closely to the default stylecop rules.

Added quite a bit of documentation to commonly used classes.

Cleaned up or simplified a lot of complex conditionals.
  • Loading branch information
jessehouwing committed Aug 18, 2015
1 parent c4023ee commit 2b58250
Show file tree
Hide file tree
Showing 83 changed files with 1,717 additions and 627 deletions.
9 changes: 7 additions & 2 deletions Aggregator.ConsoleApp/Aggregator.ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
<CodeAnalysisRuleSet>..\TFS-Aggregator-2.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -34,6 +35,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>..\TFS-Aggregator-2.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>TfsAggregator.ico</ApplicationIcon>
Expand Down Expand Up @@ -250,10 +252,10 @@
</Compile>
<Compile Include="ExceptionExtensions.cs" />
<Compile Include="ConsoleTextLogger.cs" />
<Compile Include="NotificationConsoleApp.cs" />
<Compile Include="Notification.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RequestContextConsoleApp.cs" />
<Compile Include="RequestContext.cs" />
<Compile Include="RunCommand.cs" />
<Compile Include="ConsoleEventLogger.cs" />
</ItemGroup>
Expand All @@ -270,6 +272,9 @@
<ItemGroup>
<Content Include="TfsAggregator.ico" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\StyleCop.Analyzers.1.0.0-beta007\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Microsoft.TeamFoundationServer.ExtendedClient.14.83.1\build\Microsoft.TeamFoundationServer.ExtendedClient.targets" Condition="Exists('..\packages\Microsoft.TeamFoundationServer.ExtendedClient.14.83.1\build\Microsoft.TeamFoundationServer.ExtendedClient.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
21 changes: 14 additions & 7 deletions Aggregator.ConsoleApp/ConsoleEventLogger.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
namespace Aggregator.ConsoleApp
{
using Aggregator.Core;
using Aggregator.Core.Monitoring;
using Aggregator.Core;
using Aggregator.Core.Monitoring;

class ConsoleEventLogger : TextLogComposer
namespace Aggregator.ConsoleApp
{
/// <summary>
/// Logs all events to the console.
/// </summary>
internal class ConsoleEventLogger : TextLogComposer
{
public ConsoleEventLogger(LogLevel level)
: base(new ConsoleTextLogger(level))
/// <summary>
/// Initializes a new instance of the <see cref="ConsoleEventLogger"/> class.
/// </summary>
/// <param name="minimumLogLevel">The minimum log level to show.</param>
public ConsoleEventLogger(LogLevel minimumLogLevel)
: base(new ConsoleTextLogger(minimumLogLevel))
{ }
}
}
30 changes: 15 additions & 15 deletions Aggregator.ConsoleApp/ConsoleTextLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,50 @@
using System;
using System.Diagnostics;

using Aggregator.Core;
using Aggregator.Core.Monitoring;
using Core;
using Core.Monitoring;

internal class ConsoleTextLogger : ITextLogger
{
private LogLevel minLevel;
private Stopwatch clock = new Stopwatch();
private LogLevel minimumLogLevel;
private readonly Stopwatch clock = new Stopwatch();

internal ConsoleTextLogger(LogLevel level)
internal ConsoleTextLogger(LogLevel minimumLogLevel)
{
this.minLevel = level;
this.minimumLogLevel = minimumLogLevel;
this.clock.Restart();
}

static ConsoleColor MapColor(LogLevel level)
{
switch (level)
{
case LogLevel.Critical:
return ConsoleColor.Red;
case LogLevel.Error:
case LogLevel.Critical:
return ConsoleColor.Red;

case LogLevel.Warning:
return ConsoleColor.Yellow;
case LogLevel.Information:
return ConsoleColor.Gray;

case LogLevel.Verbose:
return ConsoleColor.Cyan;
case LogLevel.Diagnostic:
return ConsoleColor.Cyan;

case LogLevel.Information:
default:
return ConsoleColor.Gray;
}//switch
}

public LogLevel Level
public LogLevel MinimumLogLevel
{
get { return minLevel; }
set { minLevel = value; }
get { return this.minimumLogLevel; }
set { this.minimumLogLevel = value; }
}

public void Log(LogLevel level, string format, params object[] args)
{
if (level > this.minLevel)
if (level > this.minimumLogLevel)
return;

clock.Stop();
Expand Down
36 changes: 36 additions & 0 deletions Aggregator.ConsoleApp/Notification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Aggregator.Core;
using Aggregator.Core.Interfaces;

namespace Aggregator.ConsoleApp
{
/// <summary>
/// Notification implementation for the Console Application
/// </summary>
public class Notification : INotification
{
/// <summary>
/// Initializes a new instance of the <see cref="Notification"/> class.
/// </summary>
/// <param name="workItemId">
/// WorkItemId of the work item to load and apply the policy on.
/// </param>
/// <param name="projectName">
/// The name of the project that holds this work item.
/// </param>
public Notification(int workItemId, string projectName)
{
this.WorkItemId = workItemId;
this.ProjectUri = projectName;
}

/// <summary>
/// WorkItemId of the work item to load and apply the policy on.
/// </summary>
public int WorkItemId { get; }

/// <summary>
/// The name of the project that holds the work item.
/// </summary>
public string ProjectUri { get; }
}
}
31 changes: 0 additions & 31 deletions Aggregator.ConsoleApp/NotificationConsoleApp.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Aggregator.ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

using ManyConsole;

class Program
static class Program
{
static int Main(string[] args)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
namespace Aggregator.ConsoleApp
{
using System;
using System.Linq;
using System;
using System.Linq;

using Aggregator.Core;
using Aggregator.Core.Facade;
using Aggregator.Core.Interfaces;
using Aggregator.Core;
using Aggregator.Core.Facade;
using Aggregator.Core.Interfaces;

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.Framework.Server;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.Server.Core;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.Framework.Server;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.Server.Core;

public class RequestContextConsoleApp : IRequestContext
namespace Aggregator.ConsoleApp
{
public class RequestContext : IRequestContext
{
internal string teamProjectCollectionUrl;
internal readonly string teamProjectCollectionUrl;

private string teamProjectName;
private readonly string teamProjectName;

public RequestContextConsoleApp(string teamProjectCollectionUrl, string teamProjectName)
public RequestContext(string teamProjectCollectionUrl, string teamProjectName)
{
this.teamProjectCollectionUrl = teamProjectCollectionUrl;
this.teamProjectName = teamProjectName;
Expand All @@ -43,12 +43,12 @@ public IProjectPropertyWrapper[] GetProjectProperties(Uri projectUri)
{
var context = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(this.teamProjectCollectionUrl));
var ics = context.GetService<ICommonStructureService4>();

string projectName;
string projectState;
int templateId = 0;
ProjectProperty[] projectProperties = null;

ics.GetProjectProperties(projectUri.ToString(), out projectName, out projectState, out templateId, out projectProperties);

return projectProperties.Select(p => (IProjectPropertyWrapper)new ProjectPropertyWrapper() { Name = p.Name, Value = p.Value }).ToArray();
Expand All @@ -69,19 +69,19 @@ private IProcessTemplateVersionWrapper GetProjectProcessVersion(string projectUr
{
ProcessTemplateVersion unknown = null;

var context = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(teamProjectCollectionUrl));
var context = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(this.teamProjectCollectionUrl));
var ics = context.GetService<ICommonStructureService4>();

string ProjectName = string.Empty;
string ProjectState = String.Empty;
int templateId = 0;
ProjectProperty[] ProjectProperties = null;
string projectName;
string projectState;

ics.GetProjectProperties(projectUri.ToString(), out ProjectName, out ProjectState, out templateId, out ProjectProperties);
int templateId = 0;
ProjectProperty[] projectProperties = null;

ics.GetProjectProperties(projectUri.ToString(), out projectName, out projectState, out templateId, out projectProperties);

string rawVersion =
ProjectProperties.FirstOrDefault(p => p.Name == versionPropertyName).Value;
projectProperties.FirstOrDefault(p => p.Name == versionPropertyName).Value;

if (rawVersion == null)
{
Expand All @@ -93,6 +93,5 @@ private IProcessTemplateVersionWrapper GetProjectProcessVersion(string projectUr
return new ProcessTemplateVersionWrapper() { TypeId = result.TypeId, Major = result.Major, Minor = result.Minor };
}
}

}
}
12 changes: 7 additions & 5 deletions Aggregator.ConsoleApp/RunCommand.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace Aggregator.ConsoleApp
using Aggregator.Core.Context;
using Aggregator.Core.Monitoring;

namespace Aggregator.ConsoleApp
{
using System;

using Aggregator.Core;
using Aggregator.Core.Configuration;
using Core;

using ManyConsole;

Expand Down Expand Up @@ -50,7 +52,7 @@ public override int Run(string[] remainingArguments)

var runtime = RuntimeContext.GetContext(
() => this.PolicyFile,
new RequestContextConsoleApp(this.TeamProjectCollectionUrl, this.TeamProjectName),
new RequestContext(this.TeamProjectCollectionUrl, this.TeamProjectName),
logger
);
if (runtime.HasErrors)
Expand All @@ -65,7 +67,7 @@ public override int Run(string[] remainingArguments)
try
{
var context = runtime.RequestContext;
var notification = new NotificationConsoleApp(this.WorkItemId, this.TeamProjectName);
var notification = new Notification(this.WorkItemId, this.TeamProjectName);

logger.StartingProcessing(context, notification);
result = eventProcessor.ProcessEvent(context, notification);
Expand Down
1 change: 1 addition & 0 deletions Aggregator.ConsoleApp/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="1.7.0.0" targetFramework="net45" />
<package id="NDesk.Options" version="0.2.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net45" />
<package id="StyleCop.Analyzers" version="1.0.0-beta007" targetFramework="net45" developmentDependency="true" />
<package id="System.IdentityModel.Tokens.Jwt" version="4.0.0" targetFramework="net45" />
<package id="System.Management.Automation_PowerShell_3.0" version="6.3.9600.17400" targetFramework="net45" />
<package id="WindowsAzure.ServiceBus" version="2.5.1.0" targetFramework="net45" />
Expand Down
Loading

0 comments on commit 2b58250

Please sign in to comment.