Exemple #1
0
        public void Save()
        {
            BigEndianBinaryWriter TROPUSRWriter =
                new BigEndianBinaryWriter(new FileStream(path + "TROPUSR.DAT", FileMode.Open));

            TROPUSRWriter.Write(header.StructToBytes());
            TypeRecord account_id_Record = typeRecordTable[2];

            TROPUSRWriter.BaseStream.Position = account_id_Record.Offset + 32; // 空行
            TROPUSRWriter.Write(account_id.ToCharArray());                     // 帳號


            TypeRecord trophy_id_Record = typeRecordTable[3];

            TROPUSRWriter.BaseStream.Position = trophy_id_Record.Offset + 16;
            TROPUSRWriter.Write(trophy_id.ToCharArray()); // 獎杯ID
            TROPUSRWriter.BaseStream.Position = trophy_id_Record.Offset + 80;
            //TROPUSRWriter.Write(AchievementRate[0]); // 完成度
            //TROPUSRWriter.Write(AchievementRate[1]); // 完成度
            //TROPUSRWriter.Write(AchievementRate[2]); // 完成度
            //TROPUSRWriter.Write(AchievementRate[3]); // 完成度



            TypeRecord TrophyType_Record = typeRecordTable[4];

            TROPUSRWriter.BaseStream.Position = TrophyType_Record.Offset;
            foreach (TrophyType type in trophyTypeTable)
            {
                TROPUSRWriter.BaseStream.Position += 16;
                TROPUSRWriter.Write(type.StructToBytes());
            }

            TypeRecord trophyListInfo_Record = typeRecordTable[5];

            TROPUSRWriter.BaseStream.Position = trophyListInfo_Record.Offset + 16;
            TROPUSRWriter.Write(trophyListInfo.StructToBytes());


            TypeRecord TrophyTimeInfo_Record = typeRecordTable[6];

            TROPUSRWriter.BaseStream.Position = TrophyTimeInfo_Record.Offset;
            foreach (TrophyTimeInfo time in trophyTimeInfoTable)
            {
                TROPUSRWriter.BaseStream.Position += 16;
                TROPUSRWriter.Write(time.StructToBytes());
            }

            TypeRecord unknowType7_Record = typeRecordTable[7];

            TROPUSRWriter.BaseStream.Position = unknowType7_Record.Offset + 16;
            TROPUSRWriter.Write(unknowType7.StructToBytes());

            TROPUSRWriter.Flush();
            TROPUSRWriter.Close();
        }
Exemple #2
0
 private void SendMessage(IPeerContext peerContext, Action <BinaryWriter> constructMessage)
 {
     using (var ms = new MemoryStream())
     {
         BinaryWriter writer = new BigEndianBinaryWriter(ms);
         constructMessage(writer);
         writer.Flush();
         peerContext.SendMessage(ExtensionProtocolMessageId, ms.ToArray());
     }
 }
Exemple #3
0
        protected Task Send(UdpTrackerRequestMessage message)
        {
            var ms     = new MemoryStream();
            var writer = new BigEndianBinaryWriter(ms);

            message.WriteTo(writer);
            writer.Flush();

            return(client.SendAsync(ms.ToArray(), (int)ms.Length, trackerUri.Host, trackerUri.Port));
        }
Exemple #4
0
 public void SendMessage(byte messageId, byte[] data)
 {
     using (var ms = new MemoryStream())
     {
         BinaryWriter writer = new BigEndianBinaryWriter(ms);
         writer.Write(messageId);
         writer.Write(data);
         writer.Flush();
         Peer.Send(ms.ToArray());
     }
 }
        public string PrintToString(string language)
        {
            var stream = new MemoryStream();

            using (var writer = new BigEndianBinaryWriter(stream))
            {
                writer.Write(language);
                writer.Flush();
                var response = _client.SendRequestWithResponse(new Request(FUNCTION_READER_PRINT_TO_STRING, stream.ToArray(), _objectId));
                using (var reader = response.Reader)
                    return(reader.ReadString());
            }
        }
Exemple #6
0
            // Mock out the web request
            protected override Task <Stream> HttpGet(string requestUri)
            {
                BDictionary response;

                if (compact)
                {
                    var ms     = new MemoryStream();
                    var writer = new BigEndianBinaryWriter(ms);

                    // Peer 1
                    writer.Write(new byte[] { 192, 168, 0, 1 });
                    writer.Write((ushort)5001);

                    // Peer 2
                    writer.Write(new byte[] { 192, 168, 0, 2 });
                    writer.Write((ushort)5002);

                    writer.Flush();

                    response = new BDictionary
                    {
                        ["peers"] = new BString(ms.ToArray())
                    };
                }
                else
                {
                    response = new BDictionary
                    {
                        ["peers"] = new BList
                        {
                            new BDictionary
                            {
                                ["ip"]   = new BString("192.168.0.1"),
                                ["port"] = new BNumber(5001)
                            },
                            new BDictionary
                            {
                                ["ip"]   = new BString("192.168.0.2"),
                                ["port"] = new BNumber(5002)
                            }
                        }
                    };
                }

                var resultStream = new MemoryStream(response.EncodeAsBytes());

                return(Task.FromResult((Stream)resultStream));
            }
            private byte[] BuildResponse()
            {
                BDictionary response;

                if (_compact)
                {
                    var ms     = new MemoryStream();
                    var writer = new BigEndianBinaryWriter(ms);

                    // Peer 1
                    writer.Write(new byte[] { 192, 168, 0, 1 });
                    writer.Write((ushort)5001);

                    // Peer 2
                    writer.Write(new byte[] { 192, 168, 0, 2 });
                    writer.Write((ushort)5002);

                    writer.Flush();

                    response = new BDictionary
                    {
                        ["peers"] = new BString(ms.ToArray()),
                    };
                }
                else
                {
                    response = new BDictionary
                    {
                        ["peers"] = new BList
                        {
                            new BDictionary
                            {
                                ["ip"]   = new BString("192.168.0.1"),
                                ["port"] = new BNumber(5001),
                            },
                            new BDictionary
                            {
                                ["ip"]   = new BString("192.168.0.2"),
                                ["port"] = new BNumber(5002),
                            },
                        },
                    };
                }

                return(response.EncodeAsBytes());
            }
        public void PrintReports(Stream output, string language)
        {
            if (!output.CanWrite)
            {
                throw new ArgumentException("Stream is not writable.");
            }
            var wrapper = new RemoteStreamWrapper(_client, output);
            var id      = _client.RegisterLocalObject(wrapper);
            var stream  = new MemoryStream();

            using (var writer = new BigEndianBinaryWriter(stream))
            {
                writer.Write(wrapper.ObjectId);
                writer.Write(language);
                writer.Flush();
                _client.SendRequestWithResponse(new Request(FUNCTION_READER_PRINT_REPORTS, stream.ToArray(), _objectId));
            }
        }
Exemple #9
0
        public void Save()
        {
            using (var fileStream = new FileStream(Path.Combine(path, TROPUSR_FILE_NAME), FileMode.Open))
                using (var TROPUSRWriter = new BigEndianBinaryWriter(fileStream))
                {
                    TROPUSRWriter.Write(header.StructToBytes());
                    TypeRecord account_id_Record = typeRecordTable[2];
                    TROPUSRWriter.BaseStream.Position = account_id_Record.Offset + 32; // 空行
                    TROPUSRWriter.Write(this.account_id);                              // 帳號

                    TypeRecord trophy_id_Record = typeRecordTable[3];
                    TROPUSRWriter.BaseStream.Position = trophy_id_Record.Offset + 16;
                    TROPUSRWriter.Write(trophy_id.ToCharArray()); // 獎杯ID
                    TROPUSRWriter.BaseStream.Position = trophy_id_Record.Offset + 80;

                    TypeRecord TrophyType_Record = typeRecordTable[4];
                    TROPUSRWriter.BaseStream.Position = TrophyType_Record.Offset;
                    foreach (TrophyType type in trophyTypeTable)
                    {
                        TROPUSRWriter.BaseStream.Position += 16;
                        TROPUSRWriter.Write(type.StructToBytes());
                    }

                    TypeRecord trophyListInfo_Record = typeRecordTable[5];
                    TROPUSRWriter.BaseStream.Position = trophyListInfo_Record.Offset + 16;
                    TROPUSRWriter.Write(trophyListInfo.StructToBytes());

                    TypeRecord TrophyTimeInfo_Record = typeRecordTable[6];
                    TROPUSRWriter.BaseStream.Position = TrophyTimeInfo_Record.Offset;
                    foreach (TrophyTimeInfo time in trophyTimeInfoTable)
                    {
                        TROPUSRWriter.BaseStream.Position += 16;
                        TROPUSRWriter.Write(time.StructToBytes());
                    }

                    TypeRecord unknowType7_Record = typeRecordTable[7];
                    TROPUSRWriter.BaseStream.Position = unknowType7_Record.Offset + 16;
                    TROPUSRWriter.Write(unknowType7.StructToBytes());

                    TROPUSRWriter.Flush();
                    TROPUSRWriter.Close();
                }
        }
Exemple #10
0
        public void Save()
        {
            BigEndianBinaryWriter TROPUSRWriter = new BigEndianBinaryWriter(new FileStream(path + "TROPUSR.DAT", FileMode.Open));
            TROPUSRWriter.Write(header.StructToBytes());
            TypeRecord account_id_Record = typeRecordTable[2];
            TROPUSRWriter.BaseStream.Position = account_id_Record.Offset + 32; // 空行
            TROPUSRWriter.Write(account_id.ToCharArray()); // 帳號

            TypeRecord trophy_id_Record = typeRecordTable[3];
            TROPUSRWriter.BaseStream.Position = trophy_id_Record.Offset + 16;
            TROPUSRWriter.Write(trophy_id.ToCharArray()); // 獎杯ID
            TROPUSRWriter.BaseStream.Position = trophy_id_Record.Offset + 80;
            //TROPUSRWriter.Write(AchievementRate[0]); // 完成度
            //TROPUSRWriter.Write(AchievementRate[1]); // 完成度
            //TROPUSRWriter.Write(AchievementRate[2]); // 完成度
            //TROPUSRWriter.Write(AchievementRate[3]); // 完成度

            TypeRecord TrophyType_Record = typeRecordTable[4];
            TROPUSRWriter.BaseStream.Position = TrophyType_Record.Offset;
            foreach (TrophyType type in trophyTypeTable) {
                TROPUSRWriter.BaseStream.Position += 16;
                TROPUSRWriter.Write(type.StructToBytes());
            }

            TypeRecord trophyListInfo_Record = typeRecordTable[5];
            TROPUSRWriter.BaseStream.Position = trophyListInfo_Record.Offset + 16;
            TROPUSRWriter.Write(trophyListInfo.StructToBytes());

            TypeRecord TrophyTimeInfo_Record = typeRecordTable[6];
            TROPUSRWriter.BaseStream.Position = TrophyTimeInfo_Record.Offset;
            foreach (TrophyTimeInfo time in trophyTimeInfoTable) {
                TROPUSRWriter.BaseStream.Position += 16;
                TROPUSRWriter.Write(time.StructToBytes());
            }

            TypeRecord unknowType7_Record = typeRecordTable[7];
            TROPUSRWriter.BaseStream.Position = unknowType7_Record.Offset + 16;
            TROPUSRWriter.Write(unknowType7.StructToBytes());

            TROPUSRWriter.Flush();
            TROPUSRWriter.Close();
        }
Exemple #11
0
 public void Send(byte[] data)
 {
     writer.Write(data.Length);
     writer.Write(data);
     writer.Flush();
 }
        /// <summary>
        /// Writes an entire shapefile to disk in one call using a geometryCollection.
        /// </summary>
        /// <remarks>
        /// Assumes the type given for the first geometry is the same for all subsequent geometries.
        /// For example, is, if the first Geometry is a Multi-polygon/ Polygon, the subsequent geometies are
        /// Muli-polygon/ polygon and not lines or points.
        /// The dbase file for the corresponding shapefile contains one column called row. It contains 
        /// the row number.
        /// </remarks>
        /// <param name="filename">The filename to write to (minus the .shp extension).</param>
        /// <param name="geometryCollection">The GeometryCollection to write.</param>		
        public virtual void Write(string filename, GeometryCollection geometryCollection)
        {
            System.IO.FileStream shpStream = new System.IO.FileStream(filename + ".shp", System.IO.FileMode.Create);
            System.IO.FileStream shxStream = new System.IO.FileStream(filename + ".shx", System.IO.FileMode.Create);
            BigEndianBinaryWriter shpBinaryWriter = new BigEndianBinaryWriter(shpStream);
            BigEndianBinaryWriter shxBinaryWriter = new BigEndianBinaryWriter(shxStream);

            // assumes
            ShapeHandler handler = Shapefile.GetShapeHandler(Shapefile.GetShapeType(geometryCollection.Geometries[0]));

            IGeometry body;
            int numShapes = geometryCollection.NumGeometries;
            // calc the length of the shp file, so it can put in the header.
            int shpLength = 50;
            for (int i = 0; i < numShapes; i++)
            {
                body = geometryCollection.Geometries[i];
                shpLength += 4; // length of header in WORDS
                shpLength += handler.GetLength(body); // length of shape in WORDS
            }

            int shxLength = 50 + (4 * numShapes);

            // write the .shp header
            ShapefileHeader ShapeHeader = new ShapefileHeader();
            ShapeHeader.FileLength = shpLength;

            // get envelope in external coordinates
            IEnvelope env = geometryCollection.EnvelopeInternal;
            IEnvelope bounds = ShapeHandler.GetEnvelopeExternal(new PrecisionModel(geometryFactory.PrecisionModel), env);
            ShapeHeader.Bounds = bounds;

            // assumes Geometry type of the first item will the same for all other items
            // in the collection.
            ShapeHeader.ShapeType = Shapefile.GetShapeType(geometryCollection.Geometries[0]);
            ShapeHeader.Write(shpBinaryWriter);

            // write the .shx header
            ShapefileHeader shxHeader = new ShapefileHeader();
            shxHeader.FileLength = shxLength;
            shxHeader.Bounds = ShapeHeader.Bounds;

            // assumes Geometry type of the first item will the same for all other items in the collection.
            shxHeader.ShapeType = Shapefile.GetShapeType(geometryCollection.Geometries[0]);
            shxHeader.Write(shxBinaryWriter);

            // write the individual records.
            int _pos = 50; // header length in WORDS
            for (int i = 0; i < numShapes; i++)
            {
                body = geometryCollection.Geometries[i];
                int recordLength = handler.GetLength(body);
                shpBinaryWriter.WriteIntBE(i + 1);
                shpBinaryWriter.WriteIntBE(recordLength);

                shxBinaryWriter.WriteIntBE(_pos);
                shxBinaryWriter.WriteIntBE(recordLength);

                _pos += 4; // length of header in WORDS
                handler.Write(body, shpBinaryWriter, geometryFactory);
                _pos += recordLength; // length of shape in WORDS
            }

            shxBinaryWriter.Flush();
            shxBinaryWriter.Close();
            shpBinaryWriter.Flush();
            shpBinaryWriter.Close();

            // WriteDummyDbf(filename + ".dbf", numShapes);	
        }
        /// <summary>
        /// Writes the geometry information from the specified IFeatureLayer to the file
        /// </summary>
        /// <param name="filename">A filename</param>
        /// <param name="Layer">An IFeatureLayer to save</param>
        public virtual void Write(string filename, IFeatureSet Layer)
        {
            if (Layer == null) return;
            if (Layer.Features == null) return;
            if (Layer.Features.Count == 0) return;
            string rootname, shpFile, shxFile;
            
            rootname = System.IO.Path.GetDirectoryName(filename) + "\\" + System.IO.Path.GetFileNameWithoutExtension(filename);
            shpFile = rootname + ".shp";
            shxFile = rootname + ".shx";
            
            System.IO.FileStream shpStream = new System.IO.FileStream(shpFile, System.IO.FileMode.Create);
            System.IO.FileStream shxStream = new System.IO.FileStream(shxFile, System.IO.FileMode.Create);
            BigEndianBinaryWriter shpBinaryWriter = new BigEndianBinaryWriter(shpStream);
            BigEndianBinaryWriter shxBinaryWriter = new BigEndianBinaryWriter(shxStream);

            // assumes
           // ShapeHandler handler = Shapefile.GetShapeHandler(Shapefile.GetShapeType(geometryCollection.Geometries[0]));

            ShapeHandler handler = null;

            switch (Layer.Features[0].FeatureType)
            {
                case FeatureTypes.Unspecified: return;
                case FeatureTypes.Line: handler = new MultiLineHandler();
                    break;
                case FeatureTypes.Point: handler = new PointHandler();
                    break;
                case FeatureTypes.Polygon: handler = new PolygonHandler();
                    break;
            }

            IBasicGeometry body;
            int numShapes = Layer.Features.Count;
            // calc the length of the shp file, so it can put in the header.
            int shpLength = 50;
            for (int i = 0; i < numShapes; i++)
            {
                body = Layer.Features[i].BasicGeometry;
                shpLength += 4; // length of header in WORDS
                shpLength += handler.GetLength(body); // length of shape in WORDS
            }

            int shxLength = 50 + (4 * numShapes);

            // write the .shp header
            ShapefileHeader ShapeHeader = new ShapefileHeader();
            ShapeHeader.FileLength = shpLength;

            // get envelope in external coordinates
            IEnvelope env = Layer.Envelope;
            //IEnvelope bounds = ShapeHandler.GetEnvelopeExternal(new PrecisionModel(geometryFactory.PrecisionModel), env);
            ShapeHeader.Bounds = env;

            // write the .shx header
            ShapefileHeader shxHeader = new ShapefileHeader();
            shxHeader.FileLength = shxLength;
            shxHeader.Bounds = ShapeHeader.Bounds;

            // assumes Geometry type of the first item will the same for all other items
            // in the collection.
            switch(Layer.FeatureType)
            {
                case FeatureTypes.Polygon:
                    ShapeHeader.ShapeType = ShapeGeometryTypes.Polygon;
                    shxHeader.ShapeType = ShapeGeometryTypes.Polygon;
                    break;
                case FeatureTypes.Point:
                    ShapeHeader.ShapeType = ShapeGeometryTypes.Point;
                    shxHeader.ShapeType = ShapeGeometryTypes.Point;
                    break;
                case FeatureTypes.Line:
                    ShapeHeader.ShapeType = ShapeGeometryTypes.LineString;
                    shxHeader.ShapeType = ShapeGeometryTypes.LineString;
                    break;
            }
            
            ShapeHeader.Write(shpBinaryWriter);

            // assumes Geometry type of the first item will the same for all other items in the collection.
            
            shxHeader.Write(shxBinaryWriter);

            // write the individual records.
            int _pos = 50; // header length in WORDS
            for (int i = 0; i < numShapes; i++)
            {
                body = Layer.Features[i].BasicGeometry;
                int recordLength = handler.GetLength(body);
                shpBinaryWriter.WriteIntBE(i + 1);
                shpBinaryWriter.WriteIntBE(recordLength);

                shxBinaryWriter.WriteIntBE(_pos);
                shxBinaryWriter.WriteIntBE(recordLength);

                _pos += 4; // length of header in WORDS
                handler.Write(body, shpBinaryWriter, geometryFactory);
                _pos += recordLength; // length of shape in WORDS
            }

            shxBinaryWriter.Flush();
            shxBinaryWriter.Close();
            shpBinaryWriter.Flush();
            shpBinaryWriter.Close();

        }
Exemple #14
0
        public void Save()
        {
            BigEndianBinaryWriter TROPTRNSWriter = new BigEndianBinaryWriter(new FileStream(path + "TROPTRNS.DAT", FileMode.Open));

            TROPTRNSWriter.Write(header.StructToBytes());
            TypeRecord account_id_Record = typeRecordTable[2];

            TROPTRNSWriter.BaseStream.Position = account_id_Record.Offset + 32; // 空行
            TROPTRNSWriter.Write(account_id.ToCharArray());

            TypeRecord trophy_id_Record = typeRecordTable[3];

            TROPTRNSWriter.BaseStream.Position = trophy_id_Record.Offset + 16; // 空行
            TROPTRNSWriter.Write(trophy_id.ToCharArray());
            TROPTRNSWriter.BaseStream.Position = trophy_id_Record.Offset + 32; // 字串長度不定,直接跳過
            TROPTRNSWriter.Write(u1);
            Console.WriteLine(trophyInfoTable.Count);
            TROPTRNSWriter.Write(trophyInfoTable.Count + 1); // AllGetTrophysCount
            AllSyncPSNTrophyCount = 0;
            for (int i = 0; i < trophyInfoTable.Count; i++)
            {
                if (trophyInfoTable[i].IsSync)
                {
                    AllSyncPSNTrophyCount++;
                }
            }
            // AllSyncPSNTrophyCount++;
            TROPTRNSWriter.Write(AllSyncPSNTrophyCount + 1);

            // Type 4
            TypeRecord TrophyType_Record = typeRecordTable[4];

            TROPTRNSWriter.BaseStream.Position  = TrophyType_Record.Offset;
            TROPTRNSWriter.BaseStream.Position += 16;
            TROPTRNSWriter.Write(trophyInitTime.StructToBytes());


            for (int i = 0; i < trophyInfoTable.Count; i++)
            {
                TROPTRNSWriter.BaseStream.Position += 16;
                TrophyInfo ti = trophyInfoTable[i];
                ti.SequenceNumber = i + 1; // 整理順序
                //if (i == 0) {
                //    ti._unknowInt2 = 0x100000;
                //} else {
                //    ti._unknowInt2 = 0x100000;
                //}
                ti._unknowInt3 = 0;

                trophyInfoTable[i] = ti;
                TROPTRNSWriter.Write(trophyInfoTable[i].StructToBytes());
            }

            byte[] emptyStruct = new byte[Marshal.SizeOf(typeof(TrophyInfo))];
            Array.Clear(emptyStruct, 0, emptyStruct.Length);
            TrophyInfo emptyTrophyInfo = emptyStruct.ToStruct <TrophyInfo>();

            for (int i = trophyInfoTable.Count; i < TrophyType_Record.Size; i++)
            {
                TROPTRNSWriter.BaseStream.Position += 16;
                emptyTrophyInfo.SequenceNumber      = i + 1;
                TROPTRNSWriter.Write(emptyTrophyInfo.StructToBytes());
            }


            TROPTRNSWriter.Flush();
            TROPTRNSWriter.Close();
        }
Exemple #15
0
        public void Save()
        {
            BigEndianBinaryWriter TROPTRNSWriter = new BigEndianBinaryWriter(new FileStream(path + "TROPTRNS.DAT", FileMode.Open));
            TROPTRNSWriter.Write(header.StructToBytes());
            TypeRecord account_id_Record = typeRecordTable[2];
            TROPTRNSWriter.BaseStream.Position = account_id_Record.Offset + 32; // 空行
            TROPTRNSWriter.Write(account_id.ToCharArray());

            TypeRecord trophy_id_Record = typeRecordTable[3];
            TROPTRNSWriter.BaseStream.Position = trophy_id_Record.Offset + 16; // 空行
            TROPTRNSWriter.Write(trophy_id.ToCharArray());
            TROPTRNSWriter.BaseStream.Position = trophy_id_Record.Offset + 32; // 字串長度不定,直接跳過
            TROPTRNSWriter.Write(u1);
            Console.WriteLine(trophyInfoTable.Count);
            TROPTRNSWriter.Write(trophyInfoTable.Count+1); // AllGetTrophysCount
            AllSyncPSNTrophyCount = 0;
            for (int i = 0; i < trophyInfoTable.Count; i++) {
                if (trophyInfoTable[i].IsSync) {
                    AllSyncPSNTrophyCount++;
                }
            }
            // AllSyncPSNTrophyCount++;
            TROPTRNSWriter.Write(AllSyncPSNTrophyCount+1);

            // Type 4
            TypeRecord TrophyType_Record = typeRecordTable[4];
            TROPTRNSWriter.BaseStream.Position = TrophyType_Record.Offset;
            TROPTRNSWriter.BaseStream.Position += 16;
            TROPTRNSWriter.Write(trophyInitTime.StructToBytes());

            for (int i = 0; i < trophyInfoTable.Count; i++) {
                TROPTRNSWriter.BaseStream.Position += 16;
                TrophyInfo ti = trophyInfoTable[i];
                ti.SequenceNumber = i+1; // 整理順序
                //if (i == 0) {
                //    ti._unknowInt2 = 0x100000;
                //} else {
                //    ti._unknowInt2 = 0x100000;
                //}
                ti._unknowInt3 = 0;

                trophyInfoTable[i] = ti;
                TROPTRNSWriter.Write(trophyInfoTable[i].StructToBytes());
            }

            byte[] emptyStruct = new byte[Marshal.SizeOf(typeof(TrophyInfo))];
            Array.Clear(emptyStruct, 0, emptyStruct.Length);
            TrophyInfo emptyTrophyInfo = emptyStruct.ToStruct<TrophyInfo>();
            for (int i = trophyInfoTable.Count; i < TrophyType_Record.Size; i++) {
                TROPTRNSWriter.BaseStream.Position += 16;
                emptyTrophyInfo.SequenceNumber = i + 1;
                TROPTRNSWriter.Write(emptyTrophyInfo.StructToBytes());
            }

            TROPTRNSWriter.Flush();
            TROPTRNSWriter.Close();
        }
        /// <summary>
        /// Writes a shapefile to disk.
        /// </summary>
        /// <remarks>
        /// Assumes the type given for the first geometry is the same for all subsequent geometries.
        /// For example, is, if the first Geometry is a Multi-polygon/ Polygon, the subsequent geometies are
        /// Muli-polygon/ polygon and not lines or points.
        /// The dbase file for the corresponding shapefile contains one column called row. It contains
        /// the row number.
        /// </remarks>
        /// <param name="filename">The filename to write to (minus the .shp extension).</param>
        /// <param name="geometryCollection">The GeometryCollection to write.</param>
        public void Write(IGeometryCollection geometryCollection)
        {
            //FileStream shpStream = new FileStream(filename + ".shp", FileMode.Create);
            //FileStream shxStream = new FileStream(filename + ".shx", FileMode.Create);

            shpStream = new MemoryStream();
            shxStream = new MemoryStream();
            BigEndianBinaryWriter shpBinaryWriter = new BigEndianBinaryWriter(shpStream);
            BigEndianBinaryWriter shxBinaryWriter = new BigEndianBinaryWriter(shxStream);

            // assumes
            ShapeHandler handler = Shapefile.GetShapeHandler(GetShapeType(geometryCollection.Geometries[0]));

            IGeometry body;
            int       numShapes = geometryCollection.NumGeometries;
            // calc the length of the shp file, so it can put in the header.
            int shpLength = 50;

            for (int i = 0; i < numShapes; i++)
            {
                body       = (IGeometry)geometryCollection.Geometries[i];
                shpLength += 4;                                          // length of header in WORDS
                shpLength += handler.ComputeRequiredLengthInWords(body); // length of shape in WORDS
            }

            int shxLength = 50 + (4 * numShapes);

            // write the .shp header
            ShapefileHeader shpHeader = new ShapefileHeader();

            shpHeader.FileLength = shpLength;

            // get envelope in external coordinates
            Envelope env    = geometryCollection.EnvelopeInternal as Envelope;
            Envelope bounds = ShapeHandler.GetEnvelopeExternal(geometryFactory.PrecisionModel, env);

            shpHeader.Bounds = bounds;

            // assumes Geometry type of the first item will the same for all other items
            // in the collection.
            shpHeader.ShapeType = GetShapeType(geometryCollection.Geometries[0]);
            shpHeader.Write(shpBinaryWriter);

            // write the .shx header
            ShapefileHeader shxHeader = new ShapefileHeader();

            shxHeader.FileLength = shxLength;
            shxHeader.Bounds     = shpHeader.Bounds;

            // assumes Geometry type of the first item will the same for all other items in the collection.
            shxHeader.ShapeType = GetShapeType(geometryCollection.Geometries[0]);
            shxHeader.Write(shxBinaryWriter);

            // write the individual records.
            int _pos = 50; // header length in WORDS

            for (int i = 0; i < numShapes; i++)
            {
                body = geometryCollection.Geometries[i];
                int recordLength = handler.ComputeRequiredLengthInWords(body);
                shpBinaryWriter.WriteIntBE(i + 1);
                shpBinaryWriter.WriteIntBE(recordLength);

                shxBinaryWriter.WriteIntBE(_pos);
                shxBinaryWriter.WriteIntBE(recordLength);

                _pos += 4;            // length of header in WORDS
                handler.Write(body, shpBinaryWriter, geometryFactory);
                _pos += recordLength; // length of shape in WORDS
            }

            shxBinaryWriter.Flush();
            //shxStream.Seek(0, SeekOrigin.Begin);
            ////shxBinaryWriter.Close();
            shpBinaryWriter.Flush();
            //shpStream.Seek(0, SeekOrigin.Begin);
            //shpBinaryWriter.Close();

            // WriteDummyDbf(filename + ".dbf", numShapes);
        }