This commit is contained in:
grzegorz.russek
2014-04-24 19:30:35 +00:00
parent b48a9a3416
commit 9bc5cd7540
18 changed files with 11192 additions and 449 deletions

View File

@@ -0,0 +1,58 @@
<?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>{A64D2052-D0CD-488E-BF05-E5952615D926}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AmalgamationTool</RootNamespace>
<AssemblyName>AmalgamationTool</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="DynamORM.Amalgamation.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.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>

File diff suppressed because it is too large Load Diff

131
AmalgamationTool/Program.cs Normal file
View File

@@ -0,0 +1,131 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace AmalgamationTool
{
internal class Program
{
private static void Main(string[] args)
{
List<string> usings = new List<string>();
Dictionary<string, List<string>> classes = new Dictionary<string, List<string>>();
// Build a file using string builder.
StringBuilder sb = new StringBuilder();
foreach (var f in new DirectoryInfo(Path.GetFullPath(args[0].Trim('"', '\''))).GetFiles("*.cs", SearchOption.AllDirectories))
{
string content = File.ReadAllText(f.FullName);
string namespaceName = string.Empty;
// Deal with usings
foreach (var u in content.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)
.Where(l => l.TrimEnd().StartsWith("using "))
.Select(l => l.Trim()))
if (!usings.Contains(u))
usings.Add(u);
// Extract namespace
var nstart = content.IndexOf("namespace ") + "namespace ".Length;
var bbrace = content.IndexOf("{", nstart);
var nlen = bbrace - nstart;
if (nstart < "namespace ".Length)
{
if (f.Name.ToLower() == "assemblyinfo.cs")
{
var hs = content.IndexOf("/*");
var es = content.IndexOf("*/", hs) + 2;
if (es > hs)
{
sb.AppendLine(content.Substring(hs, es - hs));
sb.AppendLine();
}
}
continue;
}
string ns = content.Substring(nstart, nlen).Trim();
// Add namespace if not exist
if (!classes.ContainsKey(ns))
classes.Add(ns, new List<string>());
var ebrace = content.LastIndexOf('}');
// Cut content as class/enum
classes[ns].Add(content.Substring(bbrace + 1, ebrace - bbrace - 1));
}
usings.Sort();
foreach (var u in usings)
sb.AppendLine(u);
sb.AppendLine(@"
[module: System.Diagnostics.CodeAnalysis.SuppressMessage(""StyleCop.CSharp.MaintainabilityRules"", ""SA1402:FileMayOnlyContainASingleClass"", Justification = ""This is a generated file which generates all the necessary support classes."")]
[module: System.Diagnostics.CodeAnalysis.SuppressMessage(""StyleCop.CSharp.MaintainabilityRules"", ""SA1403:FileMayOnlyContainASingleNamespace"", Justification = ""This is a generated file which generates all the necessary support classes."")]");
FillClassesAndNamespacesIddented(classes, sb);
File.WriteAllText(Path.GetFullPath(args[1].Trim('"', '\'')), sb.ToString());
}
private static void FillClassesAndNamespaces(Dictionary<string, List<string>> classes, StringBuilder sb)
{
foreach (var n in classes)
{
sb.AppendFormat("namespace {0}{1}{{", n.Key, Environment.NewLine);
n.Value.ForEach(c => sb.Append(c));
sb.AppendLine("}");
sb.AppendLine(string.Empty);
}
}
private static void FillClassesAndNamespacesIddented(Dictionary<string, List<string>> classes, StringBuilder sb)
{
foreach (var n in classes.Where(nc => nc.Key.Split('.').Count() == 1))
{
sb.AppendFormat("namespace {0}{1}{{", n.Key, Environment.NewLine);
n.Value.ForEach(c => sb.Append(c));
SubNamespaces(classes, n.Key, sb, 1);
sb.AppendLine("}");
sb.AppendLine(string.Empty);
}
}
private static void SubNamespaces(Dictionary<string, List<string>> classes, string p, StringBuilder sb, int ident)
{
sb.AppendLine(string.Empty);
foreach (var n in classes.Where(nc => nc.Key.Split('.').Count() == ident + 1 && nc.Key.StartsWith(p)))
{
for (int i = 0; i < ident; i++) sb.Append(" ");
sb.AppendFormat("namespace {0}{1}", n.Key.Substring(p.Length + 1), Environment.NewLine);
for (int i = 0; i < ident; i++) sb.Append(" ");
sb.Append("{");
n.Value.ForEach(c =>
{
foreach (var l in c.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
{
for (int i = 0; i < ident; i++) sb.Append(" ");
sb.AppendLine(l);
}
});
SubNamespaces(classes, n.Key, sb, ident + 1);
for (int i = 0; i < ident; i++) sb.Append(" ");
sb.AppendLine("}");
sb.AppendLine(string.Empty);
}
}
}
}

View File

@@ -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("AmalgamationTool")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("AmalgamationTool")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
[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("de540809-dd27-47b1-bb01-7dce3a880cde")]
// 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")]