Exemplo n.º 1
0
        public void Run(ReadBytes read)
        {
            int cmd = read.ReadInt32();

            if (CallsMethods.ContainsKey(cmd))
            {
                AutoBuffer buffer = read.ReadObject <AutoBuffer>();

                object[] args = null;

                if (CallsArgsTable.ContainsKey(cmd))
                {
                    var argsTypeTable = CallsArgsTable[cmd];

                    if (argsTypeTable.Count > 0 && argsTypeTable.Count == buffer.Args.Count)
                    {
                        args = new object[argsTypeTable.Count];

                        for (int i = 0; i < argsTypeTable.Count; i++)
                        {
                            args[i] = UnpackSingleObject(argsTypeTable[i], buffer.Args[i]);
                        }
                    }

                    CallsMethods[cmd].Invoke(null, args);
                }
            }
        }
Exemplo n.º 2
0
        public void Run <T1, T2, T3>(ReadBytes read, T1 obj1, T2 obj2, T3 obj3)
        {
            int cmd = read.ReadInt32();

            if (CallsMethods.ContainsKey(cmd))
            {
                AutoBuffer buffer = read.ReadObject <AutoBuffer>();

                object[] args = null;

                if (CallsArgsTable.ContainsKey(cmd))
                {
                    var argsTypeTable = CallsArgsTable[cmd];

                    if (argsTypeTable.Count > 0 && argsTypeTable.Count == (buffer.Args.Count + 3))
                    {
                        args = new object[argsTypeTable.Count];

                        args[0] = obj1;
                        args[1] = obj2;
                        args[2] = obj3;

                        int x = 3;
                        for (int i = 0; i < (argsTypeTable.Count - 3); i++)
                        {
                            x       = i + 3;
                            args[x] = UnpackSingleObject(argsTypeTable[x], buffer.Args[i]);
                        }
                    }

                    CallsMethods[cmd].Invoke(null, args);
                }
            }
        }
Exemplo n.º 3
0
 protected HttpMetadataReaderBase(KeekStream stream, ManualResetEvent stopSignal)
 {
     _stream     = stream;
     _buffer     = new AutoBuffer();
     _stopSignal = stopSignal;
     _timeout    = TimeSpan.FromMilliseconds(TIMEOUT_MILLISECONDS);
 }
Exemplo n.º 4
0
        public static byte[] Call(int cmd, FDataExtraHandle dataExtra, params object[] args)
        {
            AutoBuffer buffer = new AutoBuffer()
            {
                Args = new List <byte[]>(args.Length)
            };


            foreach (var item in args)
            {
                Type type = item.GetType();

                buffer.Args.Add(PackSingleObject(type, item));
            }


            using (MemoryStream stream = new MemoryStream())
            {
                BinaryWriter bufflist = new BinaryWriter(stream);

                if (dataExtra != null)
                {
                    bufflist.Write(cmd);
                    byte[] classdata = BufferFormat.SerializeObject(buffer);
                    bufflist.Write(classdata.Length);
                    bufflist.Write(classdata);

                    byte[] fdata = dataExtra(stream.ToArray());

                    stream.Position = 0;
                    stream.SetLength(0);
                    bufflist.Write(0);
                    bufflist.Write(fdata);
                }
                else
                {
                    bufflist.Write(0);
                    bufflist.Write(cmd);
                    byte[] classdata = BufferFormat.SerializeObject(buffer);
                    bufflist.Write(classdata.Length);
                    bufflist.Write(classdata);
                }

                int l = (int)(stream.Length);

                byte[] data = BufferFormat.GetSocketBytes(l);

                stream.Position = 0;

                bufflist.Write(data);


                byte[] pdata = stream.ToArray();

                stream.Dispose();

                return(pdata);
            }
        }
Exemplo n.º 5
0
 public ChunkedContentRedirector(
     ManualResetEvent signal,
     KeekStream sourceStream,
     AutoBuffer sourceBuffer,
     Stream destinationStream)
 {
     _signal            = signal;
     _sourceStream      = sourceStream;
     _sourceBuffer      = sourceBuffer;
     _destinationStream = destinationStream;
 }
Exemplo n.º 6
0
 public FixedSizeContentRedirector(
     ManualResetEvent signal,
     Stream sourceStream,
     AutoBuffer sourceBuffer,
     Stream destinationStream,
     int length)
 {
     _signal            = signal;
     _sourceStream      = sourceStream;
     _sourceBuffer      = sourceBuffer;
     _destinationStream = destinationStream;
     _length            = length;
 }
Exemplo n.º 7
0
        public static byte[] CallV2(int cmd, FDataExtraHandle dataExtra, params object[] args)
        {
            AutoBuffer buffer = new AutoBuffer()
            {
                Args = new List <byte[]>(args.Length)
            };


            foreach (var item in args)
            {
                Type type = item.GetType();

                buffer.Args.Add(PackSingleObject(type, item));
            }


            using (MemoryStream stream = new MemoryStream())
            {
                BinaryWriter bufflist = new BinaryWriter(stream);

                bufflist.Write(BufferFormatV2.GetBytes(cmd));

                byte[] classdata = BufferFormatV2.SerializeObject(buffer);
                bufflist.Write(BufferFormatV2.GetBytes(classdata.Length));
                bufflist.Write(classdata);


                byte[] fdata = null;

                if (dataExtra != null)
                {
                    fdata = dataExtra(stream.ToArray());
                }
                else
                {
                    fdata = stream.ToArray();
                }

                stream.Position = 0;
                stream.SetLength(0);



                int x = fdata.Length;

                if ((fdata.Length + 1) < 128)
                {
                    x += 1;
                }
                else if ((fdata.Length + 2) < 16384)
                {
                    x += 2;
                }
                else if ((fdata.Length + 3) < 2097152)
                {
                    x += 3;
                }
                else
                {
                    x += 4;
                }

                byte[] tmp = BufferFormatV2.GetBytes(x);

                int l = fdata.Length + tmp.Length;

                byte[] data = BufferFormatV2.GetBytes(l);

                bufflist.Write((byte)0xFF);
                bufflist.Write(data);
                bufflist.Write(fdata);

                byte[] pdata = stream.ToArray();
                stream.Dispose();
                return(pdata);
            }
        }