public Client(RevitFamilyCollection FamiliesToRespond) { InitializeComponent(); // Prepare the Revit Familytree of the current document for sending this.FamiliesToRespond = Utilities.Serialize(FamiliesToRespond); }
protected override void SolveInstance(IGH_DataAccess DA) { this.Components = new List <object>(); DA.GetDataList <object>("Components", this.Components); GH_Boolean update = new GH_Boolean(true); GH_Boolean erase = new GH_Boolean(false); this.Ip = new GH_String("127.0.0.1"); this.Port = new GH_Integer(8002); this.Timeout = new GH_Integer(10000); DA.GetData <GH_Boolean>("Update", ref update); DA.GetData <GH_String>("IP", ref this.Ip); DA.GetData <GH_Integer>("Port", ref this.Port); DA.GetData <GH_Integer>("TimeOut", ref this.Timeout); GH_Boolean send = new GH_Boolean(); DA.GetData <GH_Boolean>("Send", ref send); DA.GetData <GH_Boolean>("Erase", ref erase); this.Erase = erase.Value; this.Update = update.Value; GH_Number scale = new GH_Number(3.28084); DA.GetData <GH_Number>("Scale", ref scale); this.Scale = scale.Value; if (send.Value) { this.Icon = Properties.Resources.paper_airplane_red; this.DestroyIconCache(); Grasshopper.Instances.RedrawAll(); bool retry = true; string responseData = ""; try { while (retry) { using (TcpClient tcpClient = new TcpClient()) { tcpClient.Connect(IPAddress.Parse(Ip.Value), Port.Value); tcpClient.NoDelay = true; tcpClient.ReceiveTimeout = Timeout.Value; tcpClient.SendTimeout = Timeout.Value; using (NetworkStream stream = tcpClient.GetStream()) { using (StreamWriter writer = new StreamWriter(stream, new UTF8Encoding(false))) { writer.AutoFlush = true; using (StreamReader reader = new StreamReader(stream)) { string line = ComponentsToString(this.Components); writer.WriteLine(line); string response = reader.ReadLine(); if (response == line) { retry = false; } responseData = reader.ReadLine(); } } } } } } catch (Exception ex) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, ex.Message); } try { if (responseData != "") { revitFamilyCollection = (RevitFamilyCollection)Grevit.Serialization.Utilities.Deserialize(responseData, typeof(RevitFamilyCollection)); } } catch (Exception ex) { } this.Icon = Properties.Resources.paper_airplane_green; this.DestroyIconCache(); Grasshopper.Instances.RedrawAll(); } DA.SetDataList("Categories", revitFamilyCollection.Categories); }