public RecievePacket handleData(System.IO.BinaryReader br, System.IO.BinaryWriter bw, System.Net.Sockets.TcpClient client) { double server = br.ReadDouble(); List<object> l = new List<object>(); l.Add(server); return new RecievePacket(l); }
/// <summary> /// ctor for reading curves from cof file /// </summary> /// <param name="bin">the cof file</param> /// <param name="sail">the sail to map to</param> public MouldCurve(System.IO.BinaryReader bin, Sail sail) { m_sail = sail; m_locked = true; //read label m_label = Utilities.ReadCString(bin); //read fit point positions int nPos = bin.ReadInt32(); List<FixedPoint> pts = new List<FixedPoint>(nPos); for (int nP = 0; nP < nPos; nP++) pts.Add(new FixedPoint(bin.ReadDouble(), 0, 0)); FitPoints = pts.ToArray(); m_bGirths = new bool[pts.Count - 1];//spline all segments //read the spline m_bSpline.ReadBin(bin); //set the fixedpoints uv coords from the positions and spline double[] uv = new double[2]; for (int nP = 0; nP < nPos; nP++) { Spline.BsVal(this[nP][0], ref uv); this[nP][1] = uv[0]; this[nP][2] = uv[1]; } }
public override object Deserialize(System.IO.BinaryReader binaryReader) { bool hasValue = binaryReader.ReadBoolean (); if (!hasValue) return null; int typeID = binaryReader.ReadByte (); switch (typeID) { case 1: return binaryReader.ReadBoolean (); case 2: return binaryReader.ReadByte (); case 128: return binaryReader.ReadSByte (); case 3: return binaryReader.ReadInt16 (); case 129: return binaryReader.ReadUInt16 (); case 4: return binaryReader.ReadInt32 (); case 130: return binaryReader.ReadUInt32 (); case 5: return binaryReader.ReadInt64 (); case 131: return binaryReader.ReadUInt64 (); case 9: return binaryReader.ReadDouble (); case 16: return binaryReader.ReadString (); case 144: return binaryReader.ReadChar (); case 24: return new DateTime (binaryReader.ReadInt64 ()); case 32: return new Guid (binaryReader.ReadBytes (16)); case 36: return binaryReader.ReadBytes (binaryReader.ReadInt32 ()); case 37: { int count = binaryReader.ReadInt32 (); string[] r = new string[count]; for (int n = 0; n != count; n++) r [n] = binaryReader.ReadString (); return r; } case 38: { int count = binaryReader.ReadInt32 (); long[] r = new long[count]; for (int n = 0; n != count; n++) r [n] = binaryReader.ReadInt64 (); return r; } default: throw new Exception (string.Format ("Serialization for type <{0}> is not supported", typeID)); } }
public override void Deserialize(System.IO.BinaryReader br) { arraySize = br.ReadInt32(); array = new double[arraySize]; for (int i = 0; i < arraySize; i++) { array[i] = br.ReadDouble(); } }
public RecievePacket handleData(System.IO.BinaryReader br, System.IO.BinaryWriter bw, System.Net.Sockets.TcpClient client) { List<object> l = new List<object>(); //score maxcombo perfect great ok miss modflags l.Add(br.ReadInt32()); l.Add(br.ReadInt32()); l.Add(br.ReadInt32()); l.Add(br.ReadInt32()); l.Add(br.ReadInt32()); l.Add(br.ReadInt32()); l.Add(br.ReadInt32()); l.Add(br.ReadDouble()); return new RecievePacket(l); }
protected override void readData(System.IO.BinaryReader DataInput) { DataInput.ReadInt32(); int i = IPAddress.NetworkToHostOrder(DataInput.ReadInt32()); for (int j = 0; j < i; ++j) { readString(DataInput, 64); DataInput.ReadDouble(); short l = IPAddress.NetworkToHostOrder(DataInput.ReadInt16()); for (int k = 0; k < l; ++k) { DataInput.ReadInt64(); DataInput.ReadInt64(); DataInput.ReadInt64(); DataInput.ReadByte(); } } }
public void ReadFrom(ref MyOctreeStorage.ChunkHeader header, System.IO.Stream stream, ref bool isOldFormat) { m_data.Version = stream.ReadInt64(); m_data.Seed = stream.ReadInt64(); m_data.Radius = stream.ReadDouble(); string generator = stream.ReadString(); if (m_data.Version != STORAGE_VERSION) { isOldFormat = true; } var def = MyDefinitionManager.Static.GetDefinition<MyPlanetGeneratorDefinition>(MyStringHash.GetOrCompute(generator)); if (def == null) throw new Exception(String.Format("Cannot load planet generator definition for subtype '{0}'.", generator)); Generator = def; Init(); }
public RecievePacket handleData(System.IO.BinaryReader br, System.IO.BinaryWriter bw, System.Net.Sockets.TcpClient client) { List<object> l = new List<object>(); l.Add(br.ReadString()); l.Add(br.ReadString()); l.Add(br.ReadInt32()); l.Add(br.ReadDouble()); return new RecievePacket(l); }
private static bool ReadBinaryTemplate(string FileName, System.IO.BinaryReader Reader, int FloatingPointSize, Template Template, bool Inline, ref BinaryCache Cache, out Structure Structure) { const short TOKEN_NAME = 0x1; const short TOKEN_STRING = 0x2; const short TOKEN_INTEGER = 0x3; const short TOKEN_INTEGER_LIST = 0x6; const short TOKEN_FLOAT_LIST = 0x7; const short TOKEN_OBRACE = 0xA; const short TOKEN_CBRACE = 0xB; const short TOKEN_COMMA = 0x13; const short TOKEN_SEMICOLON = 0x14; Structure = new Structure(Template.Name, new object[] { }); System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture; System.Text.ASCIIEncoding Ascii = new System.Text.ASCIIEncoding(); int m; for (m = 0; m < Template.Members.Length; m++) { if (Template.Members[m] == "[???]") { // unknown template int Level = 0; if (Cache.IntegersRemaining != 0) { Interface.AddMessage(Interface.MessageType.Error, false, "An integer list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); } else if (Cache.FloatsRemaining != 0) { Interface.AddMessage(Interface.MessageType.Error, false, "A float list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); } short Token = Reader.ReadInt16(); switch (Token) { case TOKEN_NAME: { Level++; int n = Reader.ReadInt32(); if (n < 1) { Interface.AddMessage(Interface.MessageType.Error, false, "count is invalid in TOKEN_NAME at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } Reader.BaseStream.Position += n; Token = Reader.ReadInt16(); if (Token != TOKEN_OBRACE) { Interface.AddMessage(Interface.MessageType.Error, false, "TOKEN_OBRACE expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } } break; case TOKEN_INTEGER: { Reader.BaseStream.Position += 4; } break; case TOKEN_INTEGER_LIST: { int n = Reader.ReadInt32(); if (n < 0) { Interface.AddMessage(Interface.MessageType.Error, false, "count is invalid in TOKEN_INTEGER_LIST at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } Reader.BaseStream.Position += 4 * n; } break; case TOKEN_FLOAT_LIST: { int n = Reader.ReadInt32(); if (n < 0) { Interface.AddMessage(Interface.MessageType.Error, false, "count is invalid in TOKEN_FLOAT_LIST at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } Reader.BaseStream.Position += (FloatingPointSize >> 3) * n; } break; case TOKEN_STRING: { int n = Reader.ReadInt32(); if (n < 0) { Interface.AddMessage(Interface.MessageType.Error, false, "count is invalid in TOKEN_STRING at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } Reader.BaseStream.Position += n; Token = Reader.ReadInt16(); if (Token != TOKEN_COMMA & Token != TOKEN_SEMICOLON) { Interface.AddMessage(Interface.MessageType.Error, false, "TOKEN_COMMA or TOKEN_SEMICOLON expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } } break; case TOKEN_OBRACE: Interface.AddMessage(Interface.MessageType.Error, false, "Unexpected token TOKEN_OBRACE encountered at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; case TOKEN_CBRACE: if (Level == 0) return true; Level--; break; default: Interface.AddMessage(Interface.MessageType.Error, false, "Unknown token encountered at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } m--; } else if (Template.Members[m] == "[...]") { // any template if (Cache.IntegersRemaining != 0) { Interface.AddMessage(Interface.MessageType.Error, false, "An integer list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); } else if (Cache.FloatsRemaining != 0) { Interface.AddMessage(Interface.MessageType.Error, false, "A float list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); } if (Template.Name.Length == 0 && Reader.BaseStream.Position == Reader.BaseStream.Length) { // end of file return true; } short Token = Reader.ReadInt16(); switch (Token) { case TOKEN_NAME: int n = Reader.ReadInt32(); if (n < 1) { Interface.AddMessage(Interface.MessageType.Error, false, "count is invalid in TOKEN_NAME at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } string Name = new string(Ascii.GetChars(Reader.ReadBytes(n))); Token = Reader.ReadInt16(); if (Token != TOKEN_OBRACE) { Interface.AddMessage(Interface.MessageType.Error, false, "TOKEN_OBRACE expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } Structure o; if (!ReadBinaryTemplate(FileName, Reader, FloatingPointSize, GetTemplate(Name), false, ref Cache, out o)) { return false; } Array.Resize<object>(ref Structure.Data, Structure.Data.Length + 1); Structure.Data[Structure.Data.Length - 1] = o; break; case TOKEN_CBRACE: if (Template.Name.Length == 0) { Interface.AddMessage(Interface.MessageType.Error, false, "Unexpected TOKEN_CBRACE encountered at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } m++; break; default: Interface.AddMessage(Interface.MessageType.Error, false, "TOKEN_NAME or TOKEN_CBRACE expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } m--; } else if (Template.Members[m].EndsWith("]", StringComparison.Ordinal)) { // inlined array expected string r = Template.Members[m].Substring(0, Template.Members[m].Length - 1); int h = r.IndexOf('['); if (h >= 0) { string z = r.Substring(h + 1, r.Length - h - 1); r = r.Substring(0, h); if (!int.TryParse(z, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out h)) { Interface.AddMessage(Interface.MessageType.Error, false, "The internal format description for a template array is invalid in template " + Template.Name + " in binary X object file " + FileName); return false; } if (h < 0 || h >= Structure.Data.Length || !(Structure.Data[h] is int)) { Interface.AddMessage(Interface.MessageType.Error, false, "The internal format description for a template array is invalid in template " + Template.Name + " in binary X object file " + FileName); return false; } h = (int)Structure.Data[h]; } else { Interface.AddMessage(Interface.MessageType.Error, false, "The internal format description for a template array is invalid in template " + Template.Name + " in binary X object file " + FileName); return false; } if (r == "DWORD") { // dword array int[] o = new int[h]; for (int i = 0; i < h; i++) { if (Cache.IntegersRemaining != 0) { // use cached integer int a = Cache.Integers[Cache.IntegersRemaining - 1]; Cache.IntegersRemaining--; o[i] = a; } else if (Cache.FloatsRemaining != 0) { // cannot use cached float Interface.AddMessage(Interface.MessageType.Error, false, "A float list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } else { while (true) { short Token = Reader.ReadInt16(); if (Token == TOKEN_INTEGER) { int a = Reader.ReadInt32(); o[i] = a; break; } else if (Token == TOKEN_INTEGER_LIST) { int n = Reader.ReadInt32(); if (n < 0) { Interface.AddMessage(Interface.MessageType.Error, false, "count is invalid in TOKEN_INTEGER_LIST at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } if (n != 0) { Cache.Integers = new int[n]; for (int j = 0; j < n; i++) { Cache.Integers[n - j - 1] = Reader.ReadInt32(); } Cache.IntegersRemaining = n - 1; int a = Cache.Integers[Cache.IntegersRemaining]; o[i] = a; break; } } else { Interface.AddMessage(Interface.MessageType.Error, false, "TOKEN_INTEGER or TOKEN_INTEGER_LIST expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } } } } Array.Resize<object>(ref Structure.Data, Structure.Data.Length + 1); Structure.Data[Structure.Data.Length - 1] = o; } else if (r == "float") { // float array double[] o = new double[h]; for (int i = 0; i < h; i++) { if (Cache.IntegersRemaining != 0) { // cannot use cached integer Interface.AddMessage(Interface.MessageType.Error, false, "An integer list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } else if (Cache.FloatsRemaining != 0) { // use cached float double a = Cache.Floats[Cache.FloatsRemaining - 1]; Cache.FloatsRemaining--; o[i] = a; } else { while (true) { short Token = Reader.ReadInt16(); if (Token == TOKEN_FLOAT_LIST) { int n = Reader.ReadInt32(); if (n < 0) { Interface.AddMessage(Interface.MessageType.Error, false, "count is invalid in TOKEN_FLOAT_LIST at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } if (n != 0) { Cache.Floats = new double[n]; for (int j = 0; j < n; i++) { if (FloatingPointSize == 32) { Cache.Floats[n - j - 1] = (double)Reader.ReadSingle(); } else if (FloatingPointSize == 64) { Cache.Floats[n - j - 1] = Reader.ReadDouble(); } } Cache.FloatsRemaining = n - 1; double a = Cache.Floats[Cache.FloatsRemaining]; o[i] = a; break; } } else { Interface.AddMessage(Interface.MessageType.Error, false, "TOKEN_FLOAT_LIST expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } } } } Array.Resize<object>(ref Structure.Data, Structure.Data.Length + 1); Structure.Data[Structure.Data.Length - 1] = o; } else { // template array Structure[] o = new Structure[h]; for (int i = 0; i < h; i++) { ReadBinaryTemplate(FileName, Reader, FloatingPointSize, GetTemplate(r), true, ref Cache, out o[i]); } Array.Resize<object>(ref Structure.Data, Structure.Data.Length + 1); Structure.Data[Structure.Data.Length - 1] = o; } } else { // inlined template or primitive expected switch (Template.Members[m]) { case "DWORD": // dword expected if (Cache.IntegersRemaining != 0) { // use cached integer int a = Cache.Integers[Cache.IntegersRemaining - 1]; Cache.IntegersRemaining--; Array.Resize<object>(ref Structure.Data, Structure.Data.Length + 1); Structure.Data[Structure.Data.Length - 1] = a; } else if (Cache.FloatsRemaining != 0) { // cannot use cached float Interface.AddMessage(Interface.MessageType.Error, false, "A float list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } else { // read new data while (true) { short Token = Reader.ReadInt16(); if (Token == TOKEN_INTEGER) { int a = Reader.ReadInt32(); Array.Resize<object>(ref Structure.Data, Structure.Data.Length + 1); Structure.Data[Structure.Data.Length - 1] = a; break; } else if (Token == TOKEN_INTEGER_LIST) { int n = Reader.ReadInt32(); if (n < 0) { Interface.AddMessage(Interface.MessageType.Error, false, "count is invalid in TOKEN_INTEGER_LIST at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } if (n != 0) { Cache.Integers = new int[n]; for (int i = 0; i < n; i++) { Cache.Integers[n - i - 1] = Reader.ReadInt32(); } Cache.IntegersRemaining = n - 1; int a = Cache.Integers[Cache.IntegersRemaining]; Array.Resize<object>(ref Structure.Data, Structure.Data.Length + 1); Structure.Data[Structure.Data.Length - 1] = a; break; } } else { Interface.AddMessage(Interface.MessageType.Error, false, "TOKEN_INTEGER or TOKEN_INTEGER_LIST expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } } } break; case "float": // float expected if (Cache.IntegersRemaining != 0) { // cannot use cached integer Interface.AddMessage(Interface.MessageType.Error, false, "An integer list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } else if (Cache.FloatsRemaining != 0) { // use cached float double a = Cache.Floats[Cache.FloatsRemaining - 1]; Cache.FloatsRemaining--; Array.Resize<object>(ref Structure.Data, Structure.Data.Length + 1); Structure.Data[Structure.Data.Length - 1] = a; } else { // read new data while (true) { short Token = Reader.ReadInt16(); if (Token == TOKEN_FLOAT_LIST) { int n = Reader.ReadInt32(); if (n < 0) { Interface.AddMessage(Interface.MessageType.Error, false, "count is invalid in TOKEN_FLOAT_LIST at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } if (n != 0) { Cache.Floats = new double[n]; for (int i = 0; i < n; i++) { if (FloatingPointSize == 32) { Cache.Floats[n - i - 1] = (double)Reader.ReadSingle(); } else if (FloatingPointSize == 64) { Cache.Floats[n - i - 1] = Reader.ReadDouble(); } } Cache.FloatsRemaining = n - 1; double a = Cache.Floats[Cache.FloatsRemaining]; Array.Resize<object>(ref Structure.Data, Structure.Data.Length + 1); Structure.Data[Structure.Data.Length - 1] = a; break; } } else { Interface.AddMessage(Interface.MessageType.Error, false, "TOKEN_FLOAT_LIST expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } } } break; case "string": { // string expected if (Cache.IntegersRemaining != 0) { Interface.AddMessage(Interface.MessageType.Error, false, "An integer list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); } else if (Cache.FloatsRemaining != 0) { Interface.AddMessage(Interface.MessageType.Error, false, "A float list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); } short Token = Reader.ReadInt16(); if (Token == TOKEN_STRING) { int n = Reader.ReadInt32(); if (n < 0) { Interface.AddMessage(Interface.MessageType.Error, false, "count is invalid in TOKEN_STRING at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } string s = new string(Ascii.GetChars(Reader.ReadBytes(n))); Array.Resize<object>(ref Structure.Data, Structure.Data.Length + 1); Structure.Data[Structure.Data.Length - 1] = s; Token = Reader.ReadInt16(); if (Token != TOKEN_SEMICOLON) { Interface.AddMessage(Interface.MessageType.Error, false, "TOKEN_SEMICOLON expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } } else { Interface.AddMessage(Interface.MessageType.Error, false, "TOKEN_STRING expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } } break; default: // inlined template expected Structure o; ReadBinaryTemplate(FileName, Reader, FloatingPointSize, GetTemplate(Template.Members[m]), true, ref Cache, out o); Array.Resize<object>(ref Structure.Data, Structure.Data.Length + 1); Structure.Data[Structure.Data.Length - 1] = o; break; } } } if (Inline) { return true; } else { string s = Template.Members[Template.Members.Length - 1]; if (s != "[???]" & s != "[...]") { int Token = Reader.ReadInt16(); if (Token != TOKEN_CBRACE) { Interface.AddMessage(Interface.MessageType.Error, false, "TOKEN_CBRACE expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); return false; } } return true; } }
public override void ReadXml(System.Xml.Linq.XElement element) { base.ReadXml(element); Parameter = element.ReadDouble("Parameter"); Recalculate(); }
/// <summary> /// Reads the data. (allows faster custom serialization for better performance in TraceLab) /// </summary> /// <param name="reader">The reader.</param> public void ReadData(System.IO.BinaryReader reader) { int dataversion = reader.ReadInt32(); if (dataversion != version) { throw new InvalidOperationException("Binary reader did not correct version data. Data corrupted. Potentially IRawSerializable not implemented correctly"); } else { int termsCount = reader.ReadInt32(); //create new collections m_terms = new Dictionary<string, TLTermEntry>(); m_termEntries = new TermEntryCollection(); for (int i = 0; i < termsCount; ++i) { TLTermEntry termEntry = new TLTermEntry(); termEntry.ReadData(reader); AddTermEntry(termEntry); } int vectorLenghtsOfArtifactsCount = reader.ReadInt32(); m_vectorLengthsOfArtifacts = new Dictionary<string, double>(); for (int i = 0; i < vectorLenghtsOfArtifactsCount; ++i) { string artifactId = reader.ReadString(); double weight = reader.ReadDouble(); m_vectorLengthsOfArtifacts.Add(artifactId, weight); } } }
/// <summary> /// Reads the data. (allows faster custom serialization for better performance in TraceLab) /// </summary> /// <param name="reader">The reader.</param> public void ReadData(System.IO.BinaryReader reader) { this.m_x = reader.ReadDouble(); this.m_y = reader.ReadDouble(); }
/// <summary> /// Читает P-объект из бинарного ридера, начиная с текущего места /// </summary> /// <param name="typ"></param> /// <param name="br"></param> /// <returns></returns> internal static object GetPO(PType typ, System.IO.BinaryReader br) { switch (typ.Vid) { case PTypeEnumeration.none: return null; case PTypeEnumeration.boolean: return br.ReadBoolean(); case PTypeEnumeration.integer: return br.ReadInt32(); case PTypeEnumeration.longinteger: return br.ReadInt64(); case PTypeEnumeration.real: return br.ReadDouble(); case PTypeEnumeration.@byte: return br.ReadByte(); case PTypeEnumeration.fstring: { //int len = ((PTypeFString)typ).Length; int size = ((PTypeFString)typ).Size; byte[] arr = new byte[size]; arr = br.ReadBytes(size); string s = System.Text.Encoding.Unicode.GetString(arr); return s; } case PTypeEnumeration.sstring: { int len = br.ReadInt32(); char[] chrs = br.ReadChars(len); return new string(chrs); } case PTypeEnumeration.record: { PTypeRecord r_tp = (PTypeRecord)typ; object[] fields = new object[r_tp.Fields.Length]; for (int i = 0; i < r_tp.Fields.Length; i++) { fields[i] = GetPO(r_tp.Fields[i].Type, br); } return fields; } case PTypeEnumeration.sequence: { PTypeSequence mts = (PTypeSequence)typ; PType tel = mts.ElementType; long llen = br.ReadInt64(); object[] els = new object[llen]; for (long ii = 0; ii < llen; ii++) els[ii] = GetPO(tel, br); return els; } case PTypeEnumeration.union: { PTypeUnion mtu = (PTypeUnion)typ; int v = br.ReadByte(); PType mt = mtu.Variants[v].Type; return new object[] { v, GetPO(mt, br) }; } default: throw new Exception("Err in TPath Get(): type is not implemented " + typ.Vid); } }
internal Widget(REST aRest, System.IO.BinaryReader aReader) { Type = (WidgetType)aReader.ReadInt32(); Label = aReader.ReadString(); Icon = aReader.ReadString(); Item item; if(aRest.Items.TryGetValue(aReader.ReadString(), out item)) Item = item; Page page; if (aRest.Pages.TryGetValue(aReader.ReadString(), out page)) LinkedPage = page; var uri = aReader.ReadString(); if (!string.IsNullOrWhiteSpace(uri)) Url = new Uri(uri); Refresh = aReader.ReadInt32(); Period = aReader.ReadString(); MinValue = aReader.ReadDouble(); MaxValue = aReader.ReadDouble(); Step = aReader.ReadDouble(); var count = aReader.ReadInt32(); for (var idx = 0; idx < count; ++idx) mWidgets.Add(new Widget(aRest, aReader)); }
private static FileHeader ReadHeaderInfo(ref System.IO.BinaryReader objReader) { FileHeader _Header = new FileHeader(); try { { _Header.FileCode = BigToLittleEndian(objReader.ReadInt32()); objReader.ReadBytes(20); //*** Skip the unused bytes _Header.FileLength = BigToLittleEndian(objReader.ReadInt32()); _Header.Version = objReader.ReadInt32(); _Header.ShapeType = objReader.ReadInt32(); _Header.BoundingBoxXMin = objReader.ReadDouble(); _Header.BoundingBoxYMin = objReader.ReadDouble(); _Header.BoundingBoxXMax = objReader.ReadDouble(); _Header.BoundingBoxYMax = objReader.ReadDouble(); _Header.BoundingBoxZMin = objReader.ReadDouble(); _Header.BoundingBoxZMax = objReader.ReadDouble(); _Header.BoundingBoxMMin = objReader.ReadDouble(); _Header.BoundingBoxMMax = objReader.ReadDouble(); } return _Header; } finally { //_Header = null; } }
public override void ReadXml(System.Xml.Linq.XElement element) { base.ReadXml(element); angle = element.ReadDouble("Angle"); Recalculate(); }
/// <summary> /// Reads a node from a stream recursively /// </summary> /// <param name="depth">Current depth</param> /// <param name="br">Binary reader reference</param> /// <returns></returns> private static QuadTree ReadNode(uint depth, ref System.IO.BinaryReader br) { QuadTree node = new QuadTree(); node._Depth = depth; node.Box = new SharpMap.Geometries.BoundingBox(br.ReadDouble(),br.ReadDouble(),br.ReadDouble(),br.ReadDouble()); bool IsLeaf = br.ReadBoolean(); if (IsLeaf) { int FeatureCount = br.ReadInt32(); node._objList = new List<BoxObjects>(); for (int i = 0; i < FeatureCount; i++) { BoxObjects box = new BoxObjects(); box.box = new SharpMap.Geometries.BoundingBox(br.ReadDouble(), br.ReadDouble(), br.ReadDouble(), br.ReadDouble()); box.ID = (uint)br.ReadInt32(); node._objList.Add(box); } } else { node.Child0 = ReadNode(node._Depth + 1, ref br); node.Child1 = ReadNode(node._Depth + 1, ref br); } return node; }
/// <summary> /// Parses the arguments from a source stream (The documentation is misleading. /// The _length member does define the overall length of the action's arguments. /// Now, we have to track how much we used.) /// </summary> /// <param name="sourceStream">The source stream</param> /// <param name="sourceVersion">The version</param> protected override void Parse( System.IO.BinaryReader sourceStream, byte sourceVersion ) { _arguments = new List<AVM1DataElement>(); // // The documentation is misleading. The _length member does define the overall // length of the action's arguments. Now, we have to track how much we used. // long before = sourceStream.BaseStream.Position; while ( sourceStream.BaseStream.Position < ( before + _length ) ) { AVM1DataElement element = new AVM1DataElement(); element.DataType = ( AVM1DataTypes )sourceStream.ReadByte(); if ( ( element.DataType >= AVM1DataTypes.AVM_null ) && ( sourceVersion < 5 ) ) { throw new AVM1ExceptionVersion( "ActionPush with data type " + element.DataType.ToString() + " in Swf Version " + sourceVersion.ToString() ); } switch ( element.DataType ) { case AVM1DataTypes.AVM_String: element.Value = ( object )Helper.SwfStrings.SwfString( sourceVersion, sourceStream ); break; case AVM1DataTypes.AVM_float: element.Value = ( object )sourceStream.ReadSingle(); break; case AVM1DataTypes.AVM_null: element.Value = null; break; case AVM1DataTypes.AVM_undefined: element.Value = null; break; case AVM1DataTypes.AVM_register: element.Value = ( object )sourceStream.ReadByte(); break; case AVM1DataTypes.AVM_boolean: element.Value = ( object )sourceStream.ReadBoolean(); break; case AVM1DataTypes.AVM_double: element.Value = ( object )sourceStream.ReadDouble(); break; case AVM1DataTypes.AVM_integer: element.Value = ( object )sourceStream.ReadUInt32(); break; case AVM1DataTypes.AVM_constUInt8: element.Value = ( object )sourceStream.ReadByte(); break; case AVM1DataTypes.AVM_constUInt16: element.Value = ( object )sourceStream.ReadUInt16(); break; default: throw new AVM1ExceptionByteCodeFormat( "ActionPush with invalid data type 0x" + element.DataType.ToString( "X" ) ); } _arguments.Add( element ); } if ( sourceStream.BaseStream.Position != ( before + _length ) ) { throw new AVM1ExceptionByteCodeFormat( "ActionPush arguments consumed more than the Action's length (" + ( ( long )( sourceStream.BaseStream.Position - before ) ).ToString() + " consumed, " + _length.ToString() + " declared as length)" ); } }
/// <summary> /// Reads the data. (allows faster custom serialization for better performance in TraceLab) /// </summary> /// <param name="reader">The reader.</param> public void ReadData(System.IO.BinaryReader reader) { int dataversion = reader.ReadInt32(); if (dataversion != TLTermEntry.version) { throw new InvalidOperationException("Binary reader did not correct version data. Data corrupted. Potentially IRawSerializable not implemented correctly"); } else { m_term = reader.ReadString(); m_numberOfArtifactsContainingTerm = reader.ReadInt32(); m_totalFrequencyAcrossArtifacts = reader.ReadInt32(); m_weight = reader.ReadDouble(); int postingsCount = reader.ReadInt32(); //reset both collections m_postings = new PostingsCollection(); m_postingsLookup = new Dictionary<string, TLPosting>(); for (int i = 0; i < postingsCount; ++i) { TLPosting posting = new TLPosting(); posting.ReadData(reader); AddPosting(posting); } } }
/// <summary> /// Reads the data. (allows faster custom serialization for better performance in TraceLab) /// </summary> /// <param name="reader">The reader.</param> public void ReadData(System.IO.BinaryReader reader) { int dataversion = reader.ReadInt32(); if (dataversion != TLExperimentResults.version) { throw new InvalidOperationException("Binary reader did not read correct data version. Data corrupted. Potentially IRawSerializable not implemented correctly"); } else { this.m_techniqueName = reader.ReadString(); int resultsCount = reader.ReadInt32(); this.m_datasetsResults = new List<DatasetResults>(resultsCount); for (int i = 0; i < resultsCount; i++) { DatasetResults result = (DatasetResults)Activator.CreateInstance(typeof(DatasetResults), true); result.ReadData(reader); this.m_datasetsResults.Add(result); } this.m_score = reader.ReadDouble(); bool isMemberPresent = reader.ReadBoolean(); if (isMemberPresent) { DatasetResults result = (DatasetResults)Activator.CreateInstance(typeof(DatasetResults), true); result.ReadData(reader); this.m_acrossAllDatasetsResults = result; } this.m_baseData = null; } }
public override void ReadXml(System.Xml.Linq.XElement element) { base.ReadXml(element); Factor = element.ReadDouble("Factor"); Recalculate(); }
/// <summary> /// This method fills out a direct sound object with the minimum information from a .pac1 file. The Binary Reader must be set to a point where the method can read the direct sound data without any adjustment. /// </summary> /// <param name="BR">The open BinaryReader object</param> /// <param name="Rec_CT">The number of receivers the direct sound was calculated for.</param> /// <returns>The completed direct sound simulation type.</returns> public static Direct_Sound Read_Data(ref System.IO.BinaryReader BR, IEnumerable<Hare.Geometry.Point> RecPts, Hare.Geometry.Point SrcPt, double[] Rho_C, string Version) { Direct_Sound D = new Direct_Sound(); D.Receiver = RecPts.ToList<Hare.Geometry.Point>(); //new Receiver_Bank(RecPts, SrcPt, 343, new double[] { 0, 0, 0, 0, 0, 0, 0, 0 }, 0, 1000, 0, Receiver_Bank.Type.Stationary); int Rec_Ct = D.Receiver.Count;//RecPts.Count<Rhino.Geometry.Point3d>(); D.Rho_C = Rho_C; //2. Write strength reference data //Pre 2.0, 8 doubles. if (double.Parse(Version.Substring(0, 3)) < 2.0) { for(int i = 0; i < 8; i++) BR.ReadDouble(); } ////Duration_ms = 1; //TODO Add version 1.5 and greater Source direction. (oops) if (double.Parse(Version.Substring(0, 3)) >= 1.1) { //2.1 Write source data - type and SWL string[] typestring = BR.ReadString().Split(':'); //string D.type = typestring[0]; //if (typestring.Length > 1 && typestring[1] == "Histogram") //{ //2.2 Write number of samples ////Duration_ms = BR.ReadInt32(); //} D.SWL = new double[8]; for (int o = 0; o < 8; o++) { D.SWL[o] = BR.ReadDouble(); //double } if (double.Parse(Version.Substring(0, 3)) >= 2.0) { D.Delay_ms = BR.ReadDouble(); } else { D.Delay_ms = 0; } } else { D.type = "Geodesic Source"; D.SWL = new double[]{120, 120, 120, 120, 120, 120, 120, 120}; D.Delay_ms = 0; } D.Src = new GeodesicSource(D.SWL, new double[8]{0,0,0,0,0,0,0,0}, new Rhino.Geometry.Point3d(SrcPt.x, SrcPt.y, SrcPt.z), 0, 0); D.Validity = new Boolean[RecPts.Count<Hare.Geometry.Point>()]; D.Time_Pt = new double[RecPts.Count<Hare.Geometry.Point>()]; D.Io = new double[RecPts.Count<Hare.Geometry.Point>()][][]; D.Dir_Rec_Pos = new float[RecPts.Count<Hare.Geometry.Point>()][][][]; D.Dir_Rec_Neg = new float[RecPts.Count<Hare.Geometry.Point>()][][][]; double v = double.Parse(Version.Substring(0, 3)); for (int q = 0; q < RecPts.Count<Hare.Geometry.Point>(); q++) { //2.2 Write number of samples int no_of_samples = BR.ReadInt32(); //3. Write the validity of the direct sound D.Validity[q] = BR.ReadBoolean(); //4. Write the Time point D.Time_Pt[q] = BR.ReadDouble(); D.Io[q] = new double[9][]; D.Dir_Rec_Pos[q] = new float[8][][]; D.Dir_Rec_Neg[q] = new float[8][][]; for (int oct = 0; oct < 8; oct++) { D.Io[q][oct] = new double[no_of_samples]; D.Dir_Rec_Pos[q][oct] = new float[no_of_samples][]; D.Dir_Rec_Neg[q][oct] = new float[no_of_samples][]; for (int t = 0; t < no_of_samples; t++) { D.Dir_Rec_Pos[q][oct][t] = new float[3]; D.Dir_Rec_Neg[q][oct][t] = new float[3]; } } D.Io[q][8] = new double[no_of_samples]; for (int s = 0; s < no_of_samples; s++) { //5a. Write all Energy data D.Io[q][0][s] = BR.ReadDouble(); D.Io[q][1][s] = BR.ReadDouble(); D.Io[q][2][s] = BR.ReadDouble(); D.Io[q][3][s] = BR.ReadDouble(); D.Io[q][4][s] = BR.ReadDouble(); D.Io[q][5][s] = BR.ReadDouble(); D.Io[q][6][s] = BR.ReadDouble(); D.Io[q][7][s] = BR.ReadDouble(); D.Io[q][8][s] = D.Io[q][0][s] + D.Io[q][1][s] + D.Io[q][2][s] + D.Io[q][3][s] + D.Io[q][4][s] + D.Io[q][5][s] + D.Io[q][6][s] + D.Io[q][7][s]; if (v == 1.7) { //5b. Write all Pressure Data //Real //Imag for(int i = 0; i < 16; i++) BR.ReadSingle(); } //5c. Write all directional data for (int oct = 0; oct < 8; oct++) for (int dir = 0; dir < 3; dir++) { D.Dir_Rec_Pos[q][oct][s][dir] = BR.ReadSingle(); D.Dir_Rec_Neg[q][oct][s][dir] = BR.ReadSingle(); } } } D.Create_Pressure(); return D; }
/// <summary> /// Reads the data. (allows faster custom serialization for better performance in TraceLab) /// </summary> /// <param name="reader">The reader.</param> public virtual void ReadData(System.IO.BinaryReader reader) { var dataVersion = reader.ReadInt32(); if (dataVersion != version) { throw new InvalidOperationException("Binary reader did not correct version data. Data corrupted. Potentially IRawSerializable not implemented correctly"); } else { m_name = reader.ReadString(); m_threshold = reader.ReadDouble(); Dictionary<string, Dictionary<string, double>> matrix = new Dictionary<string, Dictionary<string, double>>(); int sourceCount = reader.ReadInt32(); for (int i = 0; i < sourceCount; ++i) { string sourceId = reader.ReadString(); int linkCount = reader.ReadInt32(); Dictionary<string, double> links = new Dictionary<string, double>(); matrix[sourceId] = links; for (int linkIterator = 0; linkIterator < linkCount; ++linkIterator) { string targetId = reader.ReadString(); double score = reader.ReadDouble(); links[targetId] = score; } } m_matrix = matrix; } }
public static JSONNode Deserialize (System.IO.BinaryReader aReader) { JSONBinaryTag type = (JSONBinaryTag)aReader.ReadByte (); switch (type) { case JSONBinaryTag.Array: { int count = aReader.ReadInt32 (); JSONArray tmp = new JSONArray (); for (int i = 0; i < count; i++) tmp.Add (Deserialize (aReader)); return tmp; } case JSONBinaryTag.Class: { int count = aReader.ReadInt32 (); JSONClass tmp = new JSONClass (); for (int i = 0; i < count; i++) { string key = aReader.ReadString (); var val = Deserialize (aReader); tmp.Add (key, val); } return tmp; } case JSONBinaryTag.Value: { return new JSONData (aReader.ReadString ()); } case JSONBinaryTag.IntValue: { return new JSONData (aReader.ReadInt32 ()); } case JSONBinaryTag.DoubleValue: { return new JSONData (aReader.ReadDouble ()); } case JSONBinaryTag.BoolValue: { return new JSONData (aReader.ReadBoolean ()); } case JSONBinaryTag.FloatValue: { return new JSONData (aReader.ReadSingle ()); } default: { throw new Exception ("Error deserializing JSON. Unknown tag: " + type); } } }
/// <summary> /// Deserialize Deserialize /// </summary> public virtual object Deserialize(System.IO.BinaryReader reader) { X = reader.ReadDouble(); Y = reader.ReadDouble(); Z = reader.ReadDouble(); TimeStamp = Microsoft.Dss.Services.Serializer.BinarySerializationHelper.DeserializeDateTime(reader); return this; }
public override void deserialize(System.IO.BinaryReader br) { Name = br.ReadString(); m_autoId = br.ReadBoolean(); Point p = new Point(); p.X = br.ReadDouble(); p.Y = br.ReadDouble(); Position = p; p.X = br.ReadDouble(); p.Y = br.ReadDouble(); Dimension = p; int compCount = br.ReadInt32(); for (int i = 0; i < compCount; ++i) { Element newComp = new Element(); newComp.deserialize(br); newComp.ParentGameObject = this; m_elements.Add(newComp); } }
private Boolean ReadValues(System.IO.BinaryReader r) { Int32 count; if(r.BaseStream.Length == 0) return false; count = Sql.Read7BitEncodedInt(r); if (count == 0) return true; for (Int32 i = 0; i < count; i++) { String name = r.ReadString(); SqlDbType LType = (SqlDbType)r.ReadUInt16(); Object value = null; Int32 len; //Int32 lcid; //SqlCompareOptions co; switch (LType) { case SqlDbType.Bit : value = new SqlBoolean(r.ReadBoolean()); break; case SqlDbType.TinyInt : value = new SqlByte(r.ReadByte()); break; case SqlDbType.SmallInt : value = new SqlInt16((Int16)r.ReadInt16()); break; case SqlDbType.Int : value = new SqlInt32((Int32)r.ReadInt32()); break; case SqlDbType.BigInt : value = new SqlInt64(r.ReadInt64()); break; case SqlDbType.Binary : case SqlDbType.VarBinary: len = r.ReadUInt16(); value = new SqlBytes(r.ReadBytes(len)); break; case SqlDbType.Char : case SqlDbType.VarChar : //value = new Sql.SqlAnsiString(r); break; case SqlDbType.NChar: case SqlDbType.NVarChar: //co = (SqlCompareOptions)r.ReadUInt16(); //lcid = r.ReadInt32(); //value = new SqlString(r.ReadString(), lcid, co); value = new SqlString(r.ReadString()); break; case SqlDbType.DateTime : value = new SqlDateTime(DateTime.FromBinary(r.ReadInt64())); break; case SqlDbType.SmallDateTime: case SqlDbType.Date : case SqlDbType.DateTime2 : value = DateTime.FromBinary(r.ReadInt64()); break; case SqlDbType.Time : value = TimeSpan.FromTicks(r.ReadInt64()); break; case SqlDbType.DateTimeOffset: DateTime LDateTime = DateTime.FromBinary(r.ReadInt64()); value = new DateTimeOffset(LDateTime, TimeSpan.FromTicks(r.ReadInt64())); break; case SqlDbType.Decimal: value = new SqlDecimal(r.ReadDecimal()); break; case SqlDbType.Float : value = new SqlDouble(r.ReadDouble()); break; // Not support SqlDbType.Image case SqlDbType.Money : value = new SqlMoney(r.ReadDecimal()); break; case SqlDbType.Real : value = new SqlSingle(r.ReadDouble()); break; case SqlDbType.SmallMoney: value = new SqlMoney(r.ReadDecimal()); break; // Not support SqlDbType.Structured // Not support SqlDbType.Text // Not support SqlDbType.Timestamp case SqlDbType.UniqueIdentifier: value = new SqlGuid(r.ReadString()); break; // Not support SqlDbType.Variant case SqlDbType.Xml: XmlReader rXml = XmlReader.Create(new System.IO.StringReader(r.ReadString())); value = new SqlXml(rXml); break; case SqlDbType.Udt: // TODO: Пока поддержа только TParams //String LTypeName = r.ReadString(); //value = CreateUdtObject(LTypeName); //if (value is IBinarySerialize) // (value as IBinarySerialize).Read(r); //else // throw new Exception(String.Format("Невозможно прочитать данные типа UDT '{0}' - не поддерживается IBinarySerialize", LTypeName)); value = new SqlUdt(r); break; default: throw new Exception(String.Format("Невозможно прочитать данные, тип '{0}' не поддерживается текущей версией {1}", LType.ToString(), this.GetType().Name)); // Not support SqlDbType.NText } if (value != null) FData.Add(name, value); } return true; }
/// <summary> /// Constructor which takes a Binary Reader at the appropriate point, from which calculated data will be extracted. /// </summary> /// <param name="BR"></param> /// <param name="Rec_CT"></param> /// <param name="Direct"></param> /// <returns></returns> public static ImageSourceData Read_Data(ref System.IO.BinaryReader BR, int Rec_CT, Direct_Sound Direct, bool Edges, int Src_ID, string version) { ImageSourceData IS = new ImageSourceData(); IS.ValidPaths = new List<Deterministic_Reflection>[Rec_CT]; IS.Direct_Time = new double[Rec_CT]; double v = double.Parse(version.Substring(0, 3)); for (int q = 0; q < Rec_CT; q++) { IS.ValidPaths[q] = new List<Deterministic_Reflection>(); //2. Write the receiver number:int BR.ReadInt32(); //3. Write number of paths:int int PathCt = BR.ReadInt32(); for (int i = 0; i < PathCt; i++) { int ReflectionType = BR.ReadInt16(); if (ReflectionType == 0) { //Speculare Reflection //4. Write the number of reflection path points Hare.Geometry.Point[] PTS = new Hare.Geometry.Point[BR.ReadInt32()]; //5. Write the reflection path:double for (int r = 0; r < PTS.Length; r++) { PTS[r] = new Hare.Geometry.Point(BR.ReadDouble(), BR.ReadDouble(), BR.ReadDouble()); } //Previously, Pachyderm performed the deterministic part in intensity only... //6a. Write the energy values double[] Energy = new double[8]; Energy[0] = BR.ReadDouble(); Energy[1] = BR.ReadDouble(); Energy[2] = BR.ReadDouble(); Energy[3] = BR.ReadDouble(); Energy[4] = BR.ReadDouble(); Energy[5] = BR.ReadDouble(); Energy[6] = BR.ReadDouble(); Energy[7] = BR.ReadDouble(); bool Special_Filter = BR.ReadBoolean(); System.Numerics.Complex[] Filter = null; if (Special_Filter) { //6aa1. Write length of filter... int Filter_Length = BR.ReadInt32(); Filter = new System.Numerics.Complex[Filter_Length]; //6aa2. Write filter... for(int j = 0; j < Filter.Length; j++) { Filter[j] = new System.Numerics.Complex(BR.ReadDouble(), BR.ReadDouble()); } //6aa3. Write octave band root mean square pressure... } double[] prms = new double[8]; for (int j = 0; j < prms.Length; j++) prms[j] = BR.ReadDouble(); //7. Write the arrival time:double double Time = BR.ReadDouble(); //8. Write the Reflection Sequence:int int[] Sequence = new int[PTS.Length - 2]; for (int r = 0; r < Sequence.Length; r++) { Sequence[r] = BR.ReadInt32(); } IS.ValidPaths[q].Add(new Specular_Path(PTS, Energy, prms, Filter, Time, Sequence, Direct.Min_Time(q), Src_ID)); } else if (ReflectionType == 1) { //TODO: Find a robust format for compound reflection paths... ///Specular Path: //BW.Write((short)1); //Write the number of samples and the pressure signal down: //Write the number of samples and the pressure signal down: //6a.2. Write the number of samples in the pressure signal.(int) //6b. Write the pressure values } } } return IS; }
public TrackHelper(System.IO.BinaryReader reader) { int playWaveEvents = reader.ReadInt32(); mEntries = new PlayWaveHelper[playWaveEvents]; for (int i = 0; i < playWaveEvents; i++) { mEntries[i] = new PlayWaveHelper(reader); } mVolume = (float)reader.ReadInt32() / 100.0f; mVariation = reader.ReadByte(); mFiltered = reader.ReadBoolean(); mFilterFrequency = (float)reader.ReadDouble(); GSGE.Debug.assert(mFilterFrequency <= 20000); mFilterQFactor = reader.ReadDouble(); mPitchVariationMin = (float)reader.ReadInt32() / 100.0f; mPitchVariationMax = (float)reader.ReadInt32() / 100.0f; mVolumeVariationMin = (float)reader.ReadInt32() / 100.0f; mVolumeVariationMax = (float)reader.ReadInt32() / 100.0f; GSGE.Debug.assert(mPitchVariationMin < 24); mLoopCount = reader.ReadInt32(); // funnel fixed sound cues to a specific variation so I don't have to deal with it for others if (mEntries.Length == 1) mVariation = 0; else if (mVariation == 4) { shuffle = new int[mEntries.Length]; shuffleIdx = mEntries.Length; } // give it an invalid initial cue idx so nothing is assumed about its previous play currIdx = mEntries.Length; }
internal override void Read(System.IO.BinaryReader reader, BinaryReadInfo readInfo) { uint length = reader.ReadUInt32(); ID = reader.ReadUInt32(); uint numSections = reader.ReadUInt32(); string componentName = null; bool canResize = false; bool canFlip = false; double minSize = ComponentHelper.GridSize; List<ComponentProperty> properties = new List<ComponentProperty>(); List<ConnectionGroup> connections = new List<ConnectionGroup>(); List<RenderDescription> renderDescriptions = new List<RenderDescription>(); List<Conditional<FlagOptions>> flagOptions = new List<Conditional<FlagOptions>>(); ComponentDescriptionMetadata descriptionMetadata = new ComponentDescriptionMetadata(); uint? iconResourceId = null; for (uint sectionCounter = 0; sectionCounter < numSections; sectionCounter++) { ushort sectionType = reader.ReadUInt16(); uint sectionLength = reader.ReadUInt32(); #region Metadata if (sectionType == (uint)BinaryConstants.ComponentSectionType.Metadata) { componentName = reader.ReadString(); canResize = reader.ReadBoolean(); canFlip = reader.ReadBoolean(); minSize = reader.ReadDouble(); descriptionMetadata.Type = String.Format("Binary r{0} (*.cdcom)", readInfo.FormatVersion); descriptionMetadata.GUID = new Guid(reader.ReadBytes(16)); descriptionMetadata.Author = reader.ReadString(); if (readInfo.IsSignatureValid && readInfo.Certificate != null && readInfo.IsCertificateTrusted) descriptionMetadata.Author = readInfo.Certificate.GetNameInfo(X509NameType.EmailName, false); descriptionMetadata.Version = new Version(reader.ReadUInt16(), reader.ReadUInt16()); descriptionMetadata.AdditionalInformation = reader.ReadString(); descriptionMetadata.ImplementSet = reader.ReadString(); descriptionMetadata.ImplementItem = reader.ReadString(); descriptionMetadata.Signature.IsHashValid = readInfo.IsSignatureValid; descriptionMetadata.Signature.Certificate = readInfo.Certificate; descriptionMetadata.Signature.IsCertificateTrusted = readInfo.IsCertificateTrusted; int iconResource = reader.ReadInt32(); if (iconResource != -1) iconResourceId = (uint)iconResource; long created = reader.ReadInt64(); } #endregion #region Flags else if (sectionType == (uint)BinaryConstants.ComponentSectionType.Flags) { uint numFlagGroups = reader.ReadUInt32(); for (uint j = 0; j < numFlagGroups; j++) { IConditionTreeItem conditions; if (readInfo.FormatVersion > 1) conditions = reader.ReadConditionTree(); else conditions = reader.ReadConditionCollection(); FlagOptions value = (FlagOptions)reader.ReadUInt32(); flagOptions.Add(new Conditional<FlagOptions>(value, conditions)); } } #endregion #region Properties else if (sectionType == (uint)BinaryConstants.ComponentSectionType.Properties) { uint numProperties = reader.ReadUInt32(); for (uint j = 0; j < numProperties; j++) { string propertyName = reader.ReadString(); string serializedName = reader.ReadString(); string displayName = reader.ReadString(); BinaryType propType; object rawDefaultValue = reader.ReadType(out propType); PropertyUnion defaultValue = propType.ToPropertyUnion(rawDefaultValue); string[] enumOptions = null; if (propType == BinaryType.Enum) { enumOptions = new string[reader.ReadInt32()]; for (int k = 0; k < enumOptions.Length; k++) enumOptions[k] = reader.ReadString(); } // Format rules List<ComponentPropertyFormat> formatRules = new List<ComponentPropertyFormat>(); uint numFormatRules = reader.ReadUInt32(); for (uint k = 0; k < numFormatRules; k++) { IConditionTreeItem conditions; if (readInfo.FormatVersion > 1) conditions = reader.ReadConditionTree(); else conditions = reader.ReadConditionCollection(); string formatRule = reader.ReadString(); formatRules.Add(new ComponentPropertyFormat(formatRule, conditions)); } // Other conditions uint numOtherConditions = reader.ReadUInt32(); Dictionary<PropertyOtherConditionType, IConditionTreeItem> otherConditions = new Dictionary<PropertyOtherConditionType, IConditionTreeItem>((int)numOtherConditions); for (uint k = 0; k < numOtherConditions; k++) { uint uintConditionType = reader.ReadUInt32(); IConditionTreeItem conditions; if (readInfo.FormatVersion > 1) conditions = reader.ReadConditionTree(); else conditions = reader.ReadConditionCollection(); PropertyOtherConditionType conditionType = (PropertyOtherConditionType)uintConditionType; otherConditions.Add(conditionType, conditions); } properties.Add(new ComponentProperty(propertyName, serializedName, displayName, BinaryIOExtentions.BinaryTypeToPropertyType(propType), defaultValue, formatRules.ToArray(), otherConditions, enumOptions)); } } #endregion #region Configurations else if (sectionType == (uint)BinaryConstants.ComponentSectionType.Configurations) { uint numConfigurations = reader.ReadUInt32(); for (int j = 0; j < numConfigurations; j++) { string configurationName = reader.ReadString(); string implementationName = reader.ReadString(); int numSetters = reader.ReadInt32(); var setters = new Dictionary<string, PropertyUnion>(numSetters); for (int k = 0; k < numSetters; k++) { BinaryType tempType; string name = reader.ReadString(); var setterValue = reader.ReadType(out tempType); setters.Add(name, tempType.ToPropertyUnion(setterValue)); } int iconID = reader.ReadInt32(); var configuration = new ComponentConfiguration(implementationName, configurationName, setters); descriptionMetadata.Configurations.Add(configuration); if (iconID != -1) iconResources.Add(configuration, (uint)iconID); } } #endregion #region Connections else if (sectionType == (uint)BinaryConstants.ComponentSectionType.Connections) { uint numConnectionGroups = reader.ReadUInt32(); List<ConnectionGroup> connectionGroups = new List<ConnectionGroup>(); for (int j = 0; j < numConnectionGroups; j++) { IConditionTreeItem conditions; if (readInfo.FormatVersion > 1) conditions = reader.ReadConditionTree(); else conditions = reader.ReadConditionCollection(); List<ConnectionDescription> tConnections = new List<ConnectionDescription>(); uint numConnections = reader.ReadUInt32(); for (uint k = 0; k < numConnections; k++) { tConnections.Add(new ConnectionDescription(reader.ReadComponentPoint(), reader.ReadComponentPoint(), (ConnectionEdge)reader.ReadInt32(), reader.ReadString())); } connections.Add(new ConnectionGroup(conditions, tConnections.ToArray())); } } #endregion #region Render else if (sectionType == (uint)BinaryConstants.ComponentSectionType.Render) { uint numRenderGroups = reader.ReadUInt32(); for (uint j = 0; j < numRenderGroups; j++) { IConditionTreeItem conditions; if (readInfo.FormatVersion > 1) conditions = reader.ReadConditionTree(); else conditions = reader.ReadConditionCollection(); int numRenderCommands = (int)reader.ReadUInt32(); List<IRenderCommand> renderCommands = new List<IRenderCommand>(numRenderCommands); for (int k = 0; k < numRenderCommands; k++) { RenderCommandType commandType = (RenderCommandType)reader.ReadUInt32(); switch (commandType) { case RenderCommandType.Line: { ComponentPoint start = reader.ReadComponentPoint(); ComponentPoint end = reader.ReadComponentPoint(); double thickness = reader.ReadDouble(); renderCommands.Add(new Line(start, end, thickness)); } continue; case RenderCommandType.Rect: { ComponentPoint location = reader.ReadComponentPoint(); double width = reader.ReadDouble(); double height = reader.ReadDouble(); double thickness = reader.ReadDouble(); bool fill = (reader.ReadUInt32() == 0 ? false : true); renderCommands.Add(new Rectangle(location, width, height, thickness, fill)); } continue; case RenderCommandType.Ellipse: { ComponentPoint centre = reader.ReadComponentPoint(); double radiusX = reader.ReadDouble(); double radiusY = reader.ReadDouble(); double thickness = reader.ReadDouble(); bool fill = (reader.ReadUInt32() == 0 ? false : true); renderCommands.Add(new Ellipse(centre, radiusX, radiusY, thickness, fill)); } continue; case RenderCommandType.Path: { ComponentPoint start = reader.ReadComponentPoint(); double thickness = reader.ReadDouble(); bool fill = (reader.ReadUInt32() == 0 ? false : true); int numCommands = reader.ReadInt32(); List<IPathCommand> pathCommands = new List<IPathCommand>(numCommands); for (int l = 0; l < numCommands; l++) { CommandType pType = (CommandType)reader.ReadInt32(); IPathCommand theCommand = null; switch (pType) { case CommandType.MoveTo: theCommand = new MoveTo(); break; case CommandType.LineTo: theCommand = new LineTo(); break; case CommandType.CurveTo: theCommand = new CurveTo(); break; case CommandType.EllipticalArcTo: theCommand = new EllipticalArcTo(); break; case CommandType.QuadraticBeizerCurveTo: theCommand = new QuadraticBeizerCurveTo(); break; case CommandType.SmoothCurveTo: theCommand = new SmoothCurveTo(); break; case CommandType.SmoothQuadraticBeizerCurveTo: theCommand = new SmoothQuadraticBeizerCurveTo(); break; default: theCommand = new ClosePath(); break; } theCommand.Read(reader); pathCommands.Add(theCommand); } renderCommands.Add(new RenderPath(start, thickness, fill, pathCommands)); } continue; case RenderCommandType.Text: { byte formattedTextVersion = reader.ReadByte(); ComponentPoint location = reader.ReadComponentPoint(); TextAlignment alignment = (TextAlignment)reader.ReadUInt32(); uint numTextRuns = reader.ReadUInt32(); List<TextRun> textRuns = new List<TextRun>((int)numTextRuns); for (uint l = 0; l < numTextRuns; l++) { TextRunFormattingType formattingType = (TextRunFormattingType)reader.ReadUInt32(); double runSize = reader.ReadDouble(); string runText = reader.ReadString(); textRuns.Add(new TextRun(runText, new TextRunFormatting(formattingType, runSize))); } renderCommands.Add(new Text(location, alignment, textRuns)); } continue; } } renderDescriptions.Add(new RenderDescription(conditions, renderCommands.ToArray())); } } #endregion #region Skip else { // Unknown type - skip reader.BaseStream.Seek(sectionLength, SeekOrigin.Current); } #endregion } ComponentDescription = new ComponentDescription(ID.ToString(), componentName, canResize, canFlip, minSize, properties.ToArray(), connections.ToArray(), renderDescriptions.ToArray(), flagOptions.ToArray(), descriptionMetadata); if (iconResourceId.HasValue) mainIconResource = iconResourceId.Value; }