Ejemplo n.º 1
0
        /// <summary>
        /// for testing purpose: it creates an element at the beginning
        /// </summary>
        private void ForTestingPurpose()
        {
            // for testing purpose
            //__________ server's part_________________
            Elements.Caps c = new Elements.Caps(1, "Caps", "Element", 1, 1, "Caps", new Length(0.2, LengthUnit.Meter), new Length(0.5, LengthUnit.Meter), new Length(0.4999, LengthUnit.Meter), new Length(0.5, LengthUnit.Meter), new Length(1, LengthUnit.Meter), new Length(0, LengthUnit.Meter), new Pressure(0, PressureUnit.Bar), "Caps", false);
            //Elements.PipeRectangular c = new Elements.PipeRectangular(1, "PipeRectangular", "Element", 1, 1, "PipeRectangular", "Shape", new Length(0.1, LengthUnit.Meter), new Length(1, LengthUnit.Meter), new Length(0.5, LengthUnit.Meter), new Length(0.5, LengthUnit.Meter));
            //Elements.ElbowCylindrical c = new Elements.ElbowCylindrical(1, "ElbowCylindrical", "Element", 1, 1, new Length(0.1, LengthUnit.Meter), new Length(1, LengthUnit.Meter), new Angle(90, AngleUnit.Degree), new Length(0, LengthUnit.Meter), false, new Length(0, LengthUnit.Meter), new Length(5, LengthUnit.Meter), new Length(0, LengthUnit.Meter), new Angle(0, AngleUnit.Degree), new Angle(0, AngleUnit.Degree));
            //Elements.Cone c = new Elements.Cone(1, "Tube", "Element", 1, 1, new Length(0.1, LengthUnit.Meter), new Length(2, LengthUnit.Meter), new Length(1, LengthUnit.Meter), new Length(2, LengthUnit.Meter), new Angle(0, AngleUnit.Degree), new Length(0, LengthUnit.Meter), new Length(0, LengthUnit.Meter), new Length(0, LengthUnit.Meter), new Length(0, LengthUnit.Meter));
            //Elements.Tube c = new Elements.Tube(1, "Tube", "Element", 1, 1, "tube", new Length(1, LengthUnit.Meter), new Length(0.1, LengthUnit.Meter), new Length(2, LengthUnit.Meter));
            JsonSerializerSettings _jsonSerializerSettingsOCCServer = new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Auto, Formatting = Formatting.Indented
            };

            _jsonSerializerSettingsOCCServer.Converters.Add(new UnitsNetJsonConverter());
            string             json          = JsonConvert.SerializeObject(c, typeof(Elements.BaseElement), _jsonSerializerSettingsOCCServer);
            CommunicateElement messageObject = new CommunicateElement(NetworkComms.NetworkIdentifier, json, c.Designation);

            //__________ client's part_________________
            constructor.AddNewElement(JsonConvert.DeserializeObject <BasicElement>(messageObject.Message, _jsonSerializerSettingsOCC));//*/
        }
Ejemplo n.º 2
0
 /// <summary>
 /// add an object to the construction queue
 /// </summary>
 /// <param name="header">The PacketHeader corresponding with the received object</param>
 /// <param name="connection">The Connection from which this object was received</param>
 /// <param name="incomingMessage">The incoming CommunicateElement we are after</param>
 private void HandleIncomingObject(PacketHeader header, Connection connection, CommunicateElement incomingMessage)
 {
     if (NetworkComms.NetworkIdentifier != connection.ConnectionInfo.NetworkIdentifier) // checks if it is not us messaging ourself
     {
         try
         {
             // adds an object to the construction queue, this is the tricky part
             // it converts your BaseElement object into a cylinder or whatever you want
             //ConstructionQueue.Add(JsonConvert.DeserializeObject<BasicElement>(incomingMessage.Message, _jsonSerializerSettingsOCC));
             constructor.AddNewElement(JsonConvert.DeserializeObject <BasicElement>(incomingMessage.Message, _jsonSerializerSettingsOCC));
             System.IO.File.WriteAllText(@"string.txt", incomingMessage.Message);
         }
         catch (Exception e) { System.IO.File.WriteAllText(@"Debug.txt", e.ToString()); }
     }
     //https://stackoverflow.com/questions/4535840/deserialize-json-object-into-dynamic-object-using-json-net
 }