From b8356cb31863d329388d5e76b9311e9215cae3bb Mon Sep 17 00:00:00 2001 From: Tilman Reinhardt Date: Mon, 9 Jan 2023 18:54:13 +0100 Subject: [PATCH 1/7] tmp --- .../Components/1_Properties/CreateProfile.cs | 35 +++--- .../1_Properties/GetSectionDimensions.cs | 2 +- .../Components/2_Geometry/SectionAlignment.cs | 2 +- GsaGH/GsaGHInfo.cs | 11 +- GsaGH/Helpers/GsaAPI/SqlReader.cs | 115 ++++++++++++++++-- 5 files changed, 134 insertions(+), 31 deletions(-) diff --git a/GsaGH/Components/1_Properties/CreateProfile.cs b/GsaGH/Components/1_Properties/CreateProfile.cs index 3445f1ca7..6abc17cce 100644 --- a/GsaGH/Components/1_Properties/CreateProfile.cs +++ b/GsaGH/Components/1_Properties/CreateProfile.cs @@ -3,11 +3,12 @@ using System.Globalization; using System.IO; using System.Linq; +using System.Reflection; using System.Text.RegularExpressions; +using System.Threading; using Grasshopper.Kernel; using Grasshopper.Kernel.Parameters; using Grasshopper.Kernel.Types; -using GsaGH.Helpers; using GsaGH.Helpers.GH; using GsaGH.Helpers.GsaAPI; using OasysGH; @@ -21,10 +22,10 @@ namespace GsaGH.Components { - /// - /// Component to create AdSec profile - /// - public class CreateProfile : GH_OasysDropDownComponent + /// + /// Component to create AdSec profile + /// + public class CreateProfile : GH_OasysDropDownComponent { #region Name and Ribbon Layout // This region handles how the component in displayed on the ribbon including name, exposure level and icon @@ -33,6 +34,7 @@ public class CreateProfile : GH_OasysDropDownComponent public override OasysPluginInfo PluginInfo => GsaGH.PluginInfo.Instance; protected override System.Drawing.Bitmap Icon => Properties.Resources.CreateProfile; + public CreateProfile() : base("Create Profile", "Profile", "Create Profile text-string for a GSA Section", CategoryName.Name(), @@ -882,19 +884,19 @@ private void Mode2Clicked() // for catalogue selection // Catalogues - private readonly Tuple, List> _cataloguedata = SqlReader.GetCataloguesDataFromSQLite(Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3")); + private readonly Tuple, List> _cataloguedata = SqlReader.reader.GetCataloguesDataFromSQLite(Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3")); private List _catalogueNumbers = new List(); // internal db catalogue numbers private List _catalogueNames = new List(); // list of displayed catalogues bool _inclSS; // Types - private Tuple, List> _typedata = SqlReader.GetTypesDataFromSQLite(-1, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), false); + private Tuple, List> _typedata = SqlReader.reader.GetTypesDataFromSQLite(-1, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), false); private List _typeNumbers = new List(); // internal db type numbers private List _typeNames = new List(); // list of displayed types // Sections // list of displayed sections - private List _sectionList = SqlReader.GetSectionsDataFromSQLite(new List { -1 }, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), false); + private List _sectionList = SqlReader.reader.GetSectionsDataFromSQLite(new List { -1 }, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), false); private List _filteredlist = new List(); int _catalogueIndex = -1; //-1 is all int _typeIndex = -1; @@ -961,12 +963,12 @@ public override void SetSelected(int i, int j) // set types to all _typeIndex = -1; // update typelist with all catalogues - _typedata = SqlReader.GetTypesDataFromSQLite(_catalogueIndex, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); + _typedata = this.GetTypesDataFromSQLite(_catalogueIndex, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); _typeNames = _typedata.Item1; _typeNumbers = _typedata.Item2; // update section list to all types - _sectionList = SqlReader.GetSectionsDataFromSQLite(_typeNumbers, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); + _sectionList = SqlReader.reader.GetSectionsDataFromSQLite(_typeNumbers, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); // filter by search pattern _filteredlist = new List(); @@ -1022,14 +1024,14 @@ public override void SetSelected(int i, int j) SelectedItems[1] = _catalogueNames[j]; // update typelist with selected input catalogue - _typedata = SqlReader.GetTypesDataFromSQLite(_catalogueIndex, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); + _typedata = SqlReader.reader.GetTypesDataFromSQLite(_catalogueIndex, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); _typeNames = _typedata.Item1; _typeNumbers = _typedata.Item2; // update section list from new types (all new types in catalogue) List types = _typeNumbers.ToList(); types.RemoveAt(0); // remove -1 from beginning of list - _sectionList = SqlReader.GetSectionsDataFromSQLite(types, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); + _sectionList = SqlReader.reader.GetSectionsDataFromSQLite(types, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); // filter by search pattern _filteredlist = new List(); @@ -1087,7 +1089,7 @@ public override void SetSelected(int i, int j) // section list with selected types (only types in selected type) - _sectionList = SqlReader.GetSectionsDataFromSQLite(types, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); + _sectionList = SqlReader.reader.GetSectionsDataFromSQLite(types, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); // filter by search pattern _filteredlist = new List(); @@ -1168,6 +1170,11 @@ public override void SetSelected(int i, int j) } } + private Tuple, List> GetTypesDataFromSQLite(int catalogueIndex, string filePath, bool inclSuperseeded) + { + return SqlReader.reader.GetTypesDataFromSQLite2(catalogueIndex, filePath, inclSuperseeded); + } + public override void UpdateUIFromSelectedItems() { if (SelectedItems[0] == "Catalogue") @@ -1180,7 +1187,7 @@ public override void UpdateUIFromSelectedItems() _catalogueNames = _cataloguedata.Item1; _catalogueNumbers = _cataloguedata.Item2; - _typedata = SqlReader.GetTypesDataFromSQLite(_catalogueIndex, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); + _typedata = SqlReader.reader.GetTypesDataFromSQLite(_catalogueIndex, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); _typeNames = _typedata.Item1; _typeNumbers = _typedata.Item2; diff --git a/GsaGH/Components/1_Properties/GetSectionDimensions.cs b/GsaGH/Components/1_Properties/GetSectionDimensions.cs index e8b419f58..1e41fedbe 100644 --- a/GsaGH/Components/1_Properties/GetSectionDimensions.cs +++ b/GsaGH/Components/1_Properties/GetSectionDimensions.cs @@ -428,7 +428,7 @@ protected override void SolveInstance(IGH_DataAccess DA) else if (profile.StartsWith("CAT")) { string prof = profile.Split(' ')[2]; - List sqlValues = SqlReader.GetCatalogueProfileValues(prof, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3")); + List sqlValues = SqlReader.reader.GetCatalogueProfileValues(prof, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3")); unit = LengthUnit.Meter; DA.SetData(i++, new GH_UnitNumber(new Length(sqlValues[0], unit).ToUnit(this.LengthUnit))); //Depth diff --git a/GsaGH/Components/2_Geometry/SectionAlignment.cs b/GsaGH/Components/2_Geometry/SectionAlignment.cs index 07327ea32..8b7a20f76 100644 --- a/GsaGH/Components/2_Geometry/SectionAlignment.cs +++ b/GsaGH/Components/2_Geometry/SectionAlignment.cs @@ -348,7 +348,7 @@ protected override void SolveInstance(IGH_DataAccess DA) else if (profile.StartsWith("CAT")) { string prof = profile.Split(' ')[2]; - List sqlValues = SqlReader.GetCatalogueProfileValues(prof, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3")); + List sqlValues = SqlReader.reader.GetCatalogueProfileValues(prof, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3")); unit = LengthUnit.Meter; depth = new Length(sqlValues[0], unit); diff --git a/GsaGH/GsaGHInfo.cs b/GsaGH/GsaGHInfo.cs index d41a0fd68..6379e46f7 100644 --- a/GsaGH/GsaGHInfo.cs +++ b/GsaGH/GsaGHInfo.cs @@ -1,16 +1,11 @@ using System; -using System.IO; using System.Collections.ObjectModel; -using Grasshopper.Kernel; -using System.Reflection; -using System.Net; using System.Diagnostics; -using GsaGH.Helpers; -using System.Threading.Tasks; -using System.Windows.Forms; +using System.IO; +using System.Reflection; +using Grasshopper.Kernel; using OasysGH; using OasysGH.Helpers; -using System.Runtime.InteropServices; namespace GsaGH { diff --git a/GsaGH/Helpers/GsaAPI/SqlReader.cs b/GsaGH/Helpers/GsaAPI/SqlReader.cs index 82ffa2285..88d23c61e 100644 --- a/GsaGH/Helpers/GsaAPI/SqlReader.cs +++ b/GsaGH/Helpers/GsaAPI/SqlReader.cs @@ -1,23 +1,64 @@ using System; using System.Collections.Generic; -using System.Data.SQLite; using System.Data; +using System.Data.SQLite; using System.Globalization; +using System.IO; +using System.Reflection; +using System.Threading; namespace GsaGH.Helpers.GsaAPI { /// /// Class containing functions to interface with SQLite db files. /// - public class SqlReader + public class SqlReader : MarshalByRefObject { + public static SqlReader reader = Initialize(); + + public static SqlReader Initialize() + { + // Get the full name of the EXE assembly. + string exeAssembly = Assembly.GetCallingAssembly().FullName; + string codeBase = Assembly.GetCallingAssembly().CodeBase; + UriBuilder uri = new UriBuilder(codeBase); + string path = Uri.UnescapeDataString(uri.Path); + + // Construct and initialize settings for a second AppDomain. + AppDomainSetup ads = new AppDomainSetup(); + ads.ApplicationBase = Path.GetDirectoryName(path); + ads.DisallowBindingRedirects = false; + ads.DisallowCodeDownload = true; + ads.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; + + // Create the second AppDomain. + AppDomain ad2 = AppDomain.CreateDomain("AD #2", null, ads); + + try + { + // Create an instance of MarshalbyRefType in the second AppDomain. + // A proxy to the object is returned. + reader = (SqlReader)ad2.CreateInstanceAndUnwrap(exeAssembly, typeof(SqlReader).FullName); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + + //// Unload the second AppDomain. This deletes its object and + //// invalidates the proxy object. + //AppDomain.Unload(ad2); + + return reader; + } + /// /// Method to set up a SQLite Connection to a specified .db3 file. /// Will return a SQLite connection to the aforementioned .db3 file database. /// /// /// - public static SQLiteConnection Connection(string filePath) + public SQLiteConnection Connection(string filePath) { return new SQLiteConnection($"URI=file:{filePath};mode=ReadOnly"); } @@ -31,8 +72,9 @@ public static SQLiteConnection Connection(string filePath) /// /// Path to SecLib.db3 /// - public static Tuple, List> GetCataloguesDataFromSQLite(string filePath) + public Tuple, List> GetCataloguesDataFromSQLite(string filePath) { + // Create empty lists to work on: List catNames = new List(); List catNumber = new List(); @@ -73,7 +115,7 @@ public static Tuple, List> GetCataloguesDataFromSQLite(string /// Path to SecLib.db3 /// True if you want to include superseeded items /// - public static Tuple, List> GetTypesDataFromSQLite(int catalogue_number, string filePath, bool inclSuperseeded = false) + public Tuple, List> GetTypesDataFromSQLite2(int catalogue_number, string filePath, bool inclSuperseeded = false) { // Create empty lists to work on: List typeNames = new List(); @@ -122,6 +164,65 @@ public static Tuple, List> GetTypesDataFromSQLite(int catalogu return new Tuple, List>(typeNames, typeNumber); } + /// + /// Get section type data from SQLite file (.db3). The method returns a tuple with: + /// Item1 = list of type name (string) + /// where first item will be "All" + /// Item2 = list of type number (int) + /// where first item will be "-1" representing All + /// + /// Catalogue number to get section types from. Input -1 in first item of the input list to get all types + /// Path to SecLib.db3 + /// True if you want to include superseeded items + /// + public Tuple, List> GetTypesDataFromSQLite(int catalogue_number, string filePath, bool inclSuperseeded = false) + { + // Create empty lists to work on: + List typeNames = new List(); + List typeNumber = new List(); + + // get Catalogue numbers if input is -1 (All catalogues) + List catNumbers = new List(); + if (catalogue_number == -1) + { + Tuple, List> catalogueData = GetCataloguesDataFromSQLite(filePath); + catNumbers = catalogueData.Item2; + catNumbers.RemoveAt(0); // remove -1 from beginning of list + } + else + catNumbers.Add(catalogue_number); + + using (var db = Connection(filePath)) + { + for (int i = 0; i < catNumbers.Count; i++) + { + int cat = catNumbers[i]; + + db.Open(); + SQLiteCommand cmd = db.CreateCommand(); + if (inclSuperseeded) + cmd.CommandText = $"Select TYPE_NAME || ' -- ' || TYPE_NUM as TYPE_NAME from Types where TYPE_CAT_NUM = {cat}"; + else + cmd.CommandText = $"Select TYPE_NAME || ' -- ' || TYPE_NUM as TYPE_NAME from Types where TYPE_CAT_NUM = {cat} and not (TYPE_SUPERSEDED = True or TYPE_SUPERSEDED = TRUE or TYPE_SUPERSEDED = 1)"; + cmd.CommandType = CommandType.Text; + SQLiteDataReader r = cmd.ExecuteReader(); + while (r.Read()) + { + // get data + string sqlData = Convert.ToString(r["TYPE_NAME"]); + + // split text string + // example: Universal Beams -- 51 + typeNames.Add(sqlData.Split(new string[] { " -- " }, StringSplitOptions.None)[0]); + typeNumber.Add(Int32.Parse(sqlData.Split(new string[] { " -- " }, StringSplitOptions.None)[1])); + } + db.Close(); + } + } + typeNames.Insert(0, "All"); + typeNumber.Insert(0, -1); + return new Tuple, List>(typeNames, typeNumber); + } /// /// Get a list of section profile strings from SQLite file (.db3). The method returns a string that includes type abbriviation as accepted by GSA. @@ -130,7 +231,7 @@ public static Tuple, List> GetTypesDataFromSQLite(int catalogu /// Path to SecLib.db3 /// True if you want to include superseeded items /// - public static List GetSectionsDataFromSQLite(List type_numbers, string filePath, bool inclSuperseeded = false) + public List GetSectionsDataFromSQLite(List type_numbers, string filePath, bool inclSuperseeded = false) { // Create empty list to work on: List section = new List(); @@ -200,7 +301,7 @@ public static List GetSectionsDataFromSQLite(List type_numbers, str /// /// /// - public static List GetCatalogueProfileValues(string profileString, string filePath) + public List GetCatalogueProfileValues(string profileString, string filePath) { // Create empty lists to work on: List values = new List(); From f612d21d95574175a1cef065b04bcf30649bd532 Mon Sep 17 00:00:00 2001 From: Tilman Reinhardt Date: Tue, 10 Jan 2023 09:25:11 +0100 Subject: [PATCH 2/7] welded beams --- GsaGH/Helpers/GsaAPI/SqlReader.cs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/GsaGH/Helpers/GsaAPI/SqlReader.cs b/GsaGH/Helpers/GsaAPI/SqlReader.cs index 88d23c61e..e00cee054 100644 --- a/GsaGH/Helpers/GsaAPI/SqlReader.cs +++ b/GsaGH/Helpers/GsaAPI/SqlReader.cs @@ -317,10 +317,8 @@ public List GetCatalogueProfileValues(string profileString, string fileP $"SECT_FLG_THICK || ' -- ' || " + $"SECT_ROOT_RAD " + $"as SECT_NAME from Sect INNER JOIN Types ON Sect.SECT_TYPE_NUM = Types.TYPE_NUM where SECT_NAME = \"{profileString}\" ORDER BY SECT_DATE_ADDED"; - - List data = new List(); - cmd.CommandType = CommandType.Text; + List data = new List(); SQLiteDataReader r = cmd.ExecuteReader(); while (r.Read()) { @@ -331,10 +329,34 @@ public List GetCatalogueProfileValues(string profileString, string fileP // example (IPE100): 0.1 -- 0.055 -- 0.0041 -- 0.0057 -- 0.007 data.Add(sqlData); } - db.Close(); string[] vals = data[0].Split(new string[] { " -- " }, StringSplitOptions.None); + if (vals.Length <= 1) + { + cmd.CommandText = $"Select " + + $"SECT_DEPTH_DIAM || ' -- ' || " + + $"SECT_WIDTH || ' -- ' || " + + $"SECT_WEB_THICK || ' -- ' || " + + $"SECT_FLG_THICK || ' -- ' || " + + $"as SECT_NAME from Sect INNER JOIN Types ON Sect.SECT_TYPE_NUM = Types.TYPE_NUM where SECT_NAME = \"{profileString}\" ORDER BY SECT_DATE_ADDED"; + + data = new List(); + r = cmd.ExecuteReader(); + while (r.Read()) + { + // get data + string sqlData = Convert.ToString(r["SECT_NAME"]); + + // split text string + // example (IPE100): 0.1 -- 0.055 -- 0.0041 -- 0.0057 -- 0.007 + data.Add(sqlData); + } + } + db.Close(); + + vals = data[0].Split(new string[] { " -- " }, StringSplitOptions.None); + NumberFormatInfo noComma = CultureInfo.InvariantCulture.NumberFormat; foreach (string val in vals) From 56206b565be528a6f078dd834a2d7a0233732b5e Mon Sep 17 00:00:00 2001 From: Tilman Reinhardt Date: Tue, 10 Jan 2023 10:23:36 +0100 Subject: [PATCH 3/7] singleton --- .../Components/1_Properties/CreateProfile.cs | 20 ++++++------ .../1_Properties/GetSectionDimensions.cs | 26 +++++++--------- .../Components/2_Geometry/SectionAlignment.cs | 2 +- GsaGH/Components/4_Analysis/Analyse.cs | 8 +---- GsaGH/GsaGH.csproj | 2 +- GsaGH/GsaGHInfo.cs | 2 +- GsaGH/Helpers/GsaAPI/SqlReader.cs | 31 +++++++------------ 7 files changed, 37 insertions(+), 54 deletions(-) diff --git a/GsaGH/Components/1_Properties/CreateProfile.cs b/GsaGH/Components/1_Properties/CreateProfile.cs index 6abc17cce..6cc2f5c42 100644 --- a/GsaGH/Components/1_Properties/CreateProfile.cs +++ b/GsaGH/Components/1_Properties/CreateProfile.cs @@ -3,9 +3,7 @@ using System.Globalization; using System.IO; using System.Linq; -using System.Reflection; using System.Text.RegularExpressions; -using System.Threading; using Grasshopper.Kernel; using Grasshopper.Kernel.Parameters; using Grasshopper.Kernel.Types; @@ -884,19 +882,19 @@ private void Mode2Clicked() // for catalogue selection // Catalogues - private readonly Tuple, List> _cataloguedata = SqlReader.reader.GetCataloguesDataFromSQLite(Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3")); + private readonly Tuple, List> _cataloguedata = SqlReader.Instance.GetCataloguesDataFromSQLite(Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3")); private List _catalogueNumbers = new List(); // internal db catalogue numbers private List _catalogueNames = new List(); // list of displayed catalogues bool _inclSS; // Types - private Tuple, List> _typedata = SqlReader.reader.GetTypesDataFromSQLite(-1, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), false); + private Tuple, List> _typedata = SqlReader.Instance.GetTypesDataFromSQLite(-1, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), false); private List _typeNumbers = new List(); // internal db type numbers private List _typeNames = new List(); // list of displayed types // Sections // list of displayed sections - private List _sectionList = SqlReader.reader.GetSectionsDataFromSQLite(new List { -1 }, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), false); + private List _sectionList = SqlReader.Instance.GetSectionsDataFromSQLite(new List { -1 }, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), false); private List _filteredlist = new List(); int _catalogueIndex = -1; //-1 is all int _typeIndex = -1; @@ -968,7 +966,7 @@ public override void SetSelected(int i, int j) _typeNumbers = _typedata.Item2; // update section list to all types - _sectionList = SqlReader.reader.GetSectionsDataFromSQLite(_typeNumbers, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); + _sectionList = SqlReader.Instance.GetSectionsDataFromSQLite(_typeNumbers, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); // filter by search pattern _filteredlist = new List(); @@ -1024,14 +1022,14 @@ public override void SetSelected(int i, int j) SelectedItems[1] = _catalogueNames[j]; // update typelist with selected input catalogue - _typedata = SqlReader.reader.GetTypesDataFromSQLite(_catalogueIndex, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); + _typedata = SqlReader.Instance.GetTypesDataFromSQLite(_catalogueIndex, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); _typeNames = _typedata.Item1; _typeNumbers = _typedata.Item2; // update section list from new types (all new types in catalogue) List types = _typeNumbers.ToList(); types.RemoveAt(0); // remove -1 from beginning of list - _sectionList = SqlReader.reader.GetSectionsDataFromSQLite(types, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); + _sectionList = SqlReader.Instance.GetSectionsDataFromSQLite(types, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); // filter by search pattern _filteredlist = new List(); @@ -1089,7 +1087,7 @@ public override void SetSelected(int i, int j) // section list with selected types (only types in selected type) - _sectionList = SqlReader.reader.GetSectionsDataFromSQLite(types, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); + _sectionList = SqlReader.Instance.GetSectionsDataFromSQLite(types, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); // filter by search pattern _filteredlist = new List(); @@ -1172,7 +1170,7 @@ public override void SetSelected(int i, int j) private Tuple, List> GetTypesDataFromSQLite(int catalogueIndex, string filePath, bool inclSuperseeded) { - return SqlReader.reader.GetTypesDataFromSQLite2(catalogueIndex, filePath, inclSuperseeded); + return SqlReader.Instance.GetTypesDataFromSQLite2(catalogueIndex, filePath, inclSuperseeded); } public override void UpdateUIFromSelectedItems() @@ -1187,7 +1185,7 @@ public override void UpdateUIFromSelectedItems() _catalogueNames = _cataloguedata.Item1; _catalogueNumbers = _cataloguedata.Item2; - _typedata = SqlReader.reader.GetTypesDataFromSQLite(_catalogueIndex, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); + _typedata = SqlReader.Instance.GetTypesDataFromSQLite(_catalogueIndex, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3"), _inclSS); _typeNames = _typedata.Item1; _typeNumbers = _typedata.Item2; diff --git a/GsaGH/Components/1_Properties/GetSectionDimensions.cs b/GsaGH/Components/1_Properties/GetSectionDimensions.cs index 1e41fedbe..f41d0a01c 100644 --- a/GsaGH/Components/1_Properties/GetSectionDimensions.cs +++ b/GsaGH/Components/1_Properties/GetSectionDimensions.cs @@ -1,29 +1,27 @@ using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; using System.Windows.Forms; using Grasshopper.Kernel; using Grasshopper.Kernel.Types; +using GsaGH.Helpers.GH; +using GsaGH.Helpers.GsaAPI; using GsaGH.Parameters; using OasysGH; using OasysGH.Components; using OasysGH.Parameters; -using OasysGH.Units.Helpers; using OasysGH.Units; -using OasysUnits.Units; +using OasysGH.Units.Helpers; using OasysUnits; -using GsaGH.Helpers.GsaAPI; -using System.Globalization; -using OasysGH.Helpers; -using System.Collections.Generic; -using System.IO; -using GsaGH.Helpers; -using GsaGH.Helpers.GH; +using OasysUnits.Units; namespace GsaGH.Components { - /// - /// Component to get geometric dimensions of a section - /// - public class GetSectionDimensions : GH_OasysComponent, IGH_VariableParameterComponent + /// + /// Component to get geometric dimensions of a section + /// + public class GetSectionDimensions : GH_OasysComponent, IGH_VariableParameterComponent { #region Name and Ribbon Layout public override Guid ComponentGuid => new Guid("98765d83-2b23-47c1-ad1d-201b5a2eed8b"); @@ -428,7 +426,7 @@ protected override void SolveInstance(IGH_DataAccess DA) else if (profile.StartsWith("CAT")) { string prof = profile.Split(' ')[2]; - List sqlValues = SqlReader.reader.GetCatalogueProfileValues(prof, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3")); + List sqlValues = SqlReader.Instance.GetCatalogueProfileValues(prof, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3")); unit = LengthUnit.Meter; DA.SetData(i++, new GH_UnitNumber(new Length(sqlValues[0], unit).ToUnit(this.LengthUnit))); //Depth diff --git a/GsaGH/Components/2_Geometry/SectionAlignment.cs b/GsaGH/Components/2_Geometry/SectionAlignment.cs index 8b7a20f76..6fc9c7fa8 100644 --- a/GsaGH/Components/2_Geometry/SectionAlignment.cs +++ b/GsaGH/Components/2_Geometry/SectionAlignment.cs @@ -348,7 +348,7 @@ protected override void SolveInstance(IGH_DataAccess DA) else if (profile.StartsWith("CAT")) { string prof = profile.Split(' ')[2]; - List sqlValues = SqlReader.reader.GetCatalogueProfileValues(prof, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3")); + List sqlValues = SqlReader.Instance.GetCatalogueProfileValues(prof, Path.Combine(AddReferencePriority.InstallPath, "sectlib.db3")); unit = LengthUnit.Meter; depth = new Length(sqlValues[0], unit); diff --git a/GsaGH/Components/4_Analysis/Analyse.cs b/GsaGH/Components/4_Analysis/Analyse.cs index b8231be24..123f5f657 100644 --- a/GsaGH/Components/4_Analysis/Analyse.cs +++ b/GsaGH/Components/4_Analysis/Analyse.cs @@ -1,14 +1,10 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; -using System.Threading.Tasks; -using Grasshopper.GUI; using System.Windows.Forms; +using Grasshopper.GUI; using Grasshopper.Kernel; -using Grasshopper.Kernel.Types; using GsaAPI; -using GsaGH.Helpers; using GsaGH.Helpers.GH; using GsaGH.Parameters; using OasysGH; @@ -18,8 +14,6 @@ using OasysGH.Units.Helpers; using OasysUnits; using OasysUnits.Units; -using Rhino.Runtime; -using System.Drawing; namespace GsaGH.Components { diff --git a/GsaGH/GsaGH.csproj b/GsaGH/GsaGH.csproj index ddca1a6ce..674669498 100644 --- a/GsaGH/GsaGH.csproj +++ b/GsaGH/GsaGH.csproj @@ -10,7 +10,7 @@ https://github.com/arup-group/GSA-Grasshopper README.md GSALogo128.png - 0.9.39-beta + 0.9.40-beta MIT false Official Oasys GSA Grasshopper Plugin diff --git a/GsaGH/GsaGHInfo.cs b/GsaGH/GsaGHInfo.cs index 6379e46f7..9e05808e7 100644 --- a/GsaGH/GsaGHInfo.cs +++ b/GsaGH/GsaGHInfo.cs @@ -204,7 +204,7 @@ public class GsaGHInfo : GH_AssemblyInfo internal const string Company = "Oasys"; internal const string Copyright = "Copyright © Oasys 1985 - 2023"; internal const string Contact = "https://www.oasys-software.com/"; - internal const string Vers = "0.9.39"; + internal const string Vers = "0.9.40"; internal static bool isBeta = true; internal static string Disclaimer = PluginName + " is pre-release and under active development, including further testing to be undertaken. It is provided \"as-is\" and you bear the risk of using it. Future versions may contain breaking changes. Any files, results, or other types of output information created using " + PluginName + " should not be relied upon without thorough and independent checking. "; internal const string ProductName = "GSA"; diff --git a/GsaGH/Helpers/GsaAPI/SqlReader.cs b/GsaGH/Helpers/GsaAPI/SqlReader.cs index e00cee054..49dc484d5 100644 --- a/GsaGH/Helpers/GsaAPI/SqlReader.cs +++ b/GsaGH/Helpers/GsaAPI/SqlReader.cs @@ -5,16 +5,17 @@ using System.Globalization; using System.IO; using System.Reflection; -using System.Threading; namespace GsaGH.Helpers.GsaAPI { /// /// Class containing functions to interface with SQLite db files. + /// Singleton makes sure this class is executed in a separate AppDomain to avoid conflicts with different SQLite versions in main AppDomain. /// public class SqlReader : MarshalByRefObject { - public static SqlReader reader = Initialize(); + public static SqlReader Instance { get { return lazy.Value; } } + private static readonly Lazy lazy = new Lazy(() => Initialize()); public static SqlReader Initialize() { @@ -32,26 +33,18 @@ public static SqlReader Initialize() ads.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; // Create the second AppDomain. - AppDomain ad2 = AppDomain.CreateDomain("AD #2", null, ads); - - try - { - // Create an instance of MarshalbyRefType in the second AppDomain. - // A proxy to the object is returned. - reader = (SqlReader)ad2.CreateInstanceAndUnwrap(exeAssembly, typeof(SqlReader).FullName); - } - catch (Exception e) - { - Console.WriteLine(e.Message); - } - - //// Unload the second AppDomain. This deletes its object and - //// invalidates the proxy object. - //AppDomain.Unload(ad2); + AppDomain ad = AppDomain.CreateDomain("SQLite AppDomain", null, ads); + // Create an instance of MarshalbyRefType in the second AppDomain. + // A proxy to the object is returned. + SqlReader reader = (SqlReader)ad.CreateInstanceAndUnwrap(exeAssembly, typeof(SqlReader).FullName); return reader; } + public SqlReader() + { + } + /// /// Method to set up a SQLite Connection to a specified .db3 file. /// Will return a SQLite connection to the aforementioned .db3 file database. @@ -297,7 +290,7 @@ public List GetSectionsDataFromSQLite(List type_numbers, string fil /// [1]: Width /// [2]: Web THK /// [3]: Flange THK - /// [4]: Root radius + /// [4]: Root radius (only if section is not welded!) /// /// /// From cdb5b98aa70417918c0337a2f9176d91f44175b4 Mon Sep 17 00:00:00 2001 From: Tilman Reinhardt Date: Tue, 10 Jan 2023 12:37:36 +0100 Subject: [PATCH 4/7] SQLite references --- GsaGH/GsaGH.csproj | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/GsaGH/GsaGH.csproj b/GsaGH/GsaGH.csproj index 674669498..c4a697dbe 100644 --- a/GsaGH/GsaGH.csproj +++ b/GsaGH/GsaGH.csproj @@ -49,7 +49,6 @@ Copyright © Oasys 1985 - 2022 all compile;build - @@ -57,6 +56,10 @@ Copyright © Oasys 1985 - 2022 ..\..\..\..\..\..\Program Files\Oasys\GSA 10.1\GsaAPI.dll False + + ..\..\..\..\..\..\Program Files\Oasys\GSA 10.1\System.Data.SQLite.dll + False + ..\..\..\..\..\..\Program Files\Oasys\GSA 10.1\Interop.Gsa_10_1.dll True From f11adeae43a96f84d30a008f7a0d0816093bf375 Mon Sep 17 00:00:00 2001 From: Tilman Reinhardt Date: Tue, 10 Jan 2023 13:08:43 +0100 Subject: [PATCH 5/7] SQLite --- GsaGH/GsaGH.csproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/GsaGH/GsaGH.csproj b/GsaGH/GsaGH.csproj index 1d4fb05b2..e3b8d7698 100644 --- a/GsaGH/GsaGH.csproj +++ b/GsaGH/GsaGH.csproj @@ -56,10 +56,6 @@ Copyright © Oasys 1985 - 2022 ..\..\..\..\..\..\Program Files\Oasys\GSA 10.1\GsaAPI.dll False - - ..\..\..\..\..\..\Program Files\Oasys\GSA 10.1\System.Data.SQLite.dll - False - ..\..\..\..\..\..\Program Files\Oasys\GSA 10.1\Interop.Gsa_10_1.dll True From 038c14b02446e186a1c8c4afee53dc380e3ba251 Mon Sep 17 00:00:00 2001 From: Tilman Reinhardt Date: Tue, 10 Jan 2023 14:07:03 +0100 Subject: [PATCH 6/7] SQLite nuget --- GsaGH/GsaGH.csproj | 5 +---- GsaGHTests/GsaGHTests.csproj | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/GsaGH/GsaGH.csproj b/GsaGH/GsaGH.csproj index e3b8d7698..674669498 100644 --- a/GsaGH/GsaGH.csproj +++ b/GsaGH/GsaGH.csproj @@ -49,6 +49,7 @@ Copyright © Oasys 1985 - 2022 all compile;build + @@ -65,10 +66,6 @@ Copyright © Oasys 1985 - 2022 - - ..\..\..\..\..\..\Program Files\Oasys\GSA 10.1\System.Data.SQLite.dll - False - diff --git a/GsaGHTests/GsaGHTests.csproj b/GsaGHTests/GsaGHTests.csproj index ed32df15b..30e3205ad 100644 --- a/GsaGHTests/GsaGHTests.csproj +++ b/GsaGHTests/GsaGHTests.csproj @@ -11,6 +11,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive @@ -31,10 +32,6 @@ ..\..\..\..\..\..\Program Files\Oasys\GSA 10.1\GsaAPI.dll False - - ..\..\..\..\..\..\Program Files\Oasys\GSA 10.1\System.Data.SQLite.dll - False - From fac3ed97c5c93d396cf7f80f4d22813357614b64 Mon Sep 17 00:00:00 2001 From: Tilman Reinhardt Date: Wed, 11 Jan 2023 09:51:52 +0100 Subject: [PATCH 7/7] OasysGH version --- GsaGH/GsaGH.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GsaGH/GsaGH.csproj b/GsaGH/GsaGH.csproj index 674669498..aeb4fa913 100644 --- a/GsaGH/GsaGH.csproj +++ b/GsaGH/GsaGH.csproj @@ -44,7 +44,7 @@ Copyright © Oasys 1985 - 2022 all - + all compile;build