Exemple #1
0
        private void RetrunResultData(ReturnResult result)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                BinaryWriter bufflist = new BinaryWriter(stream);

                if (EncodingHandler != null)
                {
                    bufflist.Write(CmdDef.ReturnResult);
                    byte[] classdata = BufferFormat.SerializeObject(result);
                    bufflist.Write(classdata.Length);
                    bufflist.Write(classdata);

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

                    stream.Position = 0;
                    stream.SetLength(0);
                    bufflist.Write(0);
                    bufflist.Write(fdata);
                }
                else
                {
                    bufflist.Write(0);
                    bufflist.Write(CmdDef.ReturnResult);
                    byte[] classdata = BufferFormat.SerializeObject(result);
                    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();
#if !COREFX
                stream.Close();
#endif
                stream.Dispose();

                SendData(pdata);
            }
        }
Exemple #2
0
        /// <summary>
        /// CALL RETURN
        /// </summary>
        /// <param name="cmdTag"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public ResultAwatier Func(int cmdTag, params object[] args)
        {
            CallPack buffer = new CallPack()
            {
                Id        = Common.MakeID,
                CmdTag    = cmdTag,
                Arguments = new List <byte[]>(args.Length)
            };

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

                buffer.Arguments.Add(Serialization.PackSingleObject(type, item));
            }


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

                if (CCloudClient.EncodingHandler != null)
                {
                    bufflist.Write(CmdDef.CallCmd);

                    bufflist.Write(buffer.Id);
                    bufflist.Write(buffer.CmdTag);
                    bufflist.Write(buffer.Arguments.Count);
                    foreach (var arg in buffer.Arguments)
                    {
                        bufflist.Write(arg.Length);
                        bufflist.Write(arg);
                    }

                    byte[] fdata = CCloudClient.EncodingHandler(stream.ToArray());

                    stream.Position = 0;
                    stream.SetLength(0);
                    bufflist.Write(0);
                    bufflist.Write(fdata);
                }
                else
                {
                    bufflist.Write(0);
                    bufflist.Write(CmdDef.CallCmd);

                    bufflist.Write(buffer.Id);
                    bufflist.Write(buffer.CmdTag);
                    bufflist.Write(buffer.Arguments.Count);
                    foreach (var arg in buffer.Arguments)
                    {
                        bufflist.Write(arg.Length);
                        bufflist.Write(arg);
                    }
                }

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

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

                stream.Position = 0;

                bufflist.Write(data);


                byte[] pdata = stream.ToArray();


                CCloudClient.AddAsyncCallBack(this, buffer.Id);

                CallSend?.Invoke(pdata);
            }

            return(_fiber.Read());
        }
Exemple #3
0
        private void RetrunResultData(Result result)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                BinaryWriter bufflist = new BinaryWriter(stream);

                if (EncodingHandler != null)
                {
                    bufflist.Write(CmdDef.ReturnResult);

                    bufflist.Write(result.Id);
                    bufflist.Write(result.ErrorId);
                    if (string.IsNullOrEmpty(result.ErrorMsg))
                    {
                        bufflist.Write(0);
                    }
                    else
                    {
                        byte[] strdata = Encoding.UTF8.GetBytes(result.ErrorMsg);
                        bufflist.Write(strdata.Length);
                        bufflist.Write(strdata);
                    }

                    bufflist.Write(result.Arguments.Count);
                    foreach (var arg in result.Arguments)
                    {
                        bufflist.Write(arg.Length);
                        bufflist.Write(arg);
                    }

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

                    stream.Position = 0;
                    stream.SetLength(0);
                    bufflist.Write(0);
                    bufflist.Write(fdata);
                }
                else
                {
                    bufflist.Write(0);
                    bufflist.Write(CmdDef.ReturnResult);

                    bufflist.Write(result.Id);
                    bufflist.Write(result.ErrorId);
                    if (string.IsNullOrEmpty(result.ErrorMsg))
                    {
                        bufflist.Write(0);
                    }
                    else
                    {
                        byte[] strdata = Encoding.UTF8.GetBytes(result.ErrorMsg);
                        bufflist.Write(strdata.Length);
                        bufflist.Write(strdata);
                    }

                    bufflist.Write(result.Arguments.Count);
                    foreach (var arg in result.Arguments)
                    {
                        bufflist.Write(arg.Length);
                        bufflist.Write(arg);
                    }
                }

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

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

                stream.Position = 0;

                bufflist.Write(data);


                byte[] pdata = stream.ToArray();


                SendData(pdata);
            }
        }
Exemple #4
0
        public override ResultAwatier CR(int cmdTag, params object[] args)
        {
            CallPack buffer = new CallPack()
            {
                Id        = Common.MakeID,
                CmdTag    = cmdTag,
                Arguments = new List <byte[]>(args.Length)
            };

            this.Id = buffer.Id;

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

                buffer.Arguments.Add(Serialization.PackSingleObject(type, item));
            }


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

                if (CCloudClient.EncodingHandler != null)
                {
                    bufflist.Write(CmdDef.CallCmd);
                    byte[] classdata = BufferFormat.SerializeObject(buffer);
                    bufflist.Write(classdata.Length);
                    bufflist.Write(classdata);

                    byte[] fdata = CCloudClient.EncodingHandler(stream.ToArray());

                    stream.Position = 0;
                    stream.SetLength(0);
                    bufflist.Write(0);
                    bufflist.Write(fdata);
                }
                else
                {
                    bufflist.Write(0);
                    bufflist.Write(CmdDef.CallCmd);
                    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();
#if !COREFX
                stream.Close();
#endif
                stream.Dispose();

                CCloudClient.AddAsyncRunBack(this, buffer.Id);

                if (CallSend != null)
                {
                    CallSend(pdata);
                }
            }


            if (awaiter == null)
            {
                awaiter = new ResultAwatier();
            }

            return(base.awaiter);
        }
Exemple #5
0
        public ReturnResult CR(int cmdTag, params object[] args)
        {
            CallPack buffer = new CallPack()
            {
                Id        = Common.MakeID,
                CmdTag    = cmdTag,
                Arguments = new List <byte[]>(args.Length)
            };

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

                buffer.Arguments.Add(Serialization.PackSingleObject(type, item));
            }


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

                if (dataExtra != null)
                {
                    bufflist.Write(CmdDef.CallCmd);
                    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(CmdDef.CallCmd);
                    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();
#if !COREFX
                stream.Close();
#endif
                stream.Dispose();



                return(SendDataAsWait(buffer.Id, pdata));
            }
        }
Exemple #6
0
        public void Action(int cmdTag, params object[] args)
        {
            CallPack buffer = new CallPack()
            {
                Id        = Common.MakeID,
                CmdTag    = cmdTag,
                Arguments = new List <byte[]>(args.Length)
            };

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

                buffer.Arguments.Add(Serialization.PackSingleObject(type, item));
            }


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

                if (DataExtra != null)
                {
                    bufflist.Write(CmdDef.CallCmd);

                    bufflist.Write(buffer.Id);
                    bufflist.Write(buffer.CmdTag);
                    bufflist.Write(buffer.Arguments.Count);
                    foreach (var arg in buffer.Arguments)
                    {
                        bufflist.Write(arg.Length);
                        bufflist.Write(arg);
                    }

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

                    stream.Position = 0;
                    stream.SetLength(0);
                    bufflist.Write(0);
                    bufflist.Write(fdata);
                }
                else
                {
                    bufflist.Write(0);
                    bufflist.Write(CmdDef.CallCmd);

                    bufflist.Write(buffer.Id);
                    bufflist.Write(buffer.CmdTag);
                    bufflist.Write(buffer.Arguments.Count);
                    foreach (var arg in buffer.Arguments)
                    {
                        bufflist.Write(arg.Length);
                        bufflist.Write(arg);
                    }
                }

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

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

                stream.Position = 0;

                bufflist.Write(data);


                byte[] pdata = stream.ToArray();


                SendData(pdata);
            }
        }