Exemplo n.º 1
0
 public ValueRange OnCalRange(CalculateRange command)
 {
     Console.WriteLine(command.ToIndentedJson());
     return(new ValueRange
     {
         MinValue = command.Values.Min(),
         MaxValue = command.Values.Max()
     });
 }
Exemplo n.º 2
0
        /// <summary>
        /// Command handler for CalculateRange
        /// </summary>
        /// <param name="range">Range.</param>
        private void CalculateRangeHandler(CalculateRange range)
        {
            Console.WriteLine("  {0}: Calculating Range from {1} to {2} Thread {3}",
                Self.Path.Name, range.From, range.To, Thread.CurrentThread.ManagedThreadId
            );

            // calculate
            double sum = 0;
            for (int k = range.From; k <= range.To; k++)
                sum += Math.Pow(-1, k) / (2 * k + 1);

            // send back result
            Sender.Tell(sum * 4);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Command handler for CalculateRange
        /// </summary>
        /// <param name="range">Range.</param>
        private void CalculateRangeHandler(CalculateRange range)
        {
            Console.WriteLine("  {0}: Calculating {1} Thread {2}",
                Self.Path.Name, range, Thread.CurrentThread.ManagedThreadId
            );

            // calculate
            double sum = 0;
            for (int n = range.StartAt; n <= range.EndAt; n++)
                sum += Math.Pow(-1, n) / (2 * n + 1);

            // send back result. If we multiply by 4 here, the sender will
            // automatically contain pi.
            Sender.Tell(sum * 4);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> GetRanges([FromBody] RangeModel model)
        {
            var firstRange  = new CalculateRange(model.Template, model.SetOne);
            var secondRange = new CalculateRange(model.Template, model.SetTwo);

            var rangeOneResult = _messaging.SendAsync(firstRange);
            var rangeTwoResult = _messaging.SendAsync(secondRange);

            await Task.WhenAll(rangeOneResult, rangeTwoResult);

            return(Ok(new []
            {
                rangeOneResult.Result.Message,
                rangeTwoResult.Result.Message
            }));
        }
Exemplo n.º 5
0
        public async Task <Range> DetermineRange(CalculateRange command)
        {
            if (command.Values.Length == 0)
            {
                throw new InvalidOperationException("The range can't be calculated.");
            }

            var range = new Range(command.Values.Min(), command.Values.Max());

            range.Message = command.MessageTemplate
                            .Replace("{min}", range.Min.ToString())
                            .Replace("{max}", range.Max.ToString());

            await Task.Delay(TimeSpan.FromSeconds(5));

            return(range);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Behandlung des Kommandos
        /// </summary>
        /// <param name="range">Range.</param>
        private void CalculateRangeHandler(CalculateRange range)
        {
            Console.WriteLine("  {0}: Calculating Range from {1} to {2} Thread {3}",
                              Self.Path.Name, range.From, range.To, Thread.CurrentThread.ManagedThreadId
                              );

            // rechnen
            double sum    = 0;
            var    factor = Math.Pow(-1, range.From - 1);
            int    denom  = 2 * range.From - 1;

            for (int k = range.From; k <= range.To; k++)
            {
                sum += (factor *= -1) / (denom += 2);
            }

            // und zurückschicken
            Sender.Tell(sum * 4);
        }
        public async Task <IActionResult> RpcCommandResponse(CalculateRange command)
        {
            var response = await _messaging.SendAsync(command);

            return(Ok(response));
        }