diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-27 19:04:50 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-27 19:04:50 +0200 |
| commit | 687910bc052e1430c8132a5eefe63e20ba6937e0 (patch) | |
| tree | 0ec042a8a5cad0615a82d1e10862a904efe79762 /Software/Visual_Studio/Utilities/Tango.PMRGenerator.CLI | |
| parent | f1a77b05c2e56cd073180803947aa991a09f9b40 (diff) | |
| download | Tango-687910bc052e1430c8132a5eefe63e20ba6937e0.tar.gz Tango-687910bc052e1430c8132a5eefe63e20ba6937e0.zip | |
Implemented PMR Generator for hardware objects !
Diffstat (limited to 'Software/Visual_Studio/Utilities/Tango.PMRGenerator.CLI')
5 files changed, 283 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.PMRGenerator.CLI/App.config b/Software/Visual_Studio/Utilities/Tango.PMRGenerator.CLI/App.config new file mode 100644 index 000000000..92aa00bf9 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.PMRGenerator.CLI/App.config @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <configSections> + <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> + <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> + </configSections> + <startup> + <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /> + </startup> + <entityFramework> + <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> + <providers> + <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> + </providers> + </entityFramework> +</configuration>
\ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.PMRGenerator.CLI/Program.cs b/Software/Visual_Studio/Utilities/Tango.PMRGenerator.CLI/Program.cs new file mode 100644 index 000000000..cbda9849e --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.PMRGenerator.CLI/Program.cs @@ -0,0 +1,180 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using Tango.CodeGeneration; +using Tango.Integration.Observables; + +namespace Tango.PMRGenerator.CLI +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Generating PMR's..."); + Console.WriteLine(); + + Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); + String pmrFolder = "..\\..\\..\\PMR\\Messages"; + + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + db.Configuration.LazyLoadingEnabled = false; + GenerateHardwareMotors(db, pmrFolder); + GenerateHardwareDancers(db, pmrFolder); + GenerateHardwarePidControls(db, pmrFolder); + GenerateHardwareDispensers(db, pmrFolder); + } + + Console.WriteLine("Done"); + } + + private static void GenerateHardwareMotors(ObservablesContext db, String pmrFolder) + { + Console.WriteLine("Generating Hardware Motor Types..."); + + ProtoEnumFile enumFile = new ProtoEnumFile(); + enumFile.Name = "HardwareMotorType"; + enumFile.Package = "Tango.PMR.Hardware"; + + foreach (var field in db.HardwareMotorTypes.ToList().OrderBy(x => x.Code)) + { + enumFile.Fields.Add(new EnumerationField() + { + Name = field.Name.Replace(" ", ""), + Value = field.Code, + }); + } + + Console.WriteLine("Generating Hardware Motor..."); + ProtoMessageFile messageFile = new ProtoMessageFile(); + messageFile.Name = "HardwareMotor"; + messageFile.Package = "Tango.PMR.Hardware"; + messageFile.Imports.Add("HardwareMotorType.proto"); + + messageFile.Properties.Add(new Property("HardwareMotorType", "HardwareMotorType")); + + foreach (var prop in typeof(HardwareMotor).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).Where(x => x.PropertyType.IsPrimitive)) + { + messageFile.Properties.Add(new Property(prop.Name, CoercePropertyType(prop.PropertyType))); + } + + String enumString = enumFile.GenerateCode(); + String messageString = messageFile.GenerateCode(); + + File.WriteAllText(Path.Combine(pmrFolder, "Hardware", enumFile.Name + ".proto"), enumString); + File.WriteAllText(Path.Combine(pmrFolder, "Hardware", messageFile.Name + ".proto"), messageString); + } + + private static void GenerateHardwareDancers(ObservablesContext db, String pmrFolder) + { + Console.WriteLine("Generating Hardware Dancer Types..."); + + ProtoEnumFile enumFile = new ProtoEnumFile(); + enumFile.Name = "HardwareDancerType"; + enumFile.Package = "Tango.PMR.Hardware"; + + foreach (var field in db.HardwareDancerTypes.ToList().OrderBy(x => x.Code)) + { + enumFile.Fields.Add(new EnumerationField() + { + Name = field.Name.Replace(" ", ""), + Value = field.Code, + }); + } + + Console.WriteLine("Generating Hardware Dancer..."); + + ProtoMessageFile messageFile = new ProtoMessageFile(); + messageFile.Name = "HardwareDancer"; + messageFile.Package = "Tango.PMR.Hardware"; + messageFile.Imports.Add("HardwareDancerType.proto"); + + messageFile.Properties.Add(new Property("HardwareDancerType", "HardwareDancerType")); + + foreach (var prop in typeof(HardwareDancer).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).Where(x => x.PropertyType.IsPrimitive)) + { + messageFile.Properties.Add(new Property(prop.Name, CoercePropertyType(prop.PropertyType))); + } + + String enumString = enumFile.GenerateCode(); + String messageString = messageFile.GenerateCode(); + + File.WriteAllText(Path.Combine(pmrFolder, "Hardware", enumFile.Name + ".proto"), enumString); + File.WriteAllText(Path.Combine(pmrFolder, "Hardware", messageFile.Name + ".proto"), messageString); + } + + private static void GenerateHardwarePidControls(ObservablesContext db, String pmrFolder) + { + Console.WriteLine("Generating Hardware PID Control Types..."); + + ProtoEnumFile enumFile = new ProtoEnumFile(); + enumFile.Name = "HardwarePidControlType"; + enumFile.Package = "Tango.PMR.Hardware"; + + foreach (var field in db.HardwarePidControlTypes.ToList().OrderBy(x => x.Code)) + { + enumFile.Fields.Add(new EnumerationField() + { + Name = field.Name.Replace(" ", ""), + Value = field.Code, + }); + } + + Console.WriteLine("Generating Hardware PID Control..."); + + ProtoMessageFile messageFile = new ProtoMessageFile(); + messageFile.Name = "HardwarePidControl"; + messageFile.Package = "Tango.PMR.Hardware"; + messageFile.Imports.Add("HardwarePidControlType.proto"); + + messageFile.Properties.Add(new Property("HardwarePidControlType", "HardwarePidControlType")); + + foreach (var prop in typeof(HardwarePidControl).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).Where(x => x.PropertyType.IsPrimitive)) + { + messageFile.Properties.Add(new Property(prop.Name, CoercePropertyType(prop.PropertyType))); + } + + String enumString = enumFile.GenerateCode(); + String messageString = messageFile.GenerateCode(); + + File.WriteAllText(Path.Combine(pmrFolder, "Hardware", enumFile.Name + ".proto"), enumString); + File.WriteAllText(Path.Combine(pmrFolder, "Hardware", messageFile.Name + ".proto"), messageString); + } + + private static void GenerateHardwareDispensers(ObservablesContext db, String pmrFolder) + { + Console.WriteLine("Generating Dispenser Control..."); + + ProtoMessageFile messageFile = new ProtoMessageFile(); + messageFile.Name = "HardwareDispenser"; + messageFile.Package = "Tango.PMR.Hardware"; + + messageFile.Properties.Add(new Property("Code", "int32")); + + foreach (var prop in typeof(HardwarePidControl).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).Where(x => x.PropertyType.IsPrimitive)) + { + messageFile.Properties.Add(new Property(prop.Name, CoercePropertyType(prop.PropertyType))); + } + + String messageString = messageFile.GenerateCode(); + + File.WriteAllText(Path.Combine(pmrFolder, "Hardware", messageFile.Name + ".proto"), messageString); + } + + private static String CoercePropertyType(Type type) + { + if (type == typeof(bool)) + { + return "bool"; + } + else + { + return type.Name.ToLower(); + } + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.PMRGenerator.CLI/Properties/AssemblyInfo.cs b/Software/Visual_Studio/Utilities/Tango.PMRGenerator.CLI/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..349d5d4a4 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.PMRGenerator.CLI/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Tango - PMR Generator")] +[assembly: ComVisible(false)]
\ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.PMRGenerator.CLI/Tango.PMRGenerator.CLI.csproj b/Software/Visual_Studio/Utilities/Tango.PMRGenerator.CLI/Tango.PMRGenerator.CLI.csproj new file mode 100644 index 000000000..813f80cb4 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.PMRGenerator.CLI/Tango.PMRGenerator.CLI.csproj @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <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>{5AFD5B7D-757A-400C-B0C9-118834F5D67E}</ProjectGuid> + <OutputType>Exe</OutputType> + <RootNamespace>Tango.PMRGenerator.CLI</RootNamespace> + <AssemblyName>Tango.PMRGenerator.CLI</AssemblyName> + <TargetFrameworkVersion>v4.6</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>..\..\Build\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> + <HintPath>..\..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.dll</HintPath> + </Reference> + <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> + <HintPath>..\..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.SqlServer.dll</HintPath> + </Reference> + <Reference Include="System" /> + <Reference Include="System.ComponentModel.DataAnnotations" /> + <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.Net.Http" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="..\..\Versioning\GlobalVersionInfo.cs"> + <Link>GlobalVersionInfo.cs</Link> + </Compile> + <Compile Include="Program.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="App.config" /> + <None Include="packages.config" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\Tango.CodeGeneration\Tango.CodeGeneration.csproj"> + <Project>{caedae94-11ed-473c-888a-268a6d38cd20}</Project> + <Name>Tango.CodeGeneration</Name> + </ProjectReference> + <ProjectReference Include="..\..\Tango.Core\Tango.Core.csproj"> + <Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project> + <Name>Tango.Core</Name> + </ProjectReference> + <ProjectReference Include="..\..\Tango.Integration\Tango.Integration.csproj"> + <Project>{4206ac58-3b57-4699-8835-90bf6db01a61}</Project> + <Name>Tango.Integration</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> +</Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.PMRGenerator.CLI/packages.config b/Software/Visual_Studio/Utilities/Tango.PMRGenerator.CLI/packages.config new file mode 100644 index 000000000..9256e1591 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.PMRGenerator.CLI/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="EntityFramework" version="6.0.0" targetFramework="net46" /> +</packages>
\ No newline at end of file |
