コード例 #1
0
ファイル: Service.cs プロジェクト: NameIsBad/NetRpc
        public Stream EchoStream(Stream data)
        {
            Console.WriteLine($"[EchoStream]...Received length:{data.Length}, {Helper.ReadStr(data)}...Send TestFile.txt");
            var stream = File.Open(Helper.GetTestFilePath(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            return(stream);
        }
コード例 #2
0
        public async Task <ComplexStream> ComplexCallAsync(CustomObj obj, string p1, Stream stream, Func <CustomCallbackObj, Task> cb, CancellationToken token)
        {
            Console.WriteLine($"[ComplexCallAsync]...receive:{obj}, p1:{p1}, streamLength:{stream.Length}");

            for (var i = 1; i <= 3; i++)
            {
                Console.Write($"{i}, ");
                await cb(new CustomCallbackObj { Progress = i });

                await Task.Delay(1000, token);
            }

            var ret = new ComplexStream
            {
                Stream     = File.Open(Helper.GetTestFilePath(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite),
                StreamName = "TestFile.txt",
                InnerObj   = new InnerObj
                {
                    CustomObj = new CustomObj
                    {
                        Name = NameEnum.John
                    },
                    P1 = "中文p1!@#$%^&*()_+\"\":?~!@#$"
                }
            };

            return(ret);
        }
コード例 #3
0
ファイル: Service.cs プロジェクト: NameIsBad/NetRpc
        public Stream GetStream()
        {
            Console.WriteLine("[GetStream]...Send TestFile.txt");
            var stream = File.Open(Helper.GetTestFilePath(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            return(stream);
        }
コード例 #4
0
ファイル: Service.cs プロジェクト: NameIsBad/NetRpc
 public ComplexStream GetComplexStream()
 {
     Console.WriteLine("[GetComplexStream]...Send TestFile.txt...this is other info");
     return(new ComplexStream
     {
         Stream = File.Open(Helper.GetTestFilePath(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite),
         OtherInfo = "this is other info"
     });
 }
コード例 #5
0
 private static void Test_EchoStream()
 {
     using (var stream = File.Open(Helper.GetTestFilePath(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
     {
         Console.Write("[EchoStream]...Send TestFile.txt...");
         var data = _proxy.EchoStream(stream);
         Console.WriteLine($"Received length:{data.Length}, {Helper.ReadStr(data)}");
     }
 }
コード例 #6
0
        private static async Task Test_EchoStreamAsync()
        {
            using (var stream = File.Open(Helper.GetTestFilePath(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                Console.Write("[EchoStreamAsync]...Send TestFile.txt...");
                var data = await _proxyAsync.EchoStreamAsync(stream);

                Console.WriteLine($"Received length:{stream.Length}, {Helper.ReadStr(data)}");
            }
        }
コード例 #7
0
        private static async Task Test_ComplexCallAsync()
        {
            using (var stream = File.Open(Helper.GetTestFilePath(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                Console.Write("[ComplexCallAsync]...Send TestFile.txt...");
                var complexStream = await _c1.Proxy.ComplexCallAsync(
                    new CustomObj { Date = DateTime.Now, Name = "ComplexCall" },
                    stream,
                    async i => Console.Write(", " + i.Progress),
                    default);

                using (var stream2 = complexStream.Stream)
                    Console.Write($", receive length:{stream.Length}, {Helper.ReadStr(stream2)}");
                Console.WriteLine($", otherInfo:{complexStream.OtherInfo}");
            }
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: NameIsBad/NetRpc
        public async Task <Ret> Call(InParam p, int i, Stream stream, Func <int, Task> progs, CancellationToken token)
        {
            Console.WriteLine($"{p}, {i}, {Helper.ReadStr(stream)}");

            for (var i1 = 0; i1 < 3; i1++)
            {
                await progs(i1);

                await Task.Delay(100, token);
            }

            return(new Ret
            {
                Stream = File.OpenRead(Helper.GetTestFilePath()),
                P1 = "return p1"
            });
        }
コード例 #9
0
        public async Task <ComplexStream> ComplexCallAsync(CustomObj obj, Stream data, Func <CustomCallbackObj, Task> cb, CancellationToken token)
        {
            Console.Write($"[ComplexCallAsync]...Received length:{data.Length}, {Helper.ReadStr(data)}, ");
            for (var i = 1; i <= 3; i++)
            {
                Console.Write($"{i}, ");
                await cb(new CustomCallbackObj { Progress = i });

                await Task.Delay(100, token);
            }

            Console.WriteLine("...Send TestFile.txt");
            return(new ComplexStream
            {
                Stream = File.Open(Helper.GetTestFilePath(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite),
                OtherInfo = "this is other info"
            });
        }
コード例 #10
0
ファイル: Service.cs プロジェクト: NameIsBad/NetRpc
        public ComplexStream ComplexCall(CustomObj obj, Stream data, Func <CustomCallbackObj, Task> cb)
        {
            Console.Write($"[ComplexCall]...Received length:{data.Length}, {Helper.ReadStr(data)}, ");
            for (var i = 1; i <= 3; i++)
            {
                Console.Write($"{i}, ");
                cb(new CustomCallbackObj {
                    Progress = i
                });
                Task.Delay(100).Wait();
            }

            Console.WriteLine("...Send TestFile.txt");
            return(new ComplexStream
            {
                Stream = File.Open(Helper.GetTestFilePath(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite),
                OtherInfo = "this is other info"
            });
        }
コード例 #11
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            try
            {
                var ret = await _s1.Call(
                    new InParam {P1 = "123"}, 100,
                    File.OpenRead(Helper.GetTestFilePath()),
                    async i => Console.WriteLine(i),
                    CancellationToken.None);
                Console.WriteLine($"ret:{ret.P1}, {Helper.ReadStr(ret.Stream)}");

                using (var fs = File.OpenWrite(@"d:\1.rar"))
                {
                    ret.Stream.CopyTo(fs);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
コード例 #12
0
 private static async Task Test_SetStreamAsync()
 {
     Console.Write("[SetStreamAsync]...Send TestFile.txt");
     using (var stream = File.Open(Helper.GetTestFilePath(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
         await _proxyAsync.SetStreamAsync(stream);
 }
コード例 #13
0
 private static void Test_SetStream()
 {
     Console.Write("[SetStream]...Send TestFile.txt");
     using (var stream = File.Open(Helper.GetTestFilePath(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
         _proxy.SetStream(stream);
 }