Beispiel #1
0
        private async void OnRunRandomOrgCollatzOnServerClick(object sender, RoutedEventArgs e)
        {
            using (Cursors.Wait.Bind(() => this.Cursor))
            {
                this.Results.Text = string.Empty;
                var pauseTime = 0;
                int.TryParse(this.PauseTime.Text, out pauseTime);

                var value = await WebApiCalls.GetRandomNumberFromWeb();

                var response = await WebApiCalls.GetResponse(value, pauseTime);

                this.Results.Text = string.Format("Number: {0}, Iterations: {1}, Time: {2}",
                                                  response.Value, response.Iterations, response.Time);
            }
        }
Beispiel #2
0
        private async void OnRunManyRandomCollatzOnServerClick(object sender, RoutedEventArgs e)
        {
            using (Cursors.Wait.Bind(() => this.Cursor))
            {
                this.Results.Text = string.Empty;
                var iterations = 0;

                if (int.TryParse(this.Iterations.Text, out iterations))
                {
                    var pauseTime = 0;
                    int.TryParse(this.PauseTime.Text, out pauseTime);

                    var random = new SecureRandom();

                    using (var writer = new StringWriter())
                    {
                        var responses = new List <Task <CollatzGetResponseMessage> >();

                        for (var i = 0; i < iterations; i++)
                        {
                            var value = random.GetBigInteger((ulong)random.Next(50, 200));
                            responses.Add(WebApiCalls.GetResponse(value, pauseTime));
                        }

                        await Task.WhenAll(responses);

                        foreach (var response in responses)
                        {
                            var result = response.Result;
                            writer.WriteLine(string.Format("Number: {0}, Iterations: {1}, Time: {2}",
                                                           result.Value, result.Iterations, result.Time));
                        }

                        this.Results.Text = writer.ToString();
                    }
                }
            }
        }