diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-31 04:08:37 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-31 04:08:37 +0300 |
| commit | 1f63d0fcaf1ec52c6fb8785fe501f205359dc87a (patch) | |
| tree | 2027fdbaae7f0820fbb04e7d64ecbb6fbf357c93 /Software | |
| parent | 20a91b86be7f83036d763bc7e3f193ca2844f59b (diff) | |
| download | Tango-1f63d0fcaf1ec52c6fb8785fe501f205359dc87a.tar.gz Tango-1f63d0fcaf1ec52c6fb8785fe501f205359dc87a.zip | |
Improved ports list generator.
Diffstat (limited to 'Software')
| -rw-r--r-- | Software/Visual_Studio/Resources/Tech IOs/Tech IOs v1.xlsx | bin | 0 -> 36265 bytes | |||
| -rw-r--r-- | Software/Visual_Studio/Resources/Tech IOs/Tech IOs v2.xlsx | bin | 0 -> 35936 bytes | |||
| -rw-r--r-- | Software/Visual_Studio/Tango.sln | 1 | ||||
| -rw-r--r-- | Software/Visual_Studio/Utilities/Tango.PortsListGenerator/Program.cs | 153 | ||||
| -rw-r--r-- | Software/Visual_Studio/Utilities/Tango.PortsListGenerator/Tango.PortsListGenerator.csproj | 10 |
5 files changed, 142 insertions, 22 deletions
diff --git a/Software/Visual_Studio/Resources/Tech IOs/Tech IOs v1.xlsx b/Software/Visual_Studio/Resources/Tech IOs/Tech IOs v1.xlsx Binary files differnew file mode 100644 index 000000000..805466696 --- /dev/null +++ b/Software/Visual_Studio/Resources/Tech IOs/Tech IOs v1.xlsx diff --git a/Software/Visual_Studio/Resources/Tech IOs/Tech IOs v2.xlsx b/Software/Visual_Studio/Resources/Tech IOs/Tech IOs v2.xlsx Binary files differnew file mode 100644 index 000000000..ecbca9f73 --- /dev/null +++ b/Software/Visual_Studio/Resources/Tech IOs/Tech IOs v2.xlsx diff --git a/Software/Visual_Studio/Tango.sln b/Software/Visual_Studio/Tango.sln index 2124bf09e..4b528131b 100644 --- a/Software/Visual_Studio/Tango.sln +++ b/Software/Visual_Studio/Tango.sln @@ -1538,6 +1538,7 @@ Global {1674F726-0E66-414F-B9FD-C6F20D7F07C7}.Release|x86.ActiveCfg = Release|Any CPU {1674F726-0E66-414F-B9FD-C6F20D7F07C7}.Release|x86.Build.0 = Release|Any CPU {12CC222B-D0F5-4048-B790-D283235F540D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {12CC222B-D0F5-4048-B790-D283235F540D}.Debug|Any CPU.Build.0 = Debug|Any CPU {12CC222B-D0F5-4048-B790-D283235F540D}.Debug|ARM.ActiveCfg = Debug|Any CPU {12CC222B-D0F5-4048-B790-D283235F540D}.Debug|ARM.Build.0 = Debug|Any CPU {12CC222B-D0F5-4048-B790-D283235F540D}.Debug|ARM64.ActiveCfg = Debug|Any CPU diff --git a/Software/Visual_Studio/Utilities/Tango.PortsListGenerator/Program.cs b/Software/Visual_Studio/Utilities/Tango.PortsListGenerator/Program.cs index 62dccc4ce..67096c49a 100644 --- a/Software/Visual_Studio/Utilities/Tango.PortsListGenerator/Program.cs +++ b/Software/Visual_Studio/Utilities/Tango.PortsListGenerator/Program.cs @@ -32,9 +32,9 @@ namespace Tango.PortsListGenerator static void Main(string[] args) { - Console.WriteLine("Generating Ports List..."); + Console.WriteLine("Initializing Ports List..."); - ExcelReader reader = new ExcelReader(PathHelper.GetStartupPath() + "\\PortsList.xlsx"); + ExcelReader reader = new ExcelReader(PathHelper.GetStartupPath() + "\\Tech IOs v2.xlsx"); var results = reader.GetDataByIndex<PortItem>("Ports List", 2); results.RemoveAll(x => String.IsNullOrWhiteSpace(x.ToString().Replace(",", ""))); @@ -65,32 +65,143 @@ namespace Tango.PortsListGenerator return; } - Console.WriteLine("Emptying TECH_IOS table..."); using (ObservablesContext db = ObservablesContext.CreateDefault()) { - db.Database.ExecuteSqlCommand("DELETE FROM TECH_IOS"); - } + var toUpdateAdd = results.Where(x => !String.IsNullOrWhiteSpace(x.InterfaceName)).ToList(); - int code = 0; + List<PortItem> toUpdate = new List<PortItem>(); + List<PortItem> toUpdateDb = new List<PortItem>(); + List<PortItem> toAdd = new List<PortItem>(); + List<PortItem> identical = new List<PortItem>(); - using (ObservablesContext db = ObservablesContext.CreateDefault()) - { - foreach (var item in results.Where(x => !String.IsNullOrWhiteSpace(x.InterfaceName))) + foreach (var item in toUpdateAdd) { - Console.WriteLine("Adding " + item.ToString()); + var existingIO = db.TechIos.SingleOrDefault(x => x.InterfaceName == item.InterfaceName); - db.TechIos.Add(new BL.Entities.TechIo() + if (existingIO != null) { - Code = code++, - Name = item.InterfaceName, - Designator = item.Designator, - Asm = item.Asm, - InterfaceName = item.InterfaceName, - Sensor = item.Sensor, - Type = (int)TypeNameToIOType(item.Type), - Averaging = (int)StringToNumber(item.Averaging), - InitValue = StringToNumber(item.InitValue), - }); + bool shouldUpdate = + existingIO.Name != item.InterfaceName + || + existingIO.Designator != item.Designator + || + existingIO.Asm != item.Asm + || + existingIO.InterfaceName != item.InterfaceName + || + existingIO.Sensor != item.Sensor + || + existingIO.Type != (int)TypeNameToIOType(item.Type) + || + existingIO.Averaging != (int)StringToNumber(item.Averaging) + || + existingIO.InitValue != StringToNumber(item.InitValue); + + if (shouldUpdate) + { + toUpdate.Add(item); + + toUpdateDb.Add(new PortItem() + { + Id = existingIO.ID.ToString(), + Asm = existingIO.Asm, + Designator = existingIO.Designator, + Averaging = existingIO.Averaging.ToString(), + InitValue = existingIO.InitValue.ToString(), + InterfaceName = existingIO.InterfaceName, + Sensor = existingIO.Sensor, + Type = ((IOType)existingIO.Type).ToString() + }); + } + else + { + identical.Add(item); + } + } + else + { + toAdd.Add(item); + } + } + + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine($"IDENTICAL ({identical.Count}) ---------------------------------------------------------"); + Console.WriteLine(); + + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine($"ITEMS TO ADD ({toAdd.Count}) ---------------------------------------------------------"); + Console.WriteLine(); + + foreach (var item in toAdd) + { + Console.WriteLine(item.ToString()); + } + + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine($"ITEMS TO UPDATE ({toUpdate.Count}) ---------------------------------------------------------"); + Console.WriteLine(); + + for (int i = 0; i < toUpdate.Count; i++) + { + Console.WriteLine($"ID: {toUpdateDb[i].Id}: {toUpdateDb[i].ToString()} => {toUpdate[i].ToString()}"); + } + + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine("Press 'Y' to perform the operation..."); + + var key = Console.ReadKey(); + + if (key.Key != ConsoleKey.Y) + { + Environment.Exit(0); + return; + } + + Console.WriteLine("Starting procedure..."); + + int code = 0; + + if (db.TechIos.Count() > 0) + { + code = db.TechIos.Max(x => x.Code) + 1; + } + + foreach (var item in toUpdateAdd) + { + var existingIO = db.TechIos.SingleOrDefault(x => x.InterfaceName == item.InterfaceName); + + if (existingIO != null) + { + Console.WriteLine("Updating " + item.ToString()); + existingIO.Name = item.InterfaceName; + existingIO.Designator = item.Designator; + existingIO.Asm = item.Asm; + existingIO.InterfaceName = item.InterfaceName; + existingIO.Sensor = item.Sensor; + existingIO.Type = (int)TypeNameToIOType(item.Type); + existingIO.Averaging = (int)StringToNumber(item.Averaging); + existingIO.InitValue = StringToNumber(item.InitValue); + } + else + { + Console.WriteLine("Adding " + item.ToString()); + db.TechIos.Add(new BL.Entities.TechIo() + { + Code = code++, + Name = item.InterfaceName, + Designator = item.Designator, + Asm = item.Asm, + InterfaceName = item.InterfaceName, + Sensor = item.Sensor, + Type = (int)TypeNameToIOType(item.Type), + Averaging = (int)StringToNumber(item.Averaging), + InitValue = StringToNumber(item.InitValue), + }); + } } Console.WriteLine("Saving changes to db..."); diff --git a/Software/Visual_Studio/Utilities/Tango.PortsListGenerator/Tango.PortsListGenerator.csproj b/Software/Visual_Studio/Utilities/Tango.PortsListGenerator/Tango.PortsListGenerator.csproj index b89ae91ce..4e7f11359 100644 --- a/Software/Visual_Studio/Utilities/Tango.PortsListGenerator/Tango.PortsListGenerator.csproj +++ b/Software/Visual_Studio/Utilities/Tango.PortsListGenerator/Tango.PortsListGenerator.csproj @@ -60,6 +60,14 @@ <Link>PortsList.xlsx</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> + <None Include="..\..\Resources\Tech IOs\Tech IOs v1.xlsx"> + <Link>Tech IOs v1.xlsx</Link> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Include="..\..\Resources\Tech IOs\Tech IOs v2.xlsx"> + <Link>Tech IOs v2.xlsx</Link> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> <None Include="App.config" /> <None Include="packages.config" /> </ItemGroup> @@ -80,7 +88,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file |
