Permalink
Browse files

files

  • Loading branch information...
1 parent 57e344f commit 04742d03ad479b248ec54a7d41a2504be1ea88a1 @bertvan committed Feb 2, 2012
Showing with 312 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +42 −0 ArgsReader.cs
  3. +50 −0 CheckFileMaximumLength.cs
  4. +61 −0 FileTools.csproj
  5. +20 −0 FileTools.sln
  6. +15 −0 Program.cs
  7. +36 −0 Properties/AssemblyInfo.cs
  8. +21 −0 ToolBase.cs
  9. +63 −0 ToolRunner.cs
View
@@ -0,0 +1,4 @@
+
+/bin
+/obj
+/FileTools.suo
View
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FileTools
+{
+ public class ArgsReader
+ {
+ public KeyValuePair<string, string> ExtractKeyValuePair(string arg)
+ {
+ var indexOfEquals = arg.IndexOf("=");
+
+ return new KeyValuePair<string, string>(
+ arg.Substring(0, indexOfEquals),
+ arg.Remove(0, indexOfEquals + 1));
+ }
+
+ public T ExtractKeyValue<T>(string[] args, string key)
+ {
+ var value = ExtractKeyValue(args, key);
+
+ return (T)Convert.ChangeType(value, typeof(T));
+ }
+
+ public string ExtractKeyValue(string[] args, string key)
+ {
+ for (int i = 0; i < args.Length; i++)
+ {
+ var arg = args[i];
+ var kvp = ExtractKeyValuePair(arg);
+
+ if (kvp.Key.Equals(key, StringComparison.OrdinalIgnoreCase))
+ {
+ return kvp.Value;
+ }
+ }
+
+ return null;
+ }
+ }
+}
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.IO;
+
+namespace FileTools
+{
+ public class CheckFileMaximumLength : ToolBase
+ {
+ public override string ToolName
+ {
+ get { return "checkfilemaxlength"; }
+ }
+
+ public CheckFileMaximumLength(string[] args): base(args) { }
+
+ public override void Run()
+ {
+ var maxLength = new ArgsReader().ExtractKeyValue<int>(Args, "max");
+ var directoryPath = new ArgsReader().ExtractKeyValue(Args, "dir");
+
+ Console.WriteLine(
+ string.Format(
+ "Looking for files, longer than {0} in '{1}'",
+ maxLength, directoryPath));
+
+ var dir = new DirectoryInfo(directoryPath);
+
+ checkDir(dir, maxLength);
+
+ }
+
+ private void checkDir(DirectoryInfo dir, int maxLength)
+ {
+ foreach (var file in dir.GetFiles())
+ {
+ if (file.FullName.Length > maxLength)
+ {
+ Console.WriteLine(file.FullName);
+ }
+ }
+
+ foreach (var subdir in dir.GetDirectories())
+ {
+ checkDir(subdir, maxLength);
+ }
+ }
+ }
+}
View
@@ -0,0 +1,61 @@
+<?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)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{79D6220E-4F9D-412C-B5D0-CABF4D839E47}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>FileTools</RootNamespace>
+ <AssemblyName>FileTools</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <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|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="ArgsReader.cs" />
+ <Compile Include="CheckFileMaximumLength.cs" />
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="ToolBase.cs" />
+ <Compile Include="ToolRunner.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.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
View
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileTools", "FileTools.csproj", "{79D6220E-4F9D-412C-B5D0-CABF4D839E47}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x86 = Debug|x86
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {79D6220E-4F9D-412C-B5D0-CABF4D839E47}.Debug|x86.ActiveCfg = Debug|x86
+ {79D6220E-4F9D-412C-B5D0-CABF4D839E47}.Debug|x86.Build.0 = Debug|x86
+ {79D6220E-4F9D-412C-B5D0-CABF4D839E47}.Release|x86.ActiveCfg = Release|x86
+ {79D6220E-4F9D-412C-B5D0-CABF4D839E47}.Release|x86.Build.0 = Release|x86
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
View
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FileTools
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ new ToolRunner(args).Run();
+ }
+ }
+}
@@ -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("FileTools")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("FileTools")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
+[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("8d1dd648-5c67-49f4-aa90-d487c1bce991")]
+
+// 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
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FileTools
+{
+ public abstract class ToolBase
+ {
+ protected string[] Args { get; set; }
+
+ public ToolBase(string[] args)
+ {
+ this.Args = args;
+ }
+
+ public abstract string ToolName { get; }
+
+ public abstract void Run();
+ }
+}
View
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FileTools
+{
+ class ToolRunner
+ {
+ private string[] args;
+ private Dictionary<string, ToolBase> tools = new Dictionary<string, ToolBase>();
+
+ public ToolRunner(string[] args)
+ {
+ this.args = args;
+ }
+
+ internal void Run()
+ {
+ loadTools();
+
+ var selectedTool = extractSelectedTool(args);
+
+ if (string.IsNullOrEmpty(selectedTool))
+ {
+ Console.WriteLine("You did not select a tool, use \"tool=\" to select a tool");
+ Console.Read();
+ return;
+ }
+
+ Console.WriteLine("You selected " + selectedTool);
+
+ if (!tools.ContainsKey(selectedTool))
+ {
+ Console.WriteLine("Never heard of that");
+ Console.Read();
+ return;
+ }
+
+ var tool = tools[selectedTool];
+
+ tool.Run();
+ }
+
+ private void loadTools()
+ {
+ foreach (var t in this.GetType().Assembly.GetTypes())
+ {
+ if (typeof(ToolBase).IsAssignableFrom(t) && t != typeof(ToolBase))
+ {
+ var tool = (ToolBase)Activator.CreateInstance(t, new object[] { args });
+
+ tools.Add(tool.ToolName, tool);
+ }
+ }
+ }
+
+ private string extractSelectedTool(string[] args)
+ {
+ return new ArgsReader().ExtractKeyValue(args, "tool");
+ }
+ }
+}

0 comments on commit 04742d0

Please sign in to comment.