protected override void SolveInstance(IGH_DataAccess DA) { this.subscribeToEvents(); string address = null; string initMsg = "Hello World"; bool reset = false; DA.GetData(0, ref address); if (!DA.GetData(1, ref initMsg)) return; if (!DA.GetData(2, ref reset)) return; if(!this.wsAddress.isSameAs(address) || reset) { this.disconnect(); this.wsAddress.setAddress(address); if (this.wsAddress.isValid()) { this.wscObj = new WsObject().init(address, initMsg); this.Message = "Connecting"; this.wscObj.changed += this.wsObjectOnChange; } else { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid address"); } } DA.SetData(0, this.wscObj); }
}//eof /// <summary> /// This is the method that actually does the work. /// </summary> protected override void SolveInstance(IGH_DataAccess DA) { WsObject wscObj = new WsObject(); string message = "Hello World"; if (!DA.GetData(0, ref wscObj)) return; if (!DA.GetData(1, ref message)) return; wscObj.send(message); }//eof
}//eof /// <summary> /// Disconnect from websocket server. /// This function needs to be run on events such as delete the component. /// </summary> private void disconnect() { if(this.wscObj != null) { try { this.wscObj.disconnect(); } catch { } this.wscObj.changed -= this.wsObjectOnChange; this.wscObj = null; this.wsAddress.setAddress(null); } }
}//eof /// <summary> /// This is the method that actually does the work. /// </summary> protected override void SolveInstance(IGH_DataAccess DA) { DA.GetData(1, ref this.isAutoUpdate); if (this.ghDocument == null) { this.ghDocument = OnPingDocument(); if (this.ghDocument == null) { return; } GH_Document.SolutionEndEventHandler handle = delegate(Object sender, GH_SolutionEventArgs e) { }; ghDocument.SolutionEnd += handle; } if (!this.onMessageTriggered) { WsObject wscObj = new WsObject(); if (DA.GetData(0, ref wscObj)) { if (this.wscObj != wscObj) { this.unsubscribeEventHandlers(); this.wscObj = wscObj; this.subscribeEventHandlers(); } } else { this.unsubscribeEventHandlers(); this.wscObj = null; this.onMessageTriggered = false; return; } } DA.SetData(0, this.wscObj.message); DA.SetData(1, WsObjectStatus.GetStatusName(this.wscObj.status)); this.onMessageTriggered = false; }