public StepFile Deserialize(IStepReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } StepFile step = new StepFile(); while (reader.Read()) { switch (reader.TokenType) { case StepToken.EntityName: step.Header.Add(deserializeEntity(reader)); continue; case StepToken.LineIdentifier: int objectNumber = getObjectNumber(reader); step.Data.Add(objectNumber, deserializeEntity(reader)); continue; default: continue; } } //TODO should try to create the tree here. Need to handle circular references though. return(step); }
public void CanReadSmallWallExample() { SUT = this.createStepReader( ExampleData.StepIFC2X3SmallWallExample() ); int count = 0; while(SUT.Read()){ count++; } Assert.AreEqual(StepToken.EndSTEP, SUT.TokenType); Assert.AreEqual(1927, count ); }
public void CanReadSmallWallExample() { SUT = this.createStepReader(ExampleData.StepIFC2X3SmallWallExample()); int count = 0; while (SUT.Read()) { count++; } Assert.AreEqual(StepToken.EndSTEP, SUT.TokenType); Assert.AreEqual(1927, count); }
/// <summary> /// /// </summary> /// <returns></returns> private StepValue deserializeArray(IStepReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } IList <StepValue> values = new List <StepValue>(); while (reader.Read()) { logger.Debug(String.Format(CultureInfo.InvariantCulture, "deserializeArray read : {0} of value {1}", reader.TokenType, reader.Value)); switch (reader.TokenType) { case StepToken.EndArray: return(StepValue.CreateArray(values)); case StepToken.LineReference: values.Add(deserializeLineReference(reader)); continue; case StepToken.Enumeration: case StepToken.Boolean: case StepToken.Integer: case StepToken.Float: case StepToken.String: values.Add(deserializeProperty(reader)); continue; case StepToken.Null: values.Add(deserializeNull()); continue; case StepToken.EntityName: case StepToken.StartEntity: values.Add(deserializeNestedEntity(reader)); continue; case StepToken.Operator: case StepToken.Overridden: case StepToken.EndEntity: case StepToken.EndLine: case StepToken.EndSection: case StepToken.EndSTEP: case StepToken.StartSTEP: case StepToken.StartSection: throw new StepSerializerException(String.Format(CultureInfo.InvariantCulture, "deserializeArray found a token which was not expected: {0}", reader.TokenType)); default: throw new NotImplementedException(String.Format(CultureInfo.InvariantCulture, "This ExpressToken type is not yet implemented by deserializeArray(), {0}", reader.TokenType)); } } throw new StepSerializerException("deserializeArray() reached the end of the reader without finding an endArray token"); }
/// <summary> /// Attempts to read a nested entity /// </summary> /// <param name="reader"></param> /// <returns></returns> private StepDataObject deserializeEntity(IStepReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } StepDataObject edo = new StepDataObject(); bool entityStarted = false; //nested entities are already on the EntityName token if (reader.TokenType == StepToken.EntityName) { edo.ObjectName = getObjectName(reader); } while (reader.Read()) { logger.Debug(String.Format(CultureInfo.InvariantCulture, "deserializer read token {0}. value {1}", reader.TokenType, reader.Value)); switch (reader.TokenType) { case StepToken.EntityName: if (!entityStarted) { edo.ObjectName = getObjectName(reader); } else //it's a nested entity { edo.Properties.Add(deserializeNestedEntity(reader)); } continue; case StepToken.LineReference: edo.Properties.Add(deserializeLineReference(reader)); continue; case StepToken.Enumeration: case StepToken.Boolean: case StepToken.Integer: case StepToken.Float: case StepToken.String: case StepToken.Date: edo.Properties.Add(deserializeProperty(reader)); continue; case StepToken.StartArray: edo.Properties.Add(deserializeArray(reader)); continue; case StepToken.StartEntity: if (!entityStarted) { entityStarted = true; } else { throw new StepSerializerException(String.Format(CultureInfo.InvariantCulture, "A token was found which was not expected: {0}", reader.TokenType)); } continue; case StepToken.Operator: case StepToken.Comment: continue; case StepToken.Overridden: edo.Properties.Add(deserializeOverridden()); continue; case StepToken.Null: edo.Properties.Add(deserializeNull()); continue; case StepToken.EndEntity: return(edo); case StepToken.EndLine: case StepToken.EndSection: case StepToken.EndSTEP: case StepToken.StartSTEP: case StepToken.StartSection: throw new StepSerializerException(String.Format(CultureInfo.InvariantCulture, "A token was found which was not expected: {0}", reader.TokenType)); default: throw new NotImplementedException(String.Format(CultureInfo.InvariantCulture, "The {0} ExpressToken type is not yet implemented by deserializeEntity()", reader.TokenType)); } //TODO should do some verification here (properties are after entityStart and before EntityEnd etc.) } throw new StepSerializerException("The reader reached the end without finding an endEntity token"); }
public StepFile Deserialize(IStepReader reader) { if( reader == null ) throw new ArgumentNullException( "reader" ); StepFile step = new StepFile(); while(reader.Read()){ switch(reader.TokenType){ case StepToken.EntityName: step.Header.Add( deserializeEntity( reader ) ); continue; case StepToken.LineIdentifier: int objectNumber = getObjectNumber( reader ); step.Data.Add( objectNumber, deserializeEntity( reader ) ); continue; default: continue; } } //TODO should try to create the tree here. Need to handle circular references though. return step; }
/// <summary> /// /// </summary> /// <returns></returns> private StepValue deserializeArray(IStepReader reader){ if(reader == null) throw new ArgumentNullException("reader"); IList<StepValue> values = new List<StepValue>(); while(reader.Read()){ logger.Debug(String.Format(CultureInfo.InvariantCulture, "deserializeArray read : {0} of value {1}", reader.TokenType, reader.Value)); switch(reader.TokenType){ case StepToken.EndArray: return StepValue.CreateArray(values); case StepToken.LineReference: values.Add(deserializeLineReference(reader)); continue; case StepToken.Enumeration: case StepToken.Boolean: case StepToken.Integer: case StepToken.Float: case StepToken.String: values.Add(deserializeProperty(reader)); continue; case StepToken.Null: values.Add(deserializeNull()); continue; case StepToken.EntityName: case StepToken.StartEntity: values.Add(deserializeNestedEntity(reader)); continue; case StepToken.Operator: case StepToken.Overridden: case StepToken.EndEntity: case StepToken.EndLine: case StepToken.EndSection: case StepToken.EndSTEP: case StepToken.StartSTEP: case StepToken.StartSection: throw new StepSerializerException( String.Format(CultureInfo.InvariantCulture, "deserializeArray found a token which was not expected: {0}", reader.TokenType)); default: throw new NotImplementedException(String.Format(CultureInfo.InvariantCulture, "This ExpressToken type is not yet implemented by deserializeArray(), {0}", reader.TokenType)); } } throw new StepSerializerException( "deserializeArray() reached the end of the reader without finding an endArray token" ); }
/// <summary> /// Attempts to read a nested entity /// </summary> /// <param name="reader"></param> /// <returns></returns> private StepDataObject deserializeEntity(IStepReader reader){ if(reader == null) throw new ArgumentNullException( "reader" ); StepDataObject edo = new StepDataObject(); bool entityStarted = false; //nested entities are already on the EntityName token if(reader.TokenType == StepToken.EntityName) edo.ObjectName = getObjectName(reader); while(reader.Read()){ logger.Debug(String.Format(CultureInfo.InvariantCulture, "deserializer read token {0}. value {1}", reader.TokenType, reader.Value)); switch(reader.TokenType){ case StepToken.EntityName: if(!entityStarted) edo.ObjectName = getObjectName( reader ); else //it's a nested entity edo.Properties.Add( deserializeNestedEntity( reader ) ); continue; case StepToken.LineReference: edo.Properties.Add(deserializeLineReference( reader )); continue; case StepToken.Enumeration: case StepToken.Boolean: case StepToken.Integer: case StepToken.Float: case StepToken.String: case StepToken.Date: edo.Properties.Add(deserializeProperty( reader )); continue; case StepToken.StartArray: edo.Properties.Add(deserializeArray( reader )); continue; case StepToken.StartEntity: if(!entityStarted) entityStarted = true; else throw new StepSerializerException(String.Format(CultureInfo.InvariantCulture, "A token was found which was not expected: {0}", reader.TokenType)); continue; case StepToken.Operator: case StepToken.Comment: continue; case StepToken.Overridden: edo.Properties.Add(deserializeOverridden()); continue; case StepToken.Null: edo.Properties.Add(deserializeNull()); continue; case StepToken.EndEntity: return edo; case StepToken.EndLine: case StepToken.EndSection: case StepToken.EndSTEP: case StepToken.StartSTEP: case StepToken.StartSection: throw new StepSerializerException(String.Format(CultureInfo.InvariantCulture, "A token was found which was not expected: {0}", reader.TokenType)); default: throw new NotImplementedException(String.Format(CultureInfo.InvariantCulture, "The {0} ExpressToken type is not yet implemented by deserializeEntity()", reader.TokenType)); } //TODO should do some verification here (properties are after entityStart and before EntityEnd etc.) } throw new StepSerializerException( "The reader reached the end without finding an endEntity token" ); }
public void CanReadSimple() { createSUT(ExampleData.simpleStepWithCommentString()); //read Iso declaration Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.StartSTEP, SUT.TokenType); Assert.AreEqual("ISO-10303-21", SUT.Value); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndLine, SUT.TokenType); //read header section definition Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.StartSection, SUT.TokenType); Assert.AreEqual("HEADER", SUT.Value); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndLine, SUT.TokenType); //read file description name Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EntityName, SUT.TokenType); Assert.AreEqual("FILE_DESCRIPTION", SUT.Value); //read start of file_description object Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.StartEntity, SUT.TokenType); Assert.IsNull(SUT.Value); //read start of array Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.StartArray, SUT.TokenType); Assert.IsNull(SUT.Value); //read only value in array Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.String, SUT.TokenType); Assert.AreEqual("ViewDefinition [CoordinationView, QuantityTakeOffAddOnView]", SUT.Value); //read end of array Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndArray, SUT.TokenType); Assert.IsNull(SUT.Value); //read implementation level Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.String, SUT.TokenType); Assert.AreEqual("2;1", SUT.Value); //read close of entity Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndEntity, SUT.TokenType); Assert.IsNull(SUT.Value); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndLine, SUT.TokenType); //read file_name function name Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EntityName, SUT.TokenType); Assert.AreEqual("FILE_NAME", SUT.Value); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.StartEntity, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.String, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.Date, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.StartArray, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.String, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndArray, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndEntity, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndLine, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EntityName, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.StartEntity, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.StartArray, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.String, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndArray, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndEntity, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndLine, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndSection, SUT.TokenType); Assert.AreEqual("ENDSEC", SUT.Value); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndLine, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.StartSection, SUT.TokenType); Assert.AreEqual("DATA", SUT.Value); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndLine, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.LineIdentifier, SUT.TokenType); Assert.AreEqual("#1", SUT.Value); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.Operator, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EntityName, SUT.TokenType); Assert.AreEqual("IFCPROJECT", SUT.Value); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.StartEntity, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.String, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.LineReference, SUT.TokenType); Assert.AreEqual("#2", SUT.Value); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.String, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.String, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.Null, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.Float, SUT.TokenType); Assert.AreEqual(-22.4, SUT.Value); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.Null, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.StartArray, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.LineReference, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndArray, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.LineReference, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndEntity, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndLine, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.Comment, SUT.TokenType); Assert.AreEqual(" a comment ", SUT.Value); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.LineIdentifier, SUT.TokenType); Assert.AreEqual("#2", SUT.Value); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.Operator, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EntityName, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.StartEntity, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.LineReference, SUT.TokenType); Assert.AreEqual("#3", SUT.Value); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EntityName, SUT.TokenType); Assert.AreEqual("IFCTEXT", SUT.Value); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.StartEntity, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.String, SUT.TokenType); Assert.AreEqual("foobar", SUT.Value); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndEntity, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.Null, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.Enumeration, SUT.TokenType); Assert.AreEqual("ADDED", SUT.Value); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.Null, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.Boolean, SUT.TokenType); Assert.AreEqual(false, SUT.Value); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.Overridden, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.Integer, SUT.TokenType); Assert.AreEqual(1217620436, SUT.Value); Assert.AreEqual(typeof(int), SUT.ValueType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndEntity, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndLine, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndSection, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndLine, SUT.TokenType); Assert.IsTrue(SUT.Read()); Assert.AreEqual(StepToken.EndSTEP, SUT.TokenType); Assert.IsFalse(SUT.Read()); }