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); }
public void JsonSpeckleStreamsToGwaRecords(IEnumerable <string> savedJsonFileNames, out List <GwaRecord> gwaRecords) { gwaRecords = new List <GwaRecord>(); receivedObjects = JsonSpeckleStreamsToSpeckleObjects(savedJsonFileNames); ScaleObjects(); ConvertSpeckleObjectsToGsaInterfacerCache(); var gwaCommands = GSACache.GetGwaSetCommands(); foreach (var gwaC in gwaCommands) { GSAInterfacer.ParseGeneralGwa(gwaC, out var keyword, out int?index, out var streamId, out var applicationId, out var gwaWithoutSet, out GwaSetCommandType? gwaSetType); gwaRecords.Add(new GwaRecord(string.IsNullOrEmpty(applicationId) ? null : applicationId, gwaC)); } }