}// end:CopyStream() public static void WriteToByte(InstanceDB DataSet) { Stream bstr = File.Create(@"c:\cpd\a.cpd"); BinaryWriter binWriter = new BinaryWriter(bstr, Encoding.ASCII); //for (int i = 0; i < DataSet.aDataSectionList.Count; i++) //{ //DataSection aDataSection = DataSet.aDataSectionList[i]; //for (int j = 0; j < aDataSection.DataList.Count; j++) //{ // WriteInstance(aDataSection.DataList.GetByIndex(j), binWriter, DataSet); //} foreach (KeyValuePair <uint, Instance> kvp in DataSet.DataList) { WriteInstance(kvp.Value, binWriter, DataSet); } //} //FileStream outfile = File.Create(@"c:\a.cpz"); //GZipStream compress = new GZipStream(bstr, CompressionMode.Compress); //bstr.CopyTo(compress); //compress.Close(); //outfile.Close(); bstr.Close(); // ZipFile(); //Compress(new FileInfo(@"c:\a.cpd")); }
public static void WriteSerializedInstances(InstanceDB DataSet) { Stream str = File.Create(@"c:\cpdsample\aSerialized.bin"); BinaryFormatter bf = new BinaryFormatter(); bf.Context = new StreamingContext(StreamingContextStates.CrossAppDomain); bf.Serialize(str, DataSet); str.Close(); }
public static void WriteCompressedSerializedInstances(InstanceDB DataSet) { Stream str = File.Create(@"c:\cpdsample\CompressedSerialized.bgz"); GZipStream compressor = new GZipStream(str, CompressionMode.Compress); BinaryFormatter bf = new BinaryFormatter(); bf.Context = new StreamingContext(StreamingContextStates.CrossAppDomain); bf.Serialize(compressor, DataSet); compressor.Close(); str.Close(); }
public static InstanceDB ReadCompressedSerialization() { Stream str = File.OpenRead(@"c:\cpd\a.bgz"); GZipStream decompressor = new GZipStream(str, CompressionMode.Decompress); BinaryFormatter bf = new BinaryFormatter(); //P21Data aData = (P21Data)bf.Deserialize(str); InstanceDB aData = (InstanceDB)bf.Deserialize(decompressor); decompressor.Close(); str.Close(); return(aData); }
public ParamEntity(uint value, InstanceDB DataSet) : base(SParamType.ENTITY) { // this fucntion only works with SimpleInstance Populations if (DataSet.DataList.ContainsKey(value)) { EntityInstance = DataSet.DataList[value]; } else { EntityInstance = new InstanceSimple(value); DataSet.DataList.Add((uint)value, EntityInstance); } }
public static void TestWriter() { var instanceDB = new InstanceDB(); var simpleRecord = new SimpleRecord("IFCORGANIZATION", instanceDB); simpleRecord.ParameterList.Add(new ParamNullValue()); simpleRecord.ParameterList.Add(new ParamString("Georgia Tech")); simpleRecord.ParameterList.Add(new ParamNullValue()); simpleRecord.ParameterList.Add(new ParamNullValue()); simpleRecord.ParameterList.Add(new ParamNullValue()); var instanceSimple = new InstanceSimple(10); instanceSimple.Record = simpleRecord; instanceDB.DataList.Add(instanceSimple.EntityInstanceName, instanceSimple); }
public static void WriteInstance(Instance aInstance, StreamWriter strWriter, InstanceDB DataSet, bool IsDictionaryType) { strWriter.Write('#'); strWriter.Write(aInstance.EntityInstanceName.ToString()); strWriter.Write('='); if (aInstance is InstanceSimple) { WriteSimpleRecord(((InstanceSimple)aInstance).Record, strWriter, DataSet, IsDictionaryType); } else if (aInstance is InstanceComplex) { } else { } strWriter.WriteLine(";"); }
/// <summary> /// Write out regular p21 file /// </summary> /// <param name="DataSet"></param> /// <param name="FileName"></param> public static void WriteP21File(InstanceDB DataSet, string FileName, bool IsDictionaryType) { using (StreamWriter aFile = new StreamWriter(FileName)) { if (IsDictionaryType) { aFile.WriteLine(DICTIONARYstr); for (int i = 0; i < DataSet.KeywordDic.Count; i++) { aFile.WriteLine("@{0}={1}", i, DataSet.KeywordDic[i]); } aFile.WriteLine(ENDSECstr); } aFile.WriteLine(ISOstr); aFile.WriteLine(HEADERstr); for (int i = 0; i < DataSet.HeaderList.Count; i++) { WriteSimpleRecord(DataSet.HeaderList[i], aFile, DataSet, false); aFile.Write(";\n"); } aFile.WriteLine(ENDSECstr); //for (int i = 0; i < DataSet.aDataSectionList.Count; i++) //{ aFile.WriteLine(DATAstr); //DataSection aDataSection = DataSet.aDataSectionList[i]; //for (int j = 0; j < aDataSection.DataList.Count; j++) //{ // WriteInstance(aDataSection.DataList, aFile, DataSet); //} foreach (KeyValuePair <uint, Instance> kvp in DataSet.DataList) { WriteInstance(kvp.Value, aFile, DataSet, IsDictionaryType); } aFile.WriteLine(ENDSECstr); //} aFile.WriteLine(ENDISOstr); //aFile.Close(); } }
public ParamEnum(string value, InstanceDB DataSet) : base(SParamType.ENUMERATION) { p_EnumValueInt = DataSet.AddKeyword(value); p_EnumValueString = value; }
/// <summary>( /// IFC MODEL Reader /// </summary> /// <param name="p21FileName">Filename to read</param> private EarlyBindingInstanceModel(string p21FileName) : this() { var model = new InstanceDB(p21FileName); ConvertToEarlyBinding(model); }
public string GetStringValue(InstanceDB DataSet) { return(DataSet.GetKeyword(p_EnumValueInt)); }
public static void WriteSimpleRecord(SimpleRecord aRecord, StreamWriter strWriter, InstanceDB DataSet, bool IsDictionaryType) { if (IsDictionaryType) { strWriter.Write("@{0}", aRecord.IntKeyword.ToString()); } else { //strWriter.Write(DataSet.GetKeyword((int)aRecord.IntKeyword)); strWriter.Write(aRecord.Keyword); } //byte[] aTemp = BitConverter.GetBytes('('); strWriter.Write('('); for (int i = 0; i < aRecord.ParameterList.Count; i++) { if (i > 0) { strWriter.Write(','); } WriteParameter(aRecord.ParameterList[i], strWriter, DataSet, IsDictionaryType); } strWriter.Write(')'); }
public static void WriteParameter(Parameter aParameter, BinaryWriter aBinaryWriter, InstanceDB DataSet) { //if (aParameter.ParameterTypeValue == ParameterType.ENTITY_INSTANCE_NAME) if (aParameter is ParamEntity) { aBinaryWriter.Write('#'); aBinaryWriter.Write(((ParamEntity)aParameter).EntityInstance.EntityInstanceName.ToString()); } //else if (aParameter.ParameterTypeValue == ParameterType.INTEGER) else if (aParameter is ParamInteger) { aBinaryWriter.Write(BitConverter.GetBytes(((ParamInteger)aParameter).IntegerValue)); } //else if (aParameter.ParameterTypeValue == ParameterType.ENUMERATION) else if (aParameter is ParamEnum) { aBinaryWriter.Write('.'); aBinaryWriter.Write(((ParamEnum)aParameter).EnumerationValueString); aBinaryWriter.Write('.'); } else if (aParameter is ParamNullValue) { aBinaryWriter.Write('$'); } else if (aParameter is ParamOmitted) { aBinaryWriter.Write('*'); } else if (aParameter is ParamString) { aBinaryWriter.Write('\''); aBinaryWriter.Write(((ParamString)aParameter).StringValue); aBinaryWriter.Write('\''); } else if (aParameter is ParamReal) { aBinaryWriter.Write(BitConverter.GetBytes(((ParamReal)aParameter).RealValue)); } else if (aParameter is ParamList) { aBinaryWriter.Write('('); for (int i = 0; i < ((ParamList)aParameter).ParameterList.Count; i++) { if (i > 0) { aBinaryWriter.Write(','); } WriteParameter(((ParamList)aParameter).ParameterList[i], aBinaryWriter, DataSet); } aBinaryWriter.Write(')'); } else if (aParameter is ParamSelect) { //WriteSimpleRecord(((ParamSelect)aParameter).TypedParameterValue, aBinaryWriter, DataSet); aBinaryWriter.Write( string.Format("{0}({1})", ((ParamSelect)aParameter).SelectName, ((ParamSelect)aParameter).SelectValue)); } }
public static void WriteParameter(Parameter aParameter, StreamWriter strWriter, InstanceDB DataSet, bool IsDictionaryType) { if (aParameter is ParamEntity) { strWriter.Write('#'); strWriter.Write(((ParamEntity)aParameter).EntityInstance.EntityInstanceName.ToString()); } else if (aParameter is ParamInteger) { strWriter.Write(((ParamInteger)aParameter).IntegerValue.ToString()); } else if (aParameter is ParamEnum) { //strWriter.Write('.'); //strWriter.Write(aParameter.StringValue); //((EnumerationParameter)aParameter).GetStringValue(DataSet) if (IsDictionaryType) { strWriter.Write("@{0}", ((ParamEnum)aParameter).EnumerationValueInt); } else { strWriter.Write("@{0}", ((ParamEnum)aParameter).EnumerationValueString); } //strWriter.Write('.'); } else if (aParameter is ParamNullValue) { strWriter.Write('$'); } else if (aParameter is ParamOmitted) { strWriter.Write('*'); } else if (aParameter is ParamString) { strWriter.Write('\''); strWriter.Write(((ParamString)aParameter).StringValue); strWriter.Write('\''); } else if (aParameter is ParamReal) { int front = (int)((ParamReal)aParameter).RealValue; double remain = ((ParamReal)aParameter).RealValue - front; if (remain == 0.0) { strWriter.Write("{0}.", ((ParamReal)aParameter).RealValue.ToString()); } else { strWriter.Write("{0}", ((ParamReal)aParameter).RealValue.ToString("G", CultureInfo.InvariantCulture)); } } else if (aParameter is ParamList) { strWriter.Write('('); for (int i = 0; i < ((ParamList)aParameter).ParameterList.Count; i++) { if (i > 0) { strWriter.Write(','); } WriteParameter(((ParamList)aParameter).ParameterList[i], strWriter, DataSet, IsDictionaryType); } strWriter.Write(')'); } else if (aParameter is ParamSelect) { //WriteSimpleRecord(((ParamSelect)aParameter).TypedParameterValue, strWriter, DataSet, IsDictionaryType); strWriter.Write( string.Format("{0}({1})", ((ParamSelect)aParameter).SelectName, ((ParamSelect)aParameter).SelectValue)); } else if (aParameter is ParamBoolean) { strWriter.Write("{0}.", ((ParamBoolean)aParameter).BoolValue.ToString()); } else { throw new NotImplementedException(); } }
public static void WriteInstance(Instance aInstance, BinaryWriter aBinaryWriter, InstanceDB DataSet) { aBinaryWriter.Write('#'); aBinaryWriter.Write(aInstance.EntityInstanceName.ToString()); aBinaryWriter.Write('='); if (aInstance is InstanceSimple) { WriteSimpleRecord(((InstanceSimple)aInstance).Record, aBinaryWriter, DataSet); } else if (aInstance is InstanceComplex) { } else { } aBinaryWriter.Write(BitConverter.GetBytes(';')); }
public static void WriteSimpleRecord(SimpleRecord aRecord, BinaryWriter aBinaryWriter, InstanceDB DataSet) { //aBinaryWriter.Write(DataSet.GetKeyword((int)aRecord.IntKeyword)); aBinaryWriter.Write(aRecord.Keyword); //aBinaryWriter.Write(aRecord.GetKeyword(DataSet)); //byte[] aTemp = BitConverter.GetBytes('('); aBinaryWriter.Write('('); for (int i = 0; i < aRecord.ParameterList.Count; i++) { if (i > 0) { aBinaryWriter.Write(','); } WriteParameter(aRecord.ParameterList[i], aBinaryWriter, DataSet); } aBinaryWriter.Write(')'); }
/// <summary> /// use this function /// </summary> /// <param name="sData"></param> /// <param name="instanceDb"></param> private void AssignEntityDefToInstance(SData sData, InstanceDB instanceDb) { foreach (KeyValuePair<uint, Instance> kvp in instanceDb.DataList) { if (kvp.Value is InstanceSimple) { var sInstance = kvp.Value as InstanceSimple; var sEntity = sData.EntityList[sInstance.Keyword]; AddSimpleDef(sInstance, sEntity); } else if (kvp.Value is InstanceComplex) { // need to implement } else { throw new InvalidDataException( string.Format("Undefined instantiation of instance at {0} : {1}", kvp.Value.EntityInstanceName, kvp.Value.Keyword)); } } }
/// <summary> /// Write out regular p21 file /// </summary> /// <param name="DataSet"></param> /// <param name="FileName"></param> public static void WriteP21File(InstanceDB DataSet, string FileName, bool IsDictionaryType) { using (StreamWriter aFile = new StreamWriter(FileName)) { if (IsDictionaryType) { aFile.WriteLine(DICTIONARYstr); for (int i = 0; i < DataSet.KeywordDic.Count; i++) { aFile.WriteLine("@{0}={1}", i, DataSet.KeywordDic[i]); } aFile.WriteLine(ENDSECstr); } aFile.WriteLine(ISOstr); aFile.WriteLine(HEADERstr); for (int i = 0; i < DataSet.HeaderList.Count; i++) { WriteSimpleRecord(DataSet.HeaderList[i], aFile, DataSet, false); aFile.Write(";\n"); } aFile.WriteLine(ENDSECstr); //for (int i = 0; i < DataSet.aDataSectionList.Count; i++) //{ aFile.WriteLine(DATAstr); //DataSection aDataSection = DataSet.aDataSectionList[i]; //for (int j = 0; j < aDataSection.DataList.Count; j++) //{ // WriteInstance(aDataSection.DataList, aFile, DataSet); //} foreach (KeyValuePair<uint, Instance> kvp in DataSet.DataList) { WriteInstance(kvp.Value, aFile, DataSet, IsDictionaryType); } aFile.WriteLine(ENDSECstr); //} aFile.WriteLine(ENDISOstr); //aFile.Close(); } }
public ParamEntRef(uint value, InstanceDB DataSet) : base(value, DataSet) { }
public static void WriteParameter(Parameter aParameter, StreamWriter strWriter, InstanceDB DataSet, bool IsDictionaryType) { if (aParameter is ParamEntity) { strWriter.Write('#'); strWriter.Write(((ParamEntity)aParameter).EntityInstance.EntityInstanceName.ToString()); } else if (aParameter is ParamInteger) { strWriter.Write(((ParamInteger)aParameter).IntegerValue.ToString()); } else if (aParameter is ParamEnum) { //strWriter.Write('.'); //strWriter.Write(aParameter.StringValue); //((EnumerationParameter)aParameter).GetStringValue(DataSet) if (IsDictionaryType) { strWriter.Write("@{0}", ((ParamEnum)aParameter).EnumerationValueInt); } else { strWriter.Write("@{0}", ((ParamEnum)aParameter).EnumerationValueString); } //strWriter.Write('.'); } else if (aParameter is ParamNullValue) { strWriter.Write('$'); } else if (aParameter is ParamOmitted) { strWriter.Write('*'); } else if (aParameter is ParamString) { strWriter.Write('\''); strWriter.Write(((ParamString)aParameter).StringValue); strWriter.Write('\''); } else if (aParameter is ParamReal) { int front = (int)((ParamReal)aParameter).RealValue; double remain = ((ParamReal)aParameter).RealValue - front; if (remain == 0.0) { strWriter.Write("{0}.", ((ParamReal)aParameter).RealValue.ToString()); } else strWriter.Write("{0}", ((ParamReal)aParameter).RealValue.ToString("G", CultureInfo.InvariantCulture)); } else if (aParameter is ParamList) { strWriter.Write('('); for (int i = 0; i < ((ParamList)aParameter).ParameterList.Count; i++) { if (i > 0) { strWriter.Write(','); } WriteParameter(((ParamList)aParameter).ParameterList[i], strWriter, DataSet, IsDictionaryType); } strWriter.Write(')'); } else if (aParameter is ParamSelect) { //WriteSimpleRecord(((ParamSelect)aParameter).TypedParameterValue, strWriter, DataSet, IsDictionaryType); strWriter.Write( string.Format("{0}({1})", ((ParamSelect)aParameter).SelectName, ((ParamSelect)aParameter).SelectValue)); } else if (aParameter is ParamBoolean) { strWriter.Write("{0}.", ((ParamBoolean)aParameter).BoolValue.ToString()); } else throw new NotImplementedException(); }
public static bool Read(RegisteredSchema schemaName, string p21FileName) { try { var p21 = new InstanceDB(p21FileName); var sData = SParser.ReadSchema(schemaName); Instance.AssignEntityDefToInstance(sData, p21); Instance.ConvertToEarlyBinding(p21); return true; } catch (Exception) { MessageBox.Show(string.Format("There was an error in parsing {0}.", Path.GetFileName(p21FileName))); return false; } }
public static void WriteToByte(InstanceDB DataSet) { Stream bstr = File.Create(@"c:\cpd\a.cpd"); BinaryWriter binWriter = new BinaryWriter(bstr, Encoding.ASCII); //for (int i = 0; i < DataSet.aDataSectionList.Count; i++) //{ //DataSection aDataSection = DataSet.aDataSectionList[i]; //for (int j = 0; j < aDataSection.DataList.Count; j++) //{ // WriteInstance(aDataSection.DataList.GetByIndex(j), binWriter, DataSet); //} foreach (KeyValuePair<uint, Instance> kvp in DataSet.DataList) { WriteInstance(kvp.Value, binWriter, DataSet); } //} //FileStream outfile = File.Create(@"c:\a.cpz"); //GZipStream compress = new GZipStream(bstr, CompressionMode.Compress); //bstr.CopyTo(compress); //compress.Close(); //outfile.Close(); bstr.Close(); // ZipFile(); //Compress(new FileInfo(@"c:\a.cpd")); }
public SimpleRecord(String Keyword, InstanceDB DataSet) { p_Keyword = Keyword; p_IntKeyword = DataSet.AddKeyword(Keyword); ParameterList = new List <Parameter>(); }
/// <summary> /// /// </summary> /// <param name="instanceDb"></param> private void ConvertToEarlyBinding(InstanceDB instanceDb) { #region header section FILE_DESCRIPTION _fileDescription = null; FILE_NAME _fileName = null; FILE_SCHEMA _fileSchema = null; foreach (var header in instanceDb.HeaderList) { //FILE_DESCRIPTION fd = new FILE_DESCRIPTION(); //var aa = fd.GetType().Assembly; //var bb = aa.CreateInstance(header.Keyword); var obj = Activator.CreateInstance(EbConstants.Part21NSName, EbConstants.Part21NSName + "." + header.Keyword); var cobj = obj.Unwrap() as P21Instance; if (cobj is FILE_DESCRIPTION) { var fdesc = cobj as FILE_DESCRIPTION; fdesc.DESCRIPTION = new List<STRING>(); var list = header.ParameterList[0] as ParamList; foreach (var item in list.ParameterList) { var str = item as ParamString; fdesc.DESCRIPTION.Add(str.StringValue); } var pstr = header.ParameterList[1] as ParamString; fdesc.IMPLEMTATION_LEVEL = pstr.StringValue; if (fdesc.DESCRIPTION.Count > 0) _fileDescription = fdesc; //_headerSection.Add(fdesc); } else if (cobj is FILE_NAME) { var fname = cobj as FILE_NAME; ParamString pstring; if (header.ParameterList[0].ParameterType == SParamType.STRING) { pstring = header.ParameterList[0] as ParamString; fname.NAME = pstring.StringValue; } if (header.ParameterList[1].ParameterType == SParamType.STRING) { pstring = header.ParameterList[1] as ParamString; fname.TIME_STAMP = new TIME_STAMP_TEXT(); fname.TIME_STAMP.Value = pstring.StringValue; } ParamList list; if (header.ParameterList[2].ParameterType == SParamType.SET) { list = header.ParameterList[2] as ParamList; if (list != null && list.ParameterList.Count > 0) { fname.AUTHOR = new List<STRING>(); foreach (var item in list.ParameterList) { var str = item as ParamString; fname.AUTHOR.Add(str.StringValue); } } } if (header.ParameterList[3].ParameterType == SParamType.SET) { list = header.ParameterList[3] as ParamList; if (list != null && list.ParameterList.Count > 0) { fname.ORGANIZATION = new List<STRING>(); foreach (var item in list.ParameterList) { var str = item as ParamString; fname.ORGANIZATION.Add(str.StringValue); } } } if (header.ParameterList[4].ParameterType == SParamType.STRING) { pstring = header.ParameterList[4] as ParamString; fname.PREPROCESSOR_VERSION = pstring.StringValue; } if (header.ParameterList[5].ParameterType == SParamType.STRING) { pstring = header.ParameterList[5] as ParamString; fname.ORIGINATING_SYSTEM = pstring.StringValue; } if (header.ParameterList[6].ParameterType == SParamType.STRING) { pstring = header.ParameterList[6] as ParamString; fname.AUTHORIZATION = pstring.StringValue; } if (null != fname.NAME) { // _headerSection.Add(fname); _fileName = fname; } } else if (cobj is FILE_SCHEMA) { var fsch = cobj as FILE_SCHEMA; if (header.ParameterList[0].ParameterType == SParamType.SET) { ParamList list = header.ParameterList[0] as ParamList; if (list != null && list.ParameterList.Count > 0) { fsch.SCHEMA_IDENTIFIERS = new List<SCHEMA_NAME>(); foreach (var item in list.ParameterList) { var str = item as ParamString; SCHEMA_NAME sname = new SCHEMA_NAME(); sname.Value = str.StringValue; fsch.SCHEMA_IDENTIFIERS.Add(sname); } } } if (fsch.SCHEMA_IDENTIFIERS != null && fsch.SCHEMA_IDENTIFIERS.Count > 0) { //_headerSection.Add(fsch); _fileSchema = fsch; } } } if (_fileDescription != null && _fileName != null && _fileSchema != null) HeaderSection.SetHeader(_fileSchema, _fileDescription, _fileName); #endregion header section #region body section //foreach (var kvp in instanceDb.DataList) //{ // if (!_dataSection.ContainsKey(kvp.Key)) // ConvertInstance(kvp.Value); //} foreach (var kvp in instanceDb.DataList.Where(kvp => !_dataSection.ContainsKey(kvp.Key))) { ConvertInstance(kvp.Value); } #endregion body section }
public string GetStringValue(InstanceDB DataSet) { return DataSet.GetKeyword(p_EnumValueInt); }
public SimpleRecord(String Keyword, InstanceDB DataSet) { p_Keyword = Keyword; p_IntKeyword = DataSet.AddKeyword(Keyword); ParameterList = new List<Parameter>(); }