public void SetupTests() { //This uses the installed SpeckleKits - when SpeckleStructural is built, the built files are copied into the // %LocalAppData%\SpeckleKits directory, so therefore this project doesn't need to reference the projects within in this solution SpeckleInitializer.Initialize(); Initialiser.AppResources = new MockGSAApp(proxy: new GSAProxy()); }
public static List <IGSASenderDictionary> GetAssembliesSenderDictionaries() { var assemblies = SpeckleInitializer.GetAssemblies().Where(a => a.GetTypes().Any(t => t.GetInterfaces().Contains(typeof(ISpeckleInitializer)))); var staticObjects = new List <IGSASenderDictionary>(); //Now obtain the serialised (inheriting from SpeckleObject) objects foreach (var ass in assemblies) { var types = ass.GetTypes(); try { var gsaStatic = types.FirstOrDefault(t => t.GetInterfaces().Contains(typeof(ISpeckleInitializer)) && t.GetProperties().Any(p => p.PropertyType == typeof(IGSACacheForKit))); if (gsaStatic != null) { var dict = (IGSASenderDictionary)gsaStatic.GetProperties().FirstOrDefault(p => p.PropertyType == typeof(IGSASenderDictionary)).GetValue(null); //This is how SpeckleGSA finds the objects in the GSASenderObjects dictionary - by finding the first property in ISpeckleInitializer which is of the specific dictionary type staticObjects.Add(dict); } } catch (Exception e) { } } return(staticObjects); }
public void CompareFiles(string fn1, string fn2) { Debug.WriteLine("----------------"); Debug.WriteLine("Comparing: " + fn1 + " and " + fn2); SpeckleInitializer.Initialize(); var j1Full = Helper.ReadFile(fn1, TestDataDirectory); var j2Full = Helper.ReadFile(fn2, TestDataDirectory); var o1All = JsonConvert.DeserializeObject <List <SpeckleObject> >(j1Full, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); var o2All = JsonConvert.DeserializeObject <List <SpeckleObject> >(j2Full, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); var j1List = o1All.ToDictionary(o => o, o => Regex.Replace(JsonConvert.SerializeObject(o, jsonSettings), jsonDecSearch, "$1")); var j2List = o2All.ToDictionary(o => o, o => Regex.Replace(JsonConvert.SerializeObject(o, jsonSettings), jsonDecSearch, "$1")); Debug.WriteLine("Listing items in 1 that aren't in 2"); Compare(j1List, j2List, out Dictionary <SpeckleObject, List <SpeckleObject> > notFoundIn2); Debug.WriteLine("Listing items in 2 that aren't in 1"); Compare(j2List, j1List, out Dictionary <SpeckleObject, List <SpeckleObject> > notFoundIn1); Debug.WriteLine("Number of in 1 that isn't found in 2: " + notFoundIn2.Count()); Debug.WriteLine("Number of in 2 that isn't found in 1: " + notFoundIn1.Count()); Assert.AreEqual(0, notFoundIn2.Count()); Assert.AreEqual(o2All.Count() - o1All.Count(), notFoundIn1.Count()); }
public static bool SetAssembliesSenderDictionaries() { var assemblies = SpeckleInitializer.GetAssemblies().Where(a => a.GetTypes().Any(t => t.GetInterfaces().Contains(typeof(ISpeckleInitializer)))); senderDictionaries = new List <IGSASenderDictionary>(); //Now obtain the serialised (inheriting from SpeckleObject) objects foreach (var ass in assemblies) { var types = ass.GetTypes(); try { var gsaStatic = types.FirstOrDefault(t => t.GetInterfaces().Contains(typeof(ISpeckleInitializer)) && t.GetProperties().Any(p => p.PropertyType == typeof(IGSACacheForKit))); if (gsaStatic != null) { var dict = (IGSASenderDictionary)gsaStatic.GetProperties().FirstOrDefault(p => p.PropertyType == typeof(IGSASenderDictionary)).GetValue(null); //This is how SpeckleGSA finds the objects in the GSASenderObjects dictionary - by finding the first property in ISpeckleInitializer which is of the specific dictionary type senderDictionaries.Add(dict); } } catch (FileNotFoundException) { //Swallow as it is likely to be an application SDK that a kit's conversion code references which isn't installed } catch (Exception e) { return(false); } } return(true); }
/// <summary> /// Initializes Speckle and assigns the scale factor of all geometry. Invokes the <c>RunStartBehaviour ()</c> /// coroutine. /// </summary> protected virtual async void Start() { SpeckleInitializer.Initialize(false); SpeckleUnityMesh.RecentreMeshTransforms = recentreMeshTransforms; SpeckleUnityPolyline.LineWidth = lineWidth; SpeckleUnityPoint.PointDiameter = pointDiameter; await RunStartBehaviourAsync(); }
public void SetupTests() { //This uses the installed SpeckleKits - when SpeckleStructural is built, the built files are copied into the // %LocalAppData%\SpeckleKits directory, so therefore this project doesn't need to reference the projects within in this solution SpeckleInitializer.Initialize(); gsaInterfacer = new GSAProxy(); gsaCache = new GSACache(); Initialiser.Cache = gsaCache; Initialiser.Interface = gsaInterfacer; Initialiser.Settings = new Settings(); }
public void SetupTests() { //This uses the installed SpeckleKits - when SpeckleStructural is built, the built files are copied into the // %LocalAppData%\SpeckleKits directory, so therefore this project doesn't need to reference the projects within in this solution //If this isn't called, then the GetObjectSubtypeBetter method in SpeckleCore will cause a {"Value cannot be null.\r\nParameter name: source"} message SpeckleInitializer.Initialize(); gsaInterfacer = new GSAProxy(); gsaCache = new GSACache(); Initialiser.Cache = gsaCache; Initialiser.Interface = gsaInterfacer; Initialiser.Settings = new Settings(); }
private List <Type> GetAssembliesTypes() { // Grab GSA interface type var interfaceType = typeof(IGSASpeckleContainer); var assemblies = SpeckleInitializer.GetAssemblies(); var objTypes = new List <Type>(); foreach (var ass in assemblies) { var types = ass.GetTypes(); objTypes.AddRange(types.Where(t => interfaceType.IsAssignableFrom(t) && t != interfaceType)); } return(objTypes); }
public void SetupTests() { //This uses the installed SpeckleKits - when SpeckleStructural is built, the built files are copied into the // %LocalAppData%\SpeckleKits directory, so therefore this project doesn't need to reference the projects within in this solution SpeckleInitializer.Initialize(); //gsaInterfacer = new GSAProxy(); //gsaCache = new GSACache(); Initialiser.AppResources = new MockGSAApp(proxy: new GSAProxy()); Initialiser.GsaKit.Clear(); //Initialiser.Instance.Cache = gsaCache; //Initialiser.Instance.Interface = gsaInterfacer; //Initialiser.Instance.Settings = new MockSettings(); //Initialiser.Instance.AppUI = new SpeckleAppUI(); }
private void ReceiverGsaValidation(string subdir, string[] jsonFiles, GSATargetLayer layer) { // Takes a saved Speckle stream with structural objects // converts to GWA and sends to GSA // then reads the data back out of GSA // and compares the two sets of GWA // if successful then there will be the same number // of each of the keywords in as out SpeckleInitializer.Initialize(); Initialiser.AppResources = new MockGSAApp(proxy: new GSAProxy()); Initialiser.GsaKit.Clear(); Initialiser.AppResources.Settings.TargetLayer = layer; Initialiser.AppResources.Proxy.NewFile(true); var dir = TestDataDirectory; if (subdir != String.Empty) { dir = Path.Combine(TestDataDirectory, subdir); dir = dir + @"\"; // TestDataDirectory setup unconvetionally with trailing seperator - follow suit } var receiverProcessor = new ReceiverProcessor(dir, Initialiser.AppResources); // Run conversion to GWA keywords // Note that it can be one model split over several json files receiverProcessor.JsonSpeckleStreamsToGwaRecords(jsonFiles, out var gwaRecordsFromFile, layer); //Run conversion to GWA keywords Assert.IsNotNull(gwaRecordsFromFile); Assert.IsNotEmpty(gwaRecordsFromFile); var designTypeHierarchy = Helper.GetTypeCastPriority(ioDirection.Receive, GSATargetLayer.Design, false); var analysisTypeHierarchy = Helper.GetTypeCastPriority(ioDirection.Receive, GSATargetLayer.Analysis, false); var keywords = designTypeHierarchy.Select(i => i.Key.GetGSAKeyword()).ToList(); keywords.AddRange(designTypeHierarchy.SelectMany(i => i.Key.GetSubGSAKeyword())); keywords.AddRange(analysisTypeHierarchy.Select(i => i.Key.GetGSAKeyword())); keywords.AddRange(analysisTypeHierarchy.SelectMany(i => i.Key.GetSubGSAKeyword())); keywords = keywords.Where(k => k.Length > 0).Select(k => Helper.RemoveVersionFromKeyword(k)).Distinct().ToList(); Initialiser.AppResources.Proxy.Sync(); // send GWA to GSA var retrievedGwa = Initialiser.AppResources.Proxy.GetGwaData(keywords, true); // read GWA from GSA var retrievedDict = new Dictionary <string, List <string> >(); foreach (var gwa in retrievedGwa) { Initialiser.AppResources.Proxy.ParseGeneralGwa(gwa.GwaWithoutSet, out string keyword, out _, out _, out _, out _, out _); if (!retrievedDict.ContainsKey(keyword)) { retrievedDict.Add(keyword, new List <string>()); } retrievedDict[keyword].Add(gwa.GwaWithoutSet); } var fromFileDict = new Dictionary <string, List <string> >(); foreach (var r in gwaRecordsFromFile) { Initialiser.AppResources.Proxy.ParseGeneralGwa(r.GwaCommand, out string keyword, out _, out _, out _, out string gwaWithoutSet, out _); if (!fromFileDict.ContainsKey(keyword)) { fromFileDict.Add(keyword, new List <string>()); } fromFileDict[keyword].Add(gwaWithoutSet); } Initialiser.AppResources.Proxy.Close(); var unmatching = new Dictionary <string, UnmatchedData>(); foreach (var keyword in fromFileDict.Keys) { if (!retrievedDict.ContainsKey(keyword)) { unmatching[keyword] = new UnmatchedData(); unmatching[keyword].FromFile = fromFileDict[keyword]; } else if (retrievedDict[keyword].Count != fromFileDict[keyword].Count) { unmatching[keyword] = new UnmatchedData(); unmatching[keyword].Retrieved = (retrievedDict.ContainsKey(keyword)) ? retrievedDict[keyword] : null; unmatching[keyword].FromFile = fromFileDict[keyword]; } } Assert.AreEqual(0, unmatching.Count()); // GSA sometimes forgets the SID - should check that this has passed through correctly here }
static void Main(string[] args) { //This uses the installed SpeckleKits - when SpeckleStructural is built, the built files are copied into the // %LocalAppData%\SpeckleKits directory, so therefore this project doesn't need to reference the projects within in this solution //If this isn't called, then the GetObjectSubtypeBetter method in SpeckleCore will cause a {"Value cannot be null.\r\nParameter name: source"} message SpeckleInitializer.Initialize(); var TestDataDirectory = AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new[] { '\\' }) + @"\..\..\..\SpeckleStructuralGSA.Test\TestData\"; var receiverTestPrep = new ReceiverTestPrep(TestDataDirectory); receiverTestPrep.SetupContext(); if (!receiverTestPrep.SetUpReceptionTestData(ReceiverTests.savedBlankRefsJsonFileNames, ReceiverTests.expectedBlankRefsGwaPerIdsFileName, GSATargetLayer.Design)) { Console.WriteLine("Error in preparing test data for the blank refs rx design layer test"); } else { Console.WriteLine("Prepared reception test data for the blank refs rx design layer test"); } receiverTestPrep = new ReceiverTestPrep(TestDataDirectory); receiverTestPrep.SetupContext(); if (!receiverTestPrep.SetUpReceptionTestData(ReceiverTests.savedJsonFileNames, ReceiverTests.expectedGwaPerIdsFileName, GSATargetLayer.Design)) { Console.WriteLine("Error in preparing test data for the rx design layer test"); } else { Console.WriteLine("Prepared reception test data for the rx design layer test"); } var senderTestPrep = new SenderTestPrep(TestDataDirectory); //First the sender test for design layer data without any results being in the file senderTestPrep.SetupContext(SenderTests.gsaFileNameWithoutResults); try { if (!senderTestPrep.SetUpTransmissionTestData("TxSpeckleObjectsDesignLayerBeforeAnalysis.json", GSATargetLayer.Design, false, true)) { throw new Exception("Transmission: design layer test preparation failed"); } Console.WriteLine("Prepared test data for the tx design layer before analysis test"); } catch (Exception e) { Console.WriteLine(e.Message); } finally { senderTestPrep.TearDownContext(); } //Next the sender tests using a file with results already generated senderTestPrep.SetupContext(SenderTests.gsaFileNameWithResults); try { if (!senderTestPrep.SetUpTransmissionTestData("TxSpeckleObjectsDesignLayer.json", GSATargetLayer.Design, false, true)) { throw new Exception("Transmission: design layer test preparation failed"); } Console.WriteLine("Prepared test data for the tx design layer test"); if (!senderTestPrep.SetUpTransmissionTestData("TxSpeckleObjectsResultsOnly.json", GSATargetLayer.Analysis, true, false, SenderTests.loadCases, SenderTests.resultTypes)) { throw new Exception("Transmission: results-only test preparation failed"); } Console.WriteLine("Prepared test data for the tx results-only test"); if (!senderTestPrep.SetUpTransmissionTestData("TxSpeckleObjectsEmbedded.json", GSATargetLayer.Analysis, false, true, SenderTests.loadCases, SenderTests.resultTypes)) { throw new Exception("Transmission: embedded test preparation failed"); } Console.WriteLine("Prepared test data for the tx embedded results test"); if (!senderTestPrep.SetUpTransmissionTestData("TxSpeckleObjectsNotEmbedded.json", GSATargetLayer.Analysis, false, false, SenderTests.loadCases, SenderTests.resultTypes)) { throw new Exception("Transmission: not-embedded test preparation failed"); } Console.WriteLine("Prepared test data for the tx non-embedded results test"); } catch (Exception e) { Console.WriteLine(e.Message); } finally { senderTestPrep.TearDownContext(); } Console.WriteLine("Press any key to exit ..."); Console.ReadKey(); }
/* * private static bool blankRefs = true; * private static bool rxDesign = true; * private static bool txDesignBeforeAnalysis = true; * private static bool txDesign = true; * private static bool txResultsOnly = true; * private static bool txEmbedded = true; * private static bool txNotEmbedded = true; */ static void Main(string[] args) { //This uses the installed SpeckleKits - when SpeckleStructural is built, the built files are copied into the // %LocalAppData%\SpeckleKits directory, so therefore this project doesn't need to reference the projects within in this solution //If this isn't called, then the GetObjectSubtypeBetter method in SpeckleCore will cause a {"Value cannot be null.\r\nParameter name: source"} message SpeckleInitializer.Initialize(); var blankRefs = args.Any(a => a.Equals("blankRefs", StringComparison.InvariantCultureIgnoreCase)); var rxDesign = args.Any(a => a.Equals("rxDesign", StringComparison.InvariantCultureIgnoreCase)); var txDesignBeforeAnalysis = args.Any(a => a.Equals("txDesignBeforeAnalysis", StringComparison.InvariantCultureIgnoreCase));; var txDesign = args.Any(a => a.Equals("txDesign", StringComparison.InvariantCultureIgnoreCase));; var txResultsOnly = args.Any(a => a.Equals("txResultsOnly", StringComparison.InvariantCultureIgnoreCase));; var txEmbedded = args.Any(a => a.Equals("txEmbedded", StringComparison.InvariantCultureIgnoreCase));; var txNotEmbedded = args.Any(a => a.Equals("txNotEmbedded", StringComparison.InvariantCultureIgnoreCase)); /* * var resultTypes = new List<string>(); * resultTypes.AddRange(resultTypes); * resultTypes.AddRange(SenderTests.nodeResultTypes); * resultTypes.AddRange(SenderTests.elem1dResultTypes); * resultTypes.AddRange(SenderTests.elem2dResultTypes); * resultTypes.AddRange(SenderTests.miscResultTypes); */ var TestDataDirectory = AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new[] { '\\' }) + @"\..\..\..\SpeckleStructuralGSA.Test\TestData\"; ReceiverTestPrep receiverTestPrep; if (blankRefs) { receiverTestPrep = new ReceiverTestPrep(TestDataDirectory); receiverTestPrep.SetupContext(); if (!receiverTestPrep.SetUpReceptionTestData(TestBase.savedBlankRefsJsonFileNames, TestBase.expectedBlankRefsGwaPerIdsFileName, GSATargetLayer.Design, "Blank")) { Console.WriteLine("Error in preparing test data for the blank refs rx design layer test"); } else { Console.WriteLine("Prepared reception test data for the blank refs rx design layer test"); } //Don't print any error related to blank references - they're expected PrintAnyErrorMessages((MockGSAMessenger)Initialiser.AppResources.Messenger, new List <string> { "blank" }); } if (rxDesign) { receiverTestPrep = new ReceiverTestPrep(TestDataDirectory); receiverTestPrep.SetupContext(); if (!receiverTestPrep.SetUpReceptionTestData(TestBase.savedJsonFileNames, TestBase.expectedGwaPerIdsFileName, GSATargetLayer.Design, "NB")) { Console.WriteLine("Error in preparing test data for the rx design layer test"); } else { Console.WriteLine("Prepared reception test data for the rx design layer test"); } PrintAnyErrorMessages(Initialiser.AppResources.Messenger); } var senderTestPrep = new SenderTestPrep(TestDataDirectory); if (txDesignBeforeAnalysis) { //First the sender test for design layer data without any results being in the file senderTestPrep.SetupContext(SenderTests.gsaFileNameWithoutResults); Initialiser.AppResources.Settings.StreamSendConfig = StreamContentConfig.ModelOnly; try { if (!senderTestPrep.SetUpTransmissionTestData("TxSpeckleObjectsDesignLayerBeforeAnalysis.json", GSATargetLayer.Design, false, true)) { throw new Exception("Transmission: design layer test preparation failed"); } Console.WriteLine("Prepared test data for the tx design layer before analysis test"); } catch (Exception e) { Console.WriteLine(e.Message); } finally { senderTestPrep.TearDownContext(); } PrintAnyErrorMessages(Initialiser.AppResources.Messenger); } try { if (txDesign) { senderTestPrep.SetupContext(SenderTests.gsaFileNameWithResults); if (!senderTestPrep.SetUpTransmissionTestData("TxSpeckleObjectsDesignLayer.json", GSATargetLayer.Design, false, true)) { throw new Exception("Transmission: design layer test preparation failed"); } Console.WriteLine("Prepared test data for the tx design layer test"); } if (txResultsOnly) { senderTestPrep.SetupContext(SenderTests.gsaFileNameWithResults); if (!senderTestPrep.SetUpTransmissionTestData("TxSpeckleObjectsResultsOnly.json", GSATargetLayer.Analysis, true, false, SenderTests.allResultTypes, SenderTests.loadCases)) //SenderTests.nodeResultTypes, SenderTests.elem1dResultTypes, SenderTests.elem2dResultTypes, SenderTests.miscResultTypes)) { throw new Exception("Transmission: results-only test preparation failed"); } Console.WriteLine("Prepared test data for the tx results-only test"); } if (txEmbedded) { senderTestPrep.SetupContext(SenderTests.gsaFileNameWithResults); if (!senderTestPrep.SetUpTransmissionTestData("TxSpeckleObjectsEmbedded.json", GSATargetLayer.Analysis, false, true, SenderTests.allResultTypes, SenderTests.loadCases)) //SenderTests.nodeResultTypes, SenderTests.elem1dResultTypes, SenderTests.elem2dResultTypes, SenderTests.miscResultTypes)) { throw new Exception("Transmission: embedded test preparation failed"); } Console.WriteLine("Prepared test data for the tx embedded results test"); } if (txNotEmbedded) { senderTestPrep.SetupContext(SenderTests.gsaFileNameWithResults); if (!senderTestPrep.SetUpTransmissionTestData("TxSpeckleObjectsNotEmbedded.json", GSATargetLayer.Analysis, false, false, SenderTests.allResultTypes, SenderTests.loadCases)) //SenderTests.nodeResultTypes, SenderTests.elem1dResultTypes, SenderTests.elem2dResultTypes, SenderTests.miscResultTypes)) { throw new Exception("Transmission: not-embedded test preparation failed"); } Console.WriteLine("Prepared test data for the tx non-embedded results test"); } } catch (Exception e) { Console.WriteLine(e.Message); } finally { senderTestPrep.TearDownContext(); } PrintAnyErrorMessages(Initialiser.AppResources.Messenger); Console.WriteLine("Press any key to exit ..."); Console.ReadKey(); }
public ListMyProjects() : base("Projects", "Projects", "Lists projects you own or have access to", "Speckle", "Management") { SpeckleInitializer.Initialize(); LocalContext.Init(); }
private static void InitialiseKits(out List <string> statusMessages) { statusMessages = new List <string>(); var attributeType = typeof(GSAObject); var interfaceType = typeof(IGSASpeckleContainer); SpeckleInitializer.Initialize(); // Run initialize receiver method in interfacer var assemblies = SpeckleInitializer.GetAssemblies().Where(a => a.GetTypes().Any(t => t.GetInterfaces().Contains(typeof(ISpeckleInitializer)))); var speckleTypes = new List <Type>(); foreach (var assembly in assemblies) { var types = assembly.GetTypes(); foreach (var t in types) { if (typeof(SpeckleObject).IsAssignableFrom(t)) { speckleTypes.Add(t); } } } var mappableTypes = new List <Type>(); foreach (var ass in assemblies) { var types = ass.GetTypes(); Type gsaStatic; try { gsaStatic = types.FirstOrDefault(t => t.GetInterfaces().Contains(typeof(ISpeckleInitializer)) && t.GetProperties().Any(p => p.PropertyType == typeof(IGSACacheForKit))); if (gsaStatic == null) { continue; } } catch { //The kits could throw an exception due to an app-specific library not being linked in (e.g.: the Revit SDK). These libraries aren't of the kind that //would contain the static properties searched for anyway, so just continue. continue; } try { gsaStatic.GetProperty("Interface").SetValue(null, gsaProxy); gsaStatic.GetProperty("Settings").SetValue(null, Settings); gsaStatic.GetProperty("Cache").SetValue(null, gsaCache); gsaStatic.GetProperty("AppUI").SetValue(null, appUi); } catch { Status.AddError($"Unable to fully connect to {ass.GetName().Name}.dll. Please check the versions of the kit you have installed."); } var objTypes = types.Where(t => interfaceType.IsAssignableFrom(t) && t != interfaceType).ToList(); objTypes = objTypes.Distinct().ToList(); foreach (var t in objTypes) { var prereq = t.GetAttribute("WritePrerequisite"); WriteTypePrereqs[t] = (prereq != null) ? ((Type[])prereq).ToList() : new List <Type>(); prereq = t.GetAttribute("ReadPrerequisite"); ReadTypePrereqs[t] = (prereq != null) ? ((Type[])prereq).ToList() : new List <Type>(); } foreach (var t in speckleTypes) { var methods = Helper.GetExtensionMethods(ass, t, "ToNative"); if (methods != null && methods.Count() > 0 && !mappableTypes.Contains(t)) { mappableTypes.Add(t); if (t.BaseType != null && t.BaseType != typeof(SpeckleObject)) { if (!mappableTypes.Contains(t.BaseType)) { mappableTypes.Add(t.BaseType); } } } } } Merger.Initialise(mappableTypes); }