コード例 #1
0
        internal DbfRecord(BinaryReader reader, DbfHeader header, List <DbfField> fields, byte[] memoData, Encoding encoding)
        {
            this.fields = fields;
            Data        = new List <object>();

            // Read record marker.
            byte marker = reader.ReadByte();

            // Read entire record as sequence of bytes.
            // Note that record length includes marker.
            byte[] row = reader.ReadBytes(header.RecordLength - 1);

            // Read data for each field.
            int offset = 0;

            foreach (DbfField field in fields)
            {
                // Copy bytes from record buffer into field buffer.
                byte[] buffer = new byte[field.Length];
                Array.Copy(row, offset, buffer, 0, field.Length);
                offset += field.Length;

                IEncoder encoder = EncoderFactory.GetEncoder(field.Type);
                Data.Add(encoder.Decode(buffer, memoData, encoding));
            }
        }
コード例 #2
0
        public static async Task RunServerAsync(int port, EncoderFactory encryptor, DecoderFactory decryptor, bool isWorldClient)
        {
            MultithreadEventLoopGroup bossGroup   = new MultithreadEventLoopGroup(1);
            MultithreadEventLoopGroup workerGroup = new MultithreadEventLoopGroup();

            try
            {
                ServerBootstrap bootstrap = new ServerBootstrap();
                bootstrap
                .Group(bossGroup, workerGroup)
                .Channel <TcpServerSocketChannel>()
                .ChildHandler(new ActionChannelInitializer <ISocketChannel>(channel =>
                {
                    SessionFactory.Instance.Sessions[channel.Id.AsLongText()] = 0;
                    IChannelPipeline pipeline = channel.Pipeline;
                    pipeline.AddLast((MessageToMessageDecoder <IByteBuffer>)decryptor.GetDecoder());
                    pipeline.AddLast(new ClientSession(channel, isWorldClient));
                    pipeline.AddLast((MessageToMessageEncoder <string>)encryptor.GetEncoder());
                }));

                IChannel bootstrapChannel = await bootstrap.BindAsync(port).ConfigureAwait(false);

                Console.ReadLine();

                await bootstrapChannel.CloseAsync().ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex.Message);
            }
            finally
            {
                Task.WaitAll(bossGroup.ShutdownGracefullyAsync(), workerGroup.ShutdownGracefullyAsync());
            }
        }
コード例 #3
0
        /// <summary>
        /// Return the encoded contents, including mime
        /// header.
        /// </summary>
        /// <returns></returns>
        public String ToDataString()
        {
            IEncoder      encoder = EncoderFactory.GetEncoder(Encoding);
            StringBuilder sb      = new StringBuilder();

            sb.Append(GetInternalMimeHeader(encoder));
            sb.Append(GetEncodedContents(encoder));
            return(sb.ToString());
        }
コード例 #4
0
ファイル: ppxEditor.cs プロジェクト: aa2g/SB3Utility
        public void ExportSubfile(string arcname, string name, string path)
        {
            var subfile = GetSubfile(arcname, name);

            using (FileStream fs = new FileStream(path, FileMode.Create))
                using (IEncoder encoder = EncoderFactory.GetEncoder(subfile, Archive))
                    using (Stream stream = encoder.Decode())
                        stream.CopyTo(fs);
        }
コード例 #5
0
ファイル: ppxEditor.cs プロジェクト: aa2g/SB3Utility
        public Stream ReadSubfile(string archiveName, string name)
        {
            var file = GetSubfile(archiveName, name);

            if (file == null)
            {
                throw new Exception("Couldn't find the subfile " + archiveName + "/" + name);
            }

            using (IEncoder encoder = EncoderFactory.GetEncoder(file, Archive))
                return(encoder.Decode());
        }
コード例 #6
0
        internal void Write(BinaryWriter writer)
        {
            // Write marker (always "not deleted")
            writer.Write((byte)0x20);

            int index = 0;

            foreach (DbfField field in fields)
            {
                IEncoder encoder = EncoderFactory.GetEncoder(field.Type);
                byte[]   buffer  = encoder.Encode(field, data[index]);
                writer.Write(buffer);
                index++;
            }
        }
コード例 #7
0
        internal void Write(BinaryWriter writer, Encoding encoding)
        {
            // Write marker (always "not deleted")
            writer.Write((byte)0x20);

            int index = 0;

            foreach (DbfField field in fields)
            {
                IEncoder encoder = EncoderFactory.GetEncoder(field.Type);
                byte[]   buffer  = encoder.Encode(field, Data[index], encoding);
                if (buffer.Length > field.Length)
                {
                    throw new ArgumentOutOfRangeException(nameof(buffer.Length), buffer.Length, "Buffer length has exceeded length of the field.");
                }

                writer.Write(buffer);
                index++;
            }
        }
コード例 #8
0
ファイル: DbfRecord.cs プロジェクト: amit-labs/dbf-reader
        internal void Write(BinaryWriter writer)
        {
            // Write marker (always "not deleted")
            writer.Write((byte)0x20);

            int index = 0;

            foreach (DbfField field in fields)
            {
                IEncoder encoder = EncoderFactory.GetEncoder(field.Type);
                byte[]   buffer;
                if (data[index] == null)
                {
                    buffer = Encoding.ASCII.GetBytes("");
                }
                else
                {
                    buffer = encoder.Encode(field, data[index]);
                }
                writer.Write(buffer);
                index++;
            }
        }
コード例 #9
0
ファイル: EmailMessage.cs プロジェクト: prasaathp/Application
        /// <summary>
        /// Render the encoded message for smtp "DATA" transmission.
        /// This is the final version that will get sent to the
        /// </summary>
        /// <returns></returns>
        public String ToDataString()
        {
            IEncoder encoder = EncoderFactory.GetEncoder(HeaderEncoding);

            return(ToDataStringHeaders(this.HeaderCharSet, encoder) + SmtpProxy.ENDOFLINE + ToDataStringBody());
        }