Example #1
0
 public IHttpActionResult SimulateCalls([FromBody] SimulatorCalls calls)
 {
     try
     {
         simulator.SimulateCalls(calls);
         return(Ok());
     }
     catch (Exception e)
     {
         return(BadRequest());
     }
 }
Example #2
0
        public async Task SimulateCalls(SimulatorCalls calls)
        {
            using (var client = new HttpClient {
                BaseAddress = uri
            })
            {
                var response = await client.PostAsJsonAsync($"api/simulator/SimulateCalls", calls);

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception("Could not post the calls. ");
                }
            }
        }
Example #3
0
        public void SimulateCalls(SimulatorCalls calls)
        {
            string[] destinations = repository.GetRandomNumbersFor(calls.CallerNumber, calls.DestinationOption, calls.Simulations);

            Random rand = new Random();

            var rangeLength = (calls.MaxDuration - calls.MinDuration).TotalMinutes;
            var minDur      = calls.MinDuration.TotalMinutes;

            var time = DateTime.Now;

            for (int i = 0; i < calls.Simulations; i++)
            {
                repository.AddCall(new Call
                {
                    CallerNumber      = calls.CallerNumber,
                    DestinationNumber = destinations[i],
                    Duration          = TimeSpan.FromMinutes((rand.Next() / (double)int.MaxValue) * rangeLength + minDur),
                    StartTime         = time
                });

                time = time.AddMinutes(5);
            }
        }