Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Gravity/Gravity.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.Build.targets = Directory.Build.targets
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Model Generation Tool", "Model Generation Tool", "{3C2F531F-8DB7-42EB-BD1A-8845D297DAC6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModelGenerationTool", "Model Generation Tool\ModelGenerationTool\ModelGenerationTool.csproj", "{6CFC0187-3447-4D9C-A931-FA6500B05EB2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModelGeneration.Tests", "Model Generation Tool\ModelGeneration.Tests\ModelGeneration.Tests.csproj", "{07463FBC-A94F-4B8A-8A1F-341812386CCB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -40,10 +46,22 @@ Global
{C0882E20-283A-4CAC-A53C-3512A71127DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0882E20-283A-4CAC-A53C-3512A71127DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0882E20-283A-4CAC-A53C-3512A71127DF}.Release|Any CPU.Build.0 = Release|Any CPU
{6CFC0187-3447-4D9C-A931-FA6500B05EB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CFC0187-3447-4D9C-A931-FA6500B05EB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CFC0187-3447-4D9C-A931-FA6500B05EB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CFC0187-3447-4D9C-A931-FA6500B05EB2}.Release|Any CPU.Build.0 = Release|Any CPU
{07463FBC-A94F-4B8A-8A1F-341812386CCB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07463FBC-A94F-4B8A-8A1F-341812386CCB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07463FBC-A94F-4B8A-8A1F-341812386CCB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07463FBC-A94F-4B8A-8A1F-341812386CCB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{6CFC0187-3447-4D9C-A931-FA6500B05EB2} = {3C2F531F-8DB7-42EB-BD1A-8845D297DAC6}
{07463FBC-A94F-4B8A-8A1F-341812386CCB} = {3C2F531F-8DB7-42EB-BD1A-8845D297DAC6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {02DBD25B-BBE4-4F36-9E32-31682E297EC9}
EndGlobalSection
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ModelGenerationTool.Factories.External;

namespace ModelGeneration.Tests
{
[TestClass]
public class GravityModelGenerationTests
{
GravityModelGenerationFactory _gravityModelGenFactory;

string _rapXmlSchemaLocation = "";
string _modelsOutputPath = "";

[TestInitialize]
public void Initialize()
{
_gravityModelGenFactory = new GravityModelGenerationFactory(_rapXmlSchemaLocation);
}

[TestMethod]
public void GenerateGravityModels()
{
_gravityModelGenFactory.GenerateGravityModels(_modelsOutputPath);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{07463FBC-A94F-4B8A-8A1F-341812386CCB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ModelGeneration.Tests</RootNamespace>
<AssemblyName>ModelGeneration.Tests</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="GravityModelGenerationTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ModelGenerationTool\ModelGenerationTool.csproj">
<Project>{6CFC0187-3447-4D9C-A931-FA6500B05EB2}</Project>
<Name>ModelGenerationTool</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("ModelGeneration.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ModelGeneration.Tests")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: ComVisible(false)]

[assembly: Guid("07463fbc-a94f-4b8a-8a1f-341812386ccb")]

// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net462" />
<package id="MSTest.TestFramework" version="1.3.2" targetFramework="net462" />
</packages>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace ModelGenerationTool.Attributes
{
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
internal class XmlNodeKeyAttribute : Attribute
{
internal XmlNodeKeyAttribute(string xmlNodeKey)
{
XmlNodeKey = xmlNodeKey;
}

internal XmlNodeKeyAttribute(string xmlNodeKey, string customData)
{
XmlNodeKey = xmlNodeKey;
CustomData = customData;
}

internal string XmlNodeKey { get; set; }

internal string CustomData { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace ModelGenerationTool.Attributes
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
internal class XmlNodePathAttribute : Attribute
{
internal XmlNodePathAttribute(string xmlNodePath)
{
XmlNodePath = xmlNodePath;
}

internal XmlNodePathAttribute(string xmlNodePath, string customData)
{
XmlNodePath = xmlNodePath;
CustomData = customData;
}

internal string XmlNodePath { get; set; }

internal string CustomData { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Text;

namespace ModelGenerationTool.Extensions
{
internal static class StringExtensions
{
internal static string ToDotNetNameFormat(this string input)
{
StringBuilder resultBuilder = new StringBuilder(input.Length);
char[] inputAsChars = input.ToCharArray();

for (int i = 0; i < input.Length; i++)
{
if ((char.IsDigit(inputAsChars[i]) && resultBuilder.Length > 0)
|| char.IsLetter(inputAsChars[i]))
{
resultBuilder.Append(inputAsChars[i]);
}
}

return resultBuilder.ToString();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Linq;
using System.Reflection;

namespace ModelGenerationTool.Extensions
{
internal static class TypeExtensions
{
internal static A GetPropertyAttribute<A>(this Type type, string propertyName)
where A : Attribute => type.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).First(p => p.Name == propertyName).GetCustomAttribute<A>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Xml;

namespace ModelGenerationTool.Factories.Base
{
public abstract class XmlFactoryBase
{
protected XmlDocument xmlDocument;

protected XmlFactoryBase(XmlDocument xmlDocument)
{
this.xmlDocument = xmlDocument;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using ModelGenerationTool.Factories.Base;
using ModelGenerationTool.Factories.Internal;
using ModelGenerationTool.Models.File;
using ModelGenerationTool.Models.GravityRdo;
using ModelGenerationTool.Models.NET;
using System.Collections.Generic;
using System.Linq;
using System.Xml;

namespace ModelGenerationTool.Factories.External
{
public class GravityModelGenerationFactory : XmlFactoryBase
{
public GravityModelGenerationFactory(XmlDocument xmlDocument)
: base(xmlDocument) { }

public GravityModelGenerationFactory(string xmlDocumentLocation)
: base(new XmlDocument()) => xmlDocument.Load(xmlDocumentLocation);

public void GenerateGravityModels(string outputPath)
{
// 1. Load xmlDocument by Path
GravityRdoFactory rdoFactory = new GravityRdoFactory(xmlDocument);

// 2. Read in Platform specific Models
var rdoModels = rdoFactory.GenerateRdoModelsForXml();

// 3. ConvertToDotNet with NetProperties
var rdoModelsAsDotNet = ConvertRdoModelsToDotNet(rdoModels);

NetModelGenerationFactory netFactory = new NetModelGenerationFactory();

foreach (var netModel in rdoModelsAsDotNet)
{
// 4. Convert NetModel with NetProperties to CSharpFile
var csFile = netFactory.GenerateCSharpFileFromModel(netModel);

// 5. Store file in specified output path
csFile.Save(outputPath);
}
}

public List<CSharpFile> GenerateGravityModelFiles()
{
List<CSharpFile> resultList = new List<CSharpFile>();

// 1. Load xmlDocument by Path
GravityRdoFactory rdoFactory = new GravityRdoFactory(xmlDocument);

// 2. Read in Platform specific Models
var rdoModels = rdoFactory.GenerateRdoModelsForXml();

// 3. ConvertToDotNet with NetProperties
var rdoModelsAsDotNet = ConvertRdoModelsToDotNet(rdoModels);

NetModelGenerationFactory netFactory = new NetModelGenerationFactory();

foreach (var netModel in rdoModelsAsDotNet)
{
// 4. Convert NetModel with NetProperties to CSharpFile
resultList.Add(netFactory.GenerateCSharpFileFromModel(netModel));
}

return resultList;
}

// TODO: This should be moved out from factory..
private static List<NetModel> ConvertRdoModelsToDotNet(List<GravityModel> rdoModels)
{
List<NetModel> returnList = new List<NetModel>();

foreach (var rdoModel in rdoModels)
{
foreach (var choice in rdoModel.GravityChoices)
{
if (returnList.Select(x => x.Name).Contains(choice.Name) == false)
returnList.Add(choice.ConvertToDotNet());
}

returnList.Add(rdoModel.ConvertToDotNet());
}

return returnList;
}
}
}
Loading