Exemplo n.º 1
0
 /// <summary>
 /// Deserialize an IfcXml file to an iso_10303_28 object
 /// </summary>
 /// <param name="reader"></param>
 /// <exception cref="XmlException"></exception>
 /// <exception cref="InvalidOperationException"></exception>
 /// <returns></returns>
 public iso_10303 Deserialize(TextReader reader){
     if(reader == null)
         throw new ArgumentNullException("reader");
     
     iso_10303 deserializedUos;
     IfcXmlValidator validator;
     try{
         validator = new IfcXmlValidator( reader );
         
         deserializedUos = (iso_10303)serializer.Deserialize( validator.Reader );
         
     }catch(XmlException xe){
         logger.Error( String.Format(CultureInfo.InvariantCulture, "Deserialize failed: {0}", xe.Message) );
         throw;
     }catch(InvalidOperationException ioe){
         logger.Error(String.Format(CultureInfo.InvariantCulture, "Deserialize failed: {0}", ioe.Message));
         throw;
     }finally{
         reader.Close();
     }
     
     if(!validator.IsValid){
         StringBuilder warningBuilder = new StringBuilder();
         foreach(String warning in validator.Messages){
             warningBuilder.AppendLine( warning );
         }
         throw new XmlException(String.Format(CultureInfo.InvariantCulture, "Not valid IfcXml: {0}", warningBuilder.ToString()));
         
     }
     return deserializedUos;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Deserialize an IfcXml file to an iso_10303_28 object
        /// </summary>
        /// <param name="reader"></param>
        /// <exception cref="XmlException"></exception>
        /// <exception cref="InvalidOperationException"></exception>
        /// <returns></returns>
        public iso_10303 Deserialize(TextReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            iso_10303       deserializedUos;
            IfcXmlValidator validator;

            try{
                validator = new IfcXmlValidator(reader);

                deserializedUos = (iso_10303)serializer.Deserialize(validator.Reader);
            }catch (XmlException xe) {
                logger.Error(String.Format(CultureInfo.InvariantCulture, "Deserialize failed: {0}", xe.Message));
                throw;
            }catch (InvalidOperationException ioe) {
                logger.Error(String.Format(CultureInfo.InvariantCulture, "Deserialize failed: {0}", ioe.Message));
                throw;
            }finally{
                reader.Close();
            }

            if (!validator.IsValid)
            {
                StringBuilder warningBuilder = new StringBuilder();
                foreach (String warning in validator.Messages)
                {
                    warningBuilder.AppendLine(warning);
                }
                throw new XmlException(String.Format(CultureInfo.InvariantCulture, "Not valid IfcXml: {0}", warningBuilder.ToString()));
            }
            return(deserializedUos);
        }
Exemplo n.º 3
0
 public void CanSerialize()
 {
     iso_10303 iso10303   = Utilities.buildMinimumExampleObject();
     
     
     string returnedValue = serializer.SerializeToString(iso10303);
     
     Assert.IsFalse(string.IsNullOrEmpty( returnedValue ) );
     
     //dumping to the console
     logger.Debug( returnedValue );
     
     IfcXmlValidator validator = new IfcXmlValidator( returnedValue );
     Assert.IsTrue( validator.IsValid );
     Assert.AreEqual(ExampleIfcXmlData.getExpectedXmlOutputString(), returnedValue );
 }
Exemplo n.º 4
0
 public void CanRoundTrip()
 {
     iso_10303 initial = Utilities.buildMinimumExampleObject();
     string serialized = serializer.SerializeToString( initial );
     
     //logger.Debug( serialized );
     IfcXmlValidator validator = new IfcXmlValidator( serialized );
     Assert.IsTrue( validator.IsValid );
     
     StringReader reader = new StringReader( serialized );
     iso_10303 returned = serializer.Deserialize( reader );
     
     Utilities.AssertIsMinimumExample( returned );
 }
Exemplo n.º 5
0
 public void CanDetectInvalid()
 {
     validator = new IfcXmlValidator( ExampleIfcXmlData.getFailingMinimumExampleXml() );
     Assert.IsFalse( validator.IsValid );
     Assert.AreEqual(1, validator.Messages.Count);
 }
Exemplo n.º 6
0
 public void CanValidateAlternative()
 {
     validator = new IfcXmlValidator( ExampleIfcXmlData.getAlternativeMinimumExampleXml() );
     Assert.IsTrue( validator.IsValid );
     Assert.AreEqual( 0, validator.Messages.Count );
 }