From 1f63d0fcaf1ec52c6fb8785fe501f205359dc87a Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 31 Aug 2020 04:08:37 +0300 Subject: Improved ports list generator. --- .../Resources/Tech IOs/Tech IOs v1.xlsx | Bin 0 -> 36265 bytes .../Resources/Tech IOs/Tech IOs v2.xlsx | Bin 0 -> 35936 bytes Software/Visual_Studio/Tango.sln | 1 + .../Utilities/Tango.PortsListGenerator/Program.cs | 153 ++++++++++++++++++--- .../Tango.PortsListGenerator.csproj | 10 +- 5 files changed, 142 insertions(+), 22 deletions(-) create mode 100644 Software/Visual_Studio/Resources/Tech IOs/Tech IOs v1.xlsx create mode 100644 Software/Visual_Studio/Resources/Tech IOs/Tech IOs v2.xlsx (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/Resources/Tech IOs/Tech IOs v1.xlsx b/Software/Visual_Studio/Resources/Tech IOs/Tech IOs v1.xlsx new file mode 100644 index 000000000..805466696 Binary files /dev/null and b/Software/Visual_Studio/Resources/Tech IOs/Tech IOs v1.xlsx differ diff --git a/Software/Visual_Studio/Resources/Tech IOs/Tech IOs v2.xlsx b/Software/Visual_Studio/Resources/Tech IOs/Tech IOs v2.xlsx new file mode 100644 index 000000000..ecbca9f73 Binary files /dev/null and b/Software/Visual_Studio/Resources/Tech IOs/Tech IOs v2.xlsx differ 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("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 toUpdate = new List(); + List toUpdateDb = new List(); + List toAdd = new List(); + List identical = new List(); - 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 @@ PortsList.xlsx PreserveNewest + + Tech IOs v1.xlsx + PreserveNewest + + + Tech IOs v2.xlsx + PreserveNewest + @@ -80,7 +88,7 @@ - + \ No newline at end of file -- cgit v1.3.1