public void UpdateGlobal( ) { Context.NotifySpeckleFrame("client-log", StreamId, JsonConvert.SerializeObject("Global update received.")); try { var streamGetResponse = Client.StreamGet(StreamId); if (streamGetResponse.Success == false) { Context.NotifySpeckleFrame("client-error", StreamId, streamGetResponse.Message); Context.NotifySpeckleFrame("client-log", StreamId, JsonConvert.SerializeObject("Failed to retrieve global update.")); } Client.Stream = streamGetResponse.Stream; var COPY = Client.Stream; Context.NotifySpeckleFrame("client-metadata-update", StreamId, Client.Stream.ToJson()); Context.NotifySpeckleFrame("client-is-loading", StreamId, ""); // prepare payload PayloadObjectGetBulk payload = new PayloadObjectGetBulk(); payload.Objects = Client.Stream.Objects.Where(o => !Context.SpeckleObjectCache.ContainsKey(o)); // bug in speckle core, no sync method for this :( Client.ObjectGetBulkAsync("omit=displayValue", payload).ContinueWith(tres => { if (tres.Result.Success == false) { Context.NotifySpeckleFrame("client-error", StreamId, streamGetResponse.Message); } var copy = tres.Result; // add to cache foreach (var obj in tres.Result.Objects) { Context.SpeckleObjectCache[obj.DatabaseId] = obj; } // populate real objects Objects.Clear(); foreach (var objId in Client.Stream.Objects) { Objects.Add(Context.SpeckleObjectCache[objId]); } DisplayContents(); Context.NotifySpeckleFrame("client-done-loading", StreamId, ""); }); } catch (Exception err) { Context.NotifySpeckleFrame("client-error", Client.Stream.StreamId, JsonConvert.SerializeObject(err.Message)); Context.NotifySpeckleFrame("client-done-loading", StreamId, ""); return; } }
public virtual void UpdateGlobal( ) { var getStream = myReceiver.StreamGetAsync(myReceiver.StreamId); getStream.Wait(); NickName = getStream.Result.Stream.Name; Layers = getStream.Result.Stream.Layers.ToList(); // TODO: Implement cache // we can safely omit the displayValue, since this is rhino! this.Message = "Getting objects"; PayloadObjectGetBulk payload = new PayloadObjectGetBulk(); payload.Objects = getStream.Result.Stream.Objects.Where(o => !ObjectCache.ContainsKey(o)); myReceiver.ObjectGetBulkAsync("omit=displayValue", payload).ContinueWith(tres => { // add to cache foreach (var x in tres.Result.Objects) { ObjectCache[x.DatabaseId] = x; } // populate real objects SpeckleObjects.Clear(); foreach (var objId in getStream.Result.Stream.Objects) { SpeckleObjects.Add(ObjectCache[objId]); } this.Message = "Converting objects"; ConvertedObjects = SpeckleCore.Converter.Deserialize(SpeckleObjects); if (ConvertedObjects.Count != SpeckleObjects.Count) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Some objects failed to convert."); } this.Message = "Updating..."; UpdateOutputStructure(); Message = "Got data\n@" + DateTime.Now.ToString("hh:mm:ss"); Rhino.RhinoApp.MainApplicationWindow.Invoke(expireComponentAction); }); }