Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
Add files part of new refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ssg committed Jul 29, 2014
1 parent 726c24e commit 811693c
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 0 deletions.
18 changes: 18 additions & 0 deletions DuplicatePathChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace PathCleaner
{
class DuplicatePathChecker : IPathChecker
{
public string Reason
{
get { return "Duplicate"; }
}

public bool Identify(string folder, string previousFolder)
{
return previousFolder != null
&& String.Compare(folder, previousFolder, StringComparison.InvariantCultureIgnoreCase) == 0;
}
}
}
19 changes: 19 additions & 0 deletions EmptyPathChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.IO;
using System.Linq;

namespace PathCleaner
{
class EmptyPathChecker : IPathChecker
{
public string Reason
{
get { return "Empty"; }
}

public bool Identify(string folder, string previousFolder)
{
return !Directory.EnumerateFiles(folder).Any();
}
}

}
9 changes: 9 additions & 0 deletions IPathChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace PathCleaner
{
interface IPathChecker
{
string Reason { get; }
bool Identify(string folder, string previousFolder);
}

}
18 changes: 18 additions & 0 deletions MissingPathChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.IO;

namespace PathCleaner
{
class MissingPathChecker : IPathChecker
{
public string Reason
{
get { return "Missing"; }
}

public bool Identify(string folder, string previousFolder)
{
return !Directory.Exists(folder);
}
}

}
27 changes: 27 additions & 0 deletions NoExecutablesPathChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace PathCleaner
{
class NoExecutablesPathChecker : IPathChecker
{
private static HashSet<string> executableExtensions = new HashSet<string>()
{
".exe", ".com", ".bat", ".cmd", ".ps1", ".dll"
};

public string Reason
{
get { return "No executables"; }
}

public bool Identify(string folder, string previousFolder)
{
return !Directory.EnumerateFiles(folder)
.Where(s => executableExtensions.Contains(Path.GetExtension(s)))
.Any();
}
}

}
42 changes: 42 additions & 0 deletions ProblemIdentifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Collections.Generic;
using System.Linq;

namespace PathCleaner
{
class ProblemIdentifier
{
public IEnumerable<IPathChecker> Checkers { get; private set; }
public PathString PathString { get; private set; }

public ProblemIdentifier(PathString pathString, IEnumerable<IPathChecker> checkers)
{
this.PathString = pathString;
this.Checkers = checkers;
}

public IEnumerable<PathProblem> Problems
{
get
{
var sortedFolders = new List<string>(PathString.Folders.OrderBy(s => s));
string previousFolder = null;
foreach(string folder in sortedFolders)
{
var problem = Checkers.Where(c => c.Identify(folder, previousFolder))
.Select(c => new PathProblem
{
Path = folder,
Reason = c.Reason,
})
.FirstOrDefault();
if (problem != null)
{
yield return problem;
}
previousFolder = folder;
}
}
}

}
}

0 comments on commit 811693c

Please sign in to comment.