示例#1
0
        private static async Task MainAsync(string[] args)
        {
            try
            {
                IpcServiceClient <IComputingService> computingClient = new IpcServiceClientBuilder <IComputingService>()
                                                                       .UseNamedPipe("pipeName")
                                                                       .Build();

                IpcServiceClient <ISystemService> systemClient = new IpcServiceClientBuilder <ISystemService>()
                                                                 .UseTcp(IPAddress.Loopback, 45684)
                                                                 .Build();

                // test 1: call IPC service method with primitive types
                float result1 = await computingClient.InvokeAsync(x => x.AddFloat(1.23f, 4.56f));

                Console.WriteLine($"[TEST 1] sum of 2 floating number is: {result1}");

                // test 2: call IPC service method with complex types
                ComplexNumber result2 = await computingClient.InvokeAsync(x => x.AddComplexNumber(
                                                                              new ComplexNumber(0.1f, 0.3f),
                                                                              new ComplexNumber(0.2f, 0.6f)));

                Console.WriteLine($"[TEST 2] sum of 2 complexe number is: {result2.A}+{result2.B}i");

                // test 3: call IPC service method with an array of complex types
                ComplexNumber result3 = await computingClient.InvokeAsync(x => x.AddComplexNumbers(new[]
                {
                    new ComplexNumber(0.5f, 0.4f),
                    new ComplexNumber(0.2f, 0.1f),
                    new ComplexNumber(0.3f, 0.5f),
                }));

                Console.WriteLine($"[TEST 3] sum of 3 complexe number is: {result3.A}+{result3.B}i");

                // test 4: call IPC service method without parameter or return
                await systemClient.InvokeAsync(x => x.DoNothing());

                Console.WriteLine($"[TEST 4] invoked DoNothing()");

                // test 5: call IPC service method with enum parameter
                string text = await systemClient.InvokeAsync(x => x.ConvertText("hEllO woRd!", TextStyle.Upper));

                Console.WriteLine($"[TEST 5] {text}");

                // test 6: call IPC service method returning GUID
                Guid generatedId = await systemClient.InvokeAsync(x => x.GenerateId());

                Console.WriteLine($"[TEST 6] generated ID is: {generatedId}");

                // test 7: call IPC service method with byte array
                byte[] input    = Encoding.UTF8.GetBytes("Test");
                byte[] reversed = await systemClient.InvokeAsync(x => x.ReverseBytes(input));

                Console.WriteLine($"[TEST 7] reversed bytes are: {Convert.ToBase64String(reversed)}");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
示例#2
0
        public static async Task Main(string[] args)
        {
            var pipeClient = new IpcServiceClientBuilder <ICalculatorService>()
                             .UseNamedPipe("pipeName") // or .UseTcp(IPAddress.Loopback, 45684) to invoke using TCP
                             .Build();

            var result = await pipeClient.InvokeAsync(x => x.Execute(new Calculation()
            {
                Operand1 = 1,
                Operand2 = 2,
                Opertor  = "+"
            }));

            Console.WriteLine(result.Result);

            var tcpClient = new IpcServiceClientBuilder <ICalculatorService>()
                            .UseTcp(IPAddress.Loopback, 45684)
                            .Build();

            result = await tcpClient.InvokeAsync(x => x.Execute(new Calculation()
            {
                Operand1 = 1,
                Operand2 = 2,
                Opertor  = "+"
            }));

            Console.WriteLine(result.Result);
        }
示例#3
0
        static async Task <int> Main()
        {
            try
            {
                var config = new ConfigurationBuilder()
                             .AddJsonFile("appsettings.json")
                             .AddJsonFile("appsettings.Development.json", true)
                             .Build();

                var client = new IpcServiceClientBuilder <Api.IFtpServerHost>()
                             .UseNamedPipe("ftpserver")
                             .Build();

                var simpleModuleInfoNames = await client.InvokeAsync(host => host.GetSimpleModules())
                                            .ConfigureAwait(false);

                var extendedModuleInfoName = await client.InvokeAsync(host => host.GetExtendedModules())
                                             .ConfigureAwait(false);

                var services = new ServiceCollection()
                               .AddLogging(builder => builder.AddConfiguration(config.GetSection("Logging")).AddConsole())
                               .AddSingleton(client)
                               .AddSingleton <IShellStatus>(new ShellStatus(simpleModuleInfoNames, extendedModuleInfoName))
                               .Scan(
                    ts => ts
                    .FromAssemblyOf <FtpShellCommandAutoCompletion>()
                    .AddClasses(itf => itf.AssignableTo <ICommandInfo>(), true).As <ICommandInfo>()
                    .WithSingletonLifetime())
                               .AddSingleton <FtpShellCommandAutoCompletion>()
                               .AddSingleton <ServerShell>();

                var serviceProvider = services.BuildServiceProvider(true);

                var shell = serviceProvider.GetRequiredService <ServerShell>();
                await shell.RunAsync(CancellationToken.None)
                .ConfigureAwait(false);

                return(0);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
                return(1);
            }
        }
示例#4
0
        static async Task Main(string[] args)
        {
            // starting a server
            new Thread(StartServer).Start();

            // sending requests to the server
            IpcServiceClient <IComputingService> client = new IpcServiceClientBuilder <IComputingService>()
                                                          .UseTcp(IPAddress.Loopback, 45684)
                                                          .Build();

            float result = await client.InvokeAsync(x => x.AddFloat(1.23f, 4.56f));

            Console.WriteLine($"AddFloat result is {result}");

            var stream = await client.InvokeAsync(x => x.GetMemoryStream());

            Console.WriteLine($"Length of stream is {stream.Length}");

            Console.ReadKey();
        }
示例#5
0
        public async Task <IActionResult> Report(int?id)
        {
            if (id == null)
            {
                return(View("Index"));
            }

            var place = await _context.Places
                        .FirstOrDefaultAsync(m => m.ID == id);

            if (place != null)
            {
                // AwesomePDF.PDFGenerator generator = new AwesomePDF.PDFGenerator("PDF");
                // var result = generator.GeneratePDF(place.Name, place.Image, place.Text);
                // return new FileContentResult(System.IO.File.ReadAllBytes(result), "application/pdf");

                IpcServiceClient <IPDFService> client = new IpcServiceClientBuilder <IPDFService>().UseNamedPipe("generatePDF").Build();
                var result = await client.InvokeAsync(x => x.GeneratePDF(place.Name, place.Image, place.Text));

                return(new FileContentResult(System.IO.File.ReadAllBytes(result), "application/pdf"));
            }

            return(View("Index"));
        }
示例#6
0
        private static async Task RunTestsAsync(CancellationToken cancellationToken)
        {
            IpcServiceClient <IComputingService> computingClient = new IpcServiceClientBuilder <IComputingService>()
                                                                   .UseNamedPipe("pipeName")
                                                                   .Build();

            IpcServiceClient <ISystemService> systemClient = new IpcServiceClientBuilder <ISystemService>()
                                                             .UseTcp(IPAddress.Loopback, 45684)
                                                             .Build();

            // test 1: call IPC service method with primitive types
            float result1 = await computingClient.InvokeAsync(x => x.AddFloat(1.23f, 4.56f), cancellationToken);

            Console.WriteLine($"[TEST 1] sum of 2 floating number is: {result1}");

            // test 2: call IPC service method with complex types
            ComplexNumber result2 = await computingClient.InvokeAsync(x => x.AddComplexNumber(
                                                                          new ComplexNumber(0.1f, 0.3f),
                                                                          new ComplexNumber(0.2f, 0.6f)), cancellationToken);

            Console.WriteLine($"[TEST 2] sum of 2 complexe number is: {result2.A}+{result2.B}i");

            // test 3: call IPC service method with an array of complex types
            ComplexNumber result3 = await computingClient.InvokeAsync(x => x.AddComplexNumbers(new[]
            {
                new ComplexNumber(0.5f, 0.4f),
                new ComplexNumber(0.2f, 0.1f),
                new ComplexNumber(0.3f, 0.5f),
            }), cancellationToken);

            Console.WriteLine($"[TEST 3] sum of 3 complexe number is: {result3.A}+{result3.B}i", cancellationToken);

            // test 4: call IPC service method without parameter or return
            await systemClient.InvokeAsync(x => x.DoNothing(), cancellationToken);

            Console.WriteLine($"[TEST 4] invoked DoNothing()");

            // test 5: call IPC service method with enum parameter
            string text = await systemClient.InvokeAsync(x => x.ConvertText("hEllO woRd!", TextStyle.Upper), cancellationToken);

            Console.WriteLine($"[TEST 5] {text}");

            // test 6: call IPC service method returning GUID
            Guid generatedId = await systemClient.InvokeAsync(x => x.GenerateId(), cancellationToken);

            Console.WriteLine($"[TEST 6] generated ID is: {generatedId}");

            // test 7: call IPC service method with byte array
            byte[] input    = Encoding.UTF8.GetBytes("Test");
            byte[] reversed = await systemClient.InvokeAsync(x => x.ReverseBytes(input), cancellationToken);

            Console.WriteLine($"[TEST 7] reversed bytes are: {Convert.ToBase64String(reversed)}");

            // test 8: call IPC service method with generic parameter
            string print = await systemClient.InvokeAsync(x => x.Printout(DateTime.UtcNow), cancellationToken);

            Console.WriteLine($"[TEST 8] print out value: {print}");

            // test 9: call slow IPC service method
            await systemClient.InvokeAsync(x => x.SlowOperation(), cancellationToken);

            Console.WriteLine($"[TEST 9] Called slow operation");
        }