public ActionResult Index()
        {
            ViewBag.Title    = $"Home Page";
            ViewBag.SumValue = $"Result of 10 + 20 = {service.Add(10, 20)}";

            return(View());
        }
Пример #2
0
        private static void Add10000MultiThreading(ILog log, ICalcService calcClient, int totalCalls, int threadCount)
        {
            log.DebugFormat("Add10000MultiThreading, TotalCalls[{0}], ThreadCount[{1}], start ...", totalCalls, threadCount);

            var taskList = new Task[threadCount];
            var watch    = Stopwatch.StartNew();

            for (int i = 0; i < threadCount; i++)
            {
                var task = Task.Factory.StartNew(() =>
                {
                    for (var j = 0; j < totalCalls / threadCount; j++)
                    {
                        calcClient.Add(new AddRequest()
                        {
                            X = 1, Y = 2
                        });
                    }
                },
                                                 TaskCreationOptions.PreferFairness);
                taskList[i] = task;
            }
            Task.WaitAll(taskList);
            watch.Stop();

            log.DebugFormat("Add10000MultiThreading, TotalCalls[{0}], ThreadCount[{1}], end with cost [{2}] ms."
                            + "{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}",
                            totalCalls, threadCount, watch.ElapsedMilliseconds,
                            Environment.NewLine, string.Format("   Concurrency level: {0} threads", threadCount),
                            Environment.NewLine, string.Format("   Complete requests: {0}", totalCalls),
                            Environment.NewLine, string.Format("Time taken for tests: {0} seconds", (decimal)watch.ElapsedMilliseconds / 1000m),
                            Environment.NewLine, string.Format("    Time per request: {0:#####0.000} ms (avg)", (decimal)watch.ElapsedMilliseconds / (decimal)totalCalls),
                            Environment.NewLine, string.Format(" Requests per second: {0} [#/sec] (avg)", (int)((decimal)totalCalls / ((decimal)watch.ElapsedMilliseconds / 1000m)))
                            );
        }
Пример #3
0
        private static void TestCalcService()
        {
            // Öffnet die Http Verbindung und ruft CalcService.svc auf. Diese Route muss in Configure
            // der Datei Startup.cs registiert werden.
            BasicHttpBinding binding  = new BasicHttpBinding();
            EndpointAddress  endpoint = new EndpointAddress($"{BaseUrl}/CalcService.asmx");
            // Jetzt kommt das Interface ins Spiel. Der Request ruft Methoden von ICalcService
            // auf, deswegen verwenden wir hier das Interface.
            ChannelFactory <ICalcService> channelFactory = new ChannelFactory <ICalcService>(binding, endpoint);
            ICalcService serviceClient = channelFactory.CreateChannel();

            // Nun können wir ganz normal Methoden aufrufen, wie wenn wir eine lokale
            // Klasse hätten, die das Interface implementiert.
            int result = serviceClient.Add(1, 3);
            List <CalcStats> calcCount = serviceClient.GetCalculationCount();

            channelFactory.Close();

            Console.WriteLine($"=========================");
            Console.WriteLine($"Das Ergebnis ist {result}");
            foreach (var c in calcCount)
            {
                Console.WriteLine($"Operator {c.Operation}: {c.Count} Berechnungen durchgeführt.");
            }
        }
Пример #4
0
        private static void Add(ILog log, ICalcService calcClient)
        {
            var response = calcClient.Add(new AddRequest()
            {
                X = 3, Y = 4
            });

            log.DebugFormat("Add, receive add response from server with [{0}].", response.Result);
        }
Пример #5
0
        public ActionResult PassUsingViewData()
        {
            var a = this.rngService.Number(-1000, 1001);
            var b = this.rngService.Number(-1000, 1001);

            this.ViewData["A"]   = a;
            this.ViewData["B"]   = b;
            this.ViewData["Add"] = calcService.Add(a, b);
            this.ViewData["Sub"] = calcService.Sub(a, b);
            this.ViewData["Mul"] = calcService.Mul(a, b);
            if (b == 0)
            {
                this.ViewData["Div"] = "Division by zero";
            }
            else
            {
                this.ViewData["Div"] = calcService.Div(a, b);
            }

            return(this.View());
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "calc/add")] HttpRequestMessage req, ILogger log)
        {
            try
            {
                var calreq = await req.ParseContentAndThrow <CalcRequest>();

                var result = await _calcService.Add(calreq.A, calreq.B);

                return(new OkObjectResult(result));
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult(ex.Message));
            }
        }
        public int Add(int a, int b)
        {
            using (ChannelFactory <ICalcService> factory = new ChannelFactory <ICalcService>("ep001"))
            {
                try
                {
                    ICalcService client = factory.CreateChannel();

                    return(client.Add(a, b));
                }
                catch (FaultException <FaultData> fault)
                {
                    throw new Exception(fault.Message);
                }
            }
        }
Пример #8
0
        static void Main(string[] args)
        {
            // Address
            string svcAddress = Host + ":" + Port + "/" + ServiceName;

            // Binding
            NetTcpBinding tcpb = new NetTcpBinding(SecurityMode.Message);
            ChannelFactory <ICalcService> chFactory = new ChannelFactory <ICalcService>(tcpb);


            // Endpoint
            EndpointAddress epAddress = new EndpointAddress(svcAddress);

            // Create Channel
            ICalcService calcService = chFactory.CreateChannel(epAddress);

            if (calcService == null)
            {
                throw new Exception("Failed to create channel for " + epAddress);
            }
            try
            {
                const int n1 = 4;
                const int n2 = 5;

                Console.WriteLine("Connected to service '" + svcAddress + "'.");
                var result = calcService.Add(n1, n2);


                Console.WriteLine("The result of " + n1 + "+" + n2 + " is '" + result + "'.");

                Console.WriteLine("Press key to quit.");
                Console.ReadKey( );
            }
            finally
            {
                chFactory.Close( );
            }
        }
Пример #9
0
        public TestModule(IHelloService helloService, ICalcService calcService)
        {
            _helloService = helloService;
            _calcService  = calcService;

            Get("/empty", x =>
            {
                return(string.Empty);
            });
            Get("/time", x =>
            {
                return(DateTime.Now.ToString(@"yyyy-MM-dd HH:mm:ss.fffffff"));
            });
            Get("/hello", x =>
            {
                var response = _helloService.Hello(new HelloRequest()
                {
                    Text = DateTime.Now.ToString(@"yyyy-MM-dd HH:mm:ss.fffffff")
                });
                return(response == null ? string.Empty : response.Text);
            });
            Get("/hello10000", x =>
            {
                var response = _helloService.Hello10000(new Hello10000Request()
                {
                    Text = DateTime.Now.ToString(@"yyyy-MM-dd HH:mm:ss.fffffff")
                });
                return(response == null ? string.Empty : response.Text);
            });
            Get("/add", x =>
            {
                var response = _calcService.Add(new AddRequest()
                {
                    X = 1, Y = 2
                });
                return(string.Format("Result = {0}, Time = {1}", response.Result.ToString(), DateTime.Now.ToString(@"yyyy-MM-dd HH:mm:ss.fffffff")));
            });
        }
 public int Sum(int x, int y)
 {
     return(service.Add(x, y));
 }
Пример #11
0
 public int Sum(int x, int y)
 {
     logger.LogInformation($"Executing sum of {x} and {y}");
     return(service.Add(x, y));
 }
Пример #12
0
 public float Add([FromQuery] float[] summands)
 {
     _logger.LogInformation("Recieved add request");
     return(calcService.Add(summands));
 }