public static SpeckleObject ToSpeckle(this GSAMiscResult dummyObject) { var keyword = typeof(GSAAssembly).GetGSAKeyword(); var loadTaskKw = GsaRecord.GetKeyword<GsaLoadCase>(); var comboKw = GsaRecord.GetKeyword<GsaCombination>(); var typeName = dummyObject.GetType().Name; var axisStr = Initialiser.AppResources.Settings.ResultInLocalAxis ? "local" : "global"; //var resultTypes = Initialiser.AppResources.Settings.MiscResults.Keys.Where(r => r.ToLower().Contains("assembly")).ToList(); var cases = Initialiser.AppResources.Settings.ResultCases; //if (resultTypes.Count() == 0 if (Initialiser.AppResources.Settings.ResultTypes == null || !Initialiser.AppResources.Settings.ResultTypes.Contains(ResultType.AssemblyForcesAndMoments) || !Initialiser.AppResources.Cache.GetKeywordRecordsSummary(keyword, out var gwa, out var indices, out var applicationIds)) { return new SpeckleNull(); } var gsaMiscResults = new List<GSAMiscResult>(); var gsaMiscResultsLock = new object(); Initialiser.AppResources.Proxy.LoadResults(ResultGroup.Assembly, out int numErrorRows, cases, indices); if (numErrorRows > 0) { Initialiser.AppResources.Messenger.Message(MessageIntent.Display, MessageLevel.Error, "Unable to process " + numErrorRows + " rows of assembly results"); Initialiser.AppResources.Messenger.Message(MessageIntent.TechnicalLog, MessageLevel.Error, "Unable to process " + numErrorRows + " rows of assembly results"); } #if DEBUG for (int i = 0; i < indices.Count(); i++) #else Parallel.For(0, indices.Count, i => #endif { var entity = indices[i]; var applicationId = applicationIds[i]; try { if (Initialiser.AppResources.Proxy.GetResultHierarchy(ResultGroup.Assembly, entity, out var results) && results != null) { var orderedLoadCases = results.Keys.OrderBy(k => k).ToList(); foreach (var loadCase in orderedLoadCases) { if (!SchemaConversion.Helper.FilterResults(results[loadCase], out var sendableResults)) { continue; } var miscResult = new StructuralMiscResult() { IsGlobal = !Initialiser.AppResources.Settings.ResultInLocalAxis, Value = sendableResults, TargetRef = applicationId }; var loadCaseRef = SchemaConversion.Helper.GsaCaseToRef(loadCase, loadTaskKw, comboKw); if (!string.IsNullOrEmpty(loadCaseRef)) { miscResult.LoadCaseRef = loadCase; } lock (gsaMiscResultsLock) { gsaMiscResults.Add(new GSAMiscResult { Value = miscResult, GSAId = entity }); } } } } catch (Exception ex) { var contextDesc = string.Join(" ", typeName, entity); Initialiser.AppResources.Messenger.Message(MessageIntent.TechnicalLog, MessageLevel.Error, ex, contextDesc, i.ToString()); } } #if !DEBUG ); #endif Initialiser.AppResources.Proxy.ClearResults(ResultGroup.Assembly); if (gsaMiscResults.Count > 0) { Initialiser.GsaKit.GSASenderObjects.AddRange(gsaMiscResults); } return new SpeckleObject(); }
public static SpeckleObject ToSpeckle(this GSAMiscResult dummyObject) { var keyword = typeof(GSAAssembly).GetGSAKeyword(); var typeName = dummyObject.GetType().Name; var axisStr = Initialiser.AppResources.Settings.ResultInLocalAxis ? "local" : "global"; if (Initialiser.AppResources.Settings.MiscResults.Count() == 0 || !Initialiser.AppResources.Cache.GetKeywordRecordsSummary(keyword, out var gwa, out var indices, out var applicationIds)) { return(new SpeckleNull()); } var results = new List <GSAMiscResult>(); //Unlike embedding, separate results doesn't necessarily mean that there is a Speckle object created for each assembly. There is always though //some GWA loaded into the cache foreach (var kvp in Initialiser.AppResources.Settings.MiscResults) { foreach (var loadCase in Initialiser.AppResources.Settings.ResultCases.Where(rc => Initialiser.AppResources.Proxy.CaseExist(rc))) { for (var i = 0; i < indices.Count(); i++) { try { var resultExport = Initialiser.AppResources.Proxy.GetGSAResult(indices[i], kvp.Value.Item2, kvp.Value.Item3, kvp.Value.Item4, loadCase, axisStr); if (resultExport == null || resultExport.Count() == 0) { continue; } var targetRef = (string.IsNullOrEmpty(applicationIds[i])) ? Helper.GetApplicationId(keyword, indices[i]) : applicationIds[i]; var existingRes = results.FirstOrDefault(x => x.Value.TargetRef == targetRef && x.Value.LoadCaseRef == loadCase); if (existingRes == null) { var newRes = new StructuralMiscResult { Description = kvp.Key, IsGlobal = !Initialiser.AppResources.Settings.ResultInLocalAxis, Value = resultExport, LoadCaseRef = loadCase, TargetRef = string.IsNullOrEmpty(applicationIds[i]) ? Helper.GetApplicationId(keyword, indices[i]) : applicationIds[i] }; newRes.GenerateHash(); results.Add(new GSAMiscResult() { Value = newRes, GSAId = indices[i] }); } else { existingRes.Value.Value[kvp.Key] = resultExport; } } catch (Exception ex) { var contextDesc = string.Join(" ", typeName, kvp.Key, loadCase); Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.Display, MessageLevel.Error, contextDesc, i.ToString()); Initialiser.AppResources.Messenger.CacheMessage(MessageIntent.TechnicalLog, MessageLevel.Error, ex, contextDesc, i.ToString()); } } } } Initialiser.GsaKit.GSASenderObjects.AddRange(results); return(new SpeckleObject()); }