public override void DoWork(Action <string, double> ReportProgress, Action Done) { if (CancellationToken.IsCancellationRequested) { return; } int branchIndex = 0, completed = 0; foreach (var list in Objects.Branches) { var path = Objects.Paths[branchIndex]; foreach (var item in list) { if (CancellationToken.IsCancellationRequested) { return; } var converted = Utilities.TryConvertItemToNative(item?.Value, Converter); ConvertedObjects.Append(new GH_ObjectWrapper() { Value = converted }, path); ReportProgress(Id, (completed++ + 1) / (double)Objects.Count()); } branchIndex++; } Done(); }
public override void DoWork(Action <string, double> ReportProgress, Action Done) { Parent.Message = "Receiving..."; var Converter = (Parent as ReceiveLocalComponent).Converter; var @base = Operations.Receive(localDataId).Result; if (Converter.CanConvertToNative(@base)) { var converted = Converter.ConvertToNative(@base); data = new GH_Structure <IGH_Goo>(); data.Append(Utilities.TryConvertItemToNative(converted, Converter)); } else if (@base.GetDynamicMembers().Count() == 1) { var treeBuilder = new TreeBuilder(Converter); var tree = treeBuilder.Build(@base[@base.GetDynamicMembers().ElementAt(0)]); data = tree; } else { data = new GH_Structure <IGH_Goo>(); data.Append(new GH_SpeckleBase(@base)); } Done(); }
private Dictionary <string, object> CreateOutputDictionary(Base @base) { // Create empty data tree placeholders for output. var outputDict = new Dictionary <string, object>(); // Assign all values to it's corresponding dictionary entry and branch path. var obj = @base; if (obj == null) { return(new Dictionary <string, object>()); } foreach (var prop in obj.GetMembers()) { // Convert and add to corresponding output structure var value = prop.Value; //if (!outputDict.ContainsKey(prop.Key)) continue; switch (value) { case null: outputDict[prop.Key] = null; break; case System.Collections.IList list: var result = new List <IGH_Goo>(); foreach (var x in list) { var wrapper = Utilities.TryConvertItemToNative(x, Converter); result.Add(wrapper); } outputDict[prop.Key] = result; break; // TODO: Not clear how we handle "tree" inner props. They can only be set by sender components, // so perhaps this is not an issue. Below a simple stopgap so we can actually see what data is // inside a sender-created object. case Dictionary <string, List <Base> > dict: foreach (var kvp in dict) { IGH_Goo wrapper = new GH_ObjectWrapper(); foreach (var b in kvp.Value) { wrapper = Utilities.TryConvertItemToNative(b, Converter); } outputDict[prop.Key] = wrapper; } break; default: outputDict[prop.Key] = Utilities.TryConvertItemToNative(obj[prop.Key], Converter); break; } } return(outputDict); }
private void AddLeaf(object data, GH_Structure <IGH_Goo> tree) { //paths must have at least one element if (!_path.Any()) { _path.Add(0); } var path = new GH_Path(_path.ToArray()); tree.Append(Utilities.TryConvertItemToNative(data, _converter), path); }
public override void DoWork(Action <string, double> ReportProgress, Action Done) { try { Parent.Message = "Receiving..."; var Converter = (Parent as ReceiveLocalComponent).Converter; Base @base = null; try { @base = Operations.Receive(localDataId).Result; } catch (Exception e) { RuntimeMessages.Add((GH_RuntimeMessageLevel.Warning, "Failed to receive local data.")); Done(); return; } if (Converter.CanConvertToNative(@base)) { var converted = Converter.ConvertToNative(@base); data = new GH_Structure <IGH_Goo>(); data.Append(Utilities.TryConvertItemToNative(converted, Converter)); } else if (@base.GetDynamicMembers().Count() == 1) { var treeBuilder = new TreeBuilder(Converter); var tree = treeBuilder.Build(@base[@base.GetDynamicMembers().ElementAt(0)]); data = tree; } else { data = new GH_Structure <IGH_Goo>(); data.Append(new GH_SpeckleBase(@base)); } } catch (Exception e) { // If we reach this, something happened that we weren't expecting... Log.CaptureException(e); RuntimeMessages.Add((GH_RuntimeMessageLevel.Error, "Something went terribly wrong... " + e.Message)); Parent.Message = "Error"; } Done(); }
protected override void SolveInstance(IGH_DataAccess DA) { // Initialize local variables var speckleObj = new GH_SpeckleBase(); var key = ""; // Get data from inputs if (!DA.GetData(0, ref speckleObj)) { return; } if (!DA.GetData(1, ref key)) { return; } var b = speckleObj.Value; if (b == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Object is not a Speckle object"); return; } // Get the value and output. var value = b[key] ?? b["@" + key]; switch (value) { case null: AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Key not found in object: " + key); return; case List <object> list: { var converted = list.Select( item => new GH_ObjectWrapper(Utilities.TryConvertItemToNative(item, Converter))); DA.SetDataList(0, converted); break; } default: DA.SetData(0, new GH_ObjectWrapper(Utilities.TryConvertItemToNative(value, Converter))); break; } }
private object DoWork(Base @base, string key, CancellationToken token) { object value = null; try { if (token.IsCancellationRequested) { return(null); } var obj = @base[key] ?? @base["@" + key]; switch (obj) { case null: AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Key not found in object: " + key); break; case List <object> list: { value = list.Select( item => Converter != null ? Utilities.TryConvertItemToNative(item, Converter) : item).ToList(); break; } default: value = Converter != null?Utilities.TryConvertItemToNative(obj, Converter) : obj; break; } } catch (Exception e) { // If we reach this, something happened that we weren't expecting... Log.CaptureException(e); AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Something went terribly wrong... " + e.Message); } return(value); }
public override void DoWork(Action <string, double> ReportProgress, Action Done) { try { if (CancellationToken.IsCancellationRequested) { return; } int branchIndex = 0, completed = 0; foreach (var list in Objects.Branches) { var path = Objects.Paths[branchIndex]; foreach (var item in list) { if (CancellationToken.IsCancellationRequested) { return; } var converted = Utilities.TryConvertItemToNative(item?.Value, Converter); ConvertedObjects.Append(converted, path); ReportProgress(Id, (completed++ + 1) / (double)Objects.Count()); } branchIndex++; } Done(); } catch (Exception e) { // If we reach this, something happened that we weren't expecting... Log.CaptureException(e); Parent.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Something went terribly wrong... " + e.Message); Parent.Message = "Error"; } }
private Dictionary <string, GH_Structure <IGH_Goo> > CreateOutputDictionary() { // Create empty data tree placeholders for output. var outputDict = outputList.ToDictionary(outParam => outParam, _ => new GH_Structure <IGH_Goo>()); // Assign all values to it's corresponding dictionary entry and branch path. foreach (var path in speckleObjects.Paths) { if (speckleObjects.get_Branch(path).Count == 0) { continue; } // Loop through all dynamic properties var baseGoo = speckleObjects.get_DataItem(path, 0) as GH_SpeckleBase; if (baseGoo == null) { continue; } var obj = baseGoo.Value; foreach (var prop in obj.GetMembers()) { // Convert and add to corresponding output structure var value = prop.Value; if (!outputDict.ContainsKey(prop.Key)) { continue; } switch (value) { case null: continue; case System.Collections.IList list: var index = 0; foreach (var x in list) { var wrapper = Utilities.TryConvertItemToNative(x, Converter); outputDict[prop.Key].Append(wrapper, path); index++; } break; // TODO: Not clear how we handle "tree" inner props. They can only be set by sender components, // so perhaps this is not an issue. Below a simple stopgap so we can actually see what data is // inside a sender-created object. case Dictionary <string, List <Base> > dict: foreach (var kvp in dict) { IGH_Goo wrapper = new GH_ObjectWrapper(); foreach (var b in kvp.Value) { wrapper = Utilities.TryConvertItemToNative(b, Converter); } outputDict[prop.Key].Append(wrapper, path); } break; default: outputDict[prop.Key].Append( Utilities.TryConvertItemToNative(obj[prop.Key], Converter), path); break; } } } return(outputDict); }