protected List <SpeckleObject> ModelToSpeckleObjects(GSATargetLayer layer, bool resultsOnly, bool embedResults, string[] cases = null, string[] resultsToSend = null) { gsaCache.Clear(); //Clear out all sender objects that might be there from the last test preparation Initialiser.GSASenderObjects.Clear(); //Compile all GWA commands with application IDs var senderProcessor = new SenderProcessor(TestDataDirectory, gsaInterfacer, gsaCache, layer, embedResults, cases, resultsToSend); var keywords = senderProcessor.GetKeywords(layer); var data = gsaInterfacer.GetGwaData(keywords, false); for (int i = 0; i < data.Count(); i++) { gsaCache.Upsert( data[i].Keyword, data[i].Index, data[i].GwaWithoutSet, //This needs to be revised as this logic is in the kit too applicationId: (string.IsNullOrEmpty(data[i].ApplicationId)) ? ("gsa/" + data[i].Keyword + "_" + data[i].Index.ToString()) : data[i].ApplicationId, gwaSetCommandType: data[i].GwaSetType, streamId: data[i].StreamId ); } senderProcessor.GsaInstanceToSpeckleObjects(layer, out var speckleObjects, resultsOnly); return(speckleObjects); }
private void ConvertSpeckleObjectsToGsaInterfacerCache() { // Write objects var currentBatch = new List <Type>(); var traversedTypes = new List <Type>(); var TypePrerequisites = Helper.GetTypeCastPriority(ioDirection.Receive, GSATargetLayer.Design, false); do { currentBatch = TypePrerequisites.Where(i => i.Value.Count(x => !traversedTypes.Contains(x)) == 0).Select(i => i.Key).ToList(); currentBatch.RemoveAll(i => traversedTypes.Contains(i)); foreach (var t in currentBatch) { var dummyObject = Activator.CreateInstance(t); var keyword = dummyObject.GetAttribute("GSAKeyword").ToString(); var valueType = t.GetProperty("Value").GetValue(dummyObject).GetType(); var speckleTypeName = ((SpeckleObject)((IGSASpeckleContainer)dummyObject).Value).Type; var targetObjects = receivedObjects.Where(o => o.Item2.GetType() == valueType).ToList(); for (var i = 0; i < targetObjects.Count(); i++) { var streamId = targetObjects[i].Item1; var obj = targetObjects[i].Item2; //DESERIALISE var deserialiseReturn = ((string)Converter.Deserialise(obj)); var gwaCommands = deserialiseReturn.Split(new[] { '\n' }).Where(c => c.Length > 0).ToList(); for (var j = 0; j < gwaCommands.Count(); j++) { Initialiser.Interface.ParseGeneralGwa(gwaCommands[j], out keyword, out int?foundIndex, out string foundStreamId, out string foundApplicationId, out string gwaWithoutSet, out GwaSetCommandType? gwaSetCommandType); GSAInterfacer.SetGwa(gwaCommands[j]); //Only cache the object against, the top-level GWA command, not the sub-commands GSACache.Upsert(keyword, foundIndex.Value, gwaWithoutSet, applicationId: foundApplicationId, so: (foundApplicationId == obj.ApplicationId) ? obj : null); } } traversedTypes.Add(t); } } while (currentBatch.Count > 0); }