Example #1
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello SpeedTestLogger!");
            var config = new LoggerConfiguration();
            var runner = new SpeedTestRunner(config.LoggerLocation);

            runner.RunSpeedTest();

            var testData = runner.RunSpeedTest();
            var results  = new TestResult
            {
                SessionId = new Guid(),
                User      = config.UserId,
                Device    = config.LoggerId,
                Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
                Data      = testData
            };

            var success = false;

            using (var client = new SpeedTestApiClient(config.ApiUrl))
            {
                success = await client.PublishTestResult(results);
            }

            if (success)
            {
                Console.WriteLine("Speedtest complete!");
            }
            else
            {
                Console.WriteLine("Speedtest failed!");
            }
        }
        static void Main(string[] args)
        {
            //     Console.WriteLine("Hello World!");
            System.Console.WriteLine("Hello SpeedTestLogger");
            //     var client = new SpeedTestClient();
            //     var settings = client.GetSettings();

            //     System.Console.WriteLine("finding test server");
            var config = new LoggerConfiguration();

            // var location = new RegionInfo("nb-NO");
            var runner = new SpeedTestRunner(config.LoggerLocation);

            runner.RunSpeedTest();

            var testData = runner.RunSpeedTest();
            var results  = new TestResult
            {
                SessionId = new Guid(),
                User      = config.UserId,
                Device    = config.LoggerId,
                Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
                Data      = testData
            };

            //     var tenLocalServers = settings.Servers
            //         .Where (s=> s.Country.Equals(location.EnglishName
            //     )).Take(10);

            //     var serversOrdersByLatency = tenLocalServers
            //         .Select ( s =>
            //         {
            //             s.Latency = client.TestServerLatency(s);
            //              return s;
            //         })
            //         .OrderBy(s => s.Latency);


            // var server = serversOrdersByLatency.First();

            // Console.WriteLine("Testing download speed");
            // var downloadSpeed = client.TestDownloadSpeed(server, settings.Download.ThreadsPerUrl);
            // Console.WriteLine("Download speed was: {0} Mbps", Math.Round(downloadSpeed / 1024, 2));

            // Console.WriteLine("Testing upload speed");
            // var uploadSpeed = client.TestUploadSpeed(server, settings.Upload.ThreadsPerUrl);
            // Console.WriteLine("Upload speed was: {0} Mbps", Math.Round(uploadSpeed / 1024, 2))// ;
        }
Example #3
0
        static async Task <SubscriberClient.Reply> HandleMessage(PubsubMessage message, CancellationToken token)
        {
            var messageBody = Encoding.UTF8.GetString(message.Data.ToByteArray());

            if (messageBody != "RUN_SPEEDTEST")
            {
                return(SubscriberClient.Reply.Nack);
            }

            Console.WriteLine("Running speedtest!");

            var runner   = new SpeedTestRunner(_loggerConfig.LoggerLocation);
            var testData = runner.RunSpeedTest();
            var results  = new TestResult
            {
                User      = _loggerConfig.UserId,
                Device    = _loggerConfig.LoggerId,
                Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
                Data      = testData
            };

            var success = false;

            using (var client = new SpeedTestApiClient(_loggerConfig.ApiUrl))
            {
                success = await client.PublishTestResult(results);
            }

            Console.WriteLine($"SpeedTest {(success == true ? "complete" : "failed")}!");
            return(success == true ? SubscriberClient.Reply.Ack : SubscriberClient.Reply.Nack);
        }
Example #4
0
        private async Task RunSpeedTestAndUploadResults()
        {
            var testData = _runner.RunSpeedTest();

            Console.WriteLine("Got download: {0} Mbps and upload: {1} Mbps", testData.Speeds.Download, testData.Speeds.Upload);

            var results = new TestResult
            {
                SessionId = Guid.NewGuid(),
                User      = _config.UserId,
                Device    = _config.LoggerId,
                TestDate  = DateTime.Now,
                Data      = testData
            };

            if (!_config.UploadResults)
            {
                Console.WriteLine("Skipping data upload to speedtest API");
                return;
            }

            Console.WriteLine("Uploading data to speedtest API");
            var success = await _apiClient.PublishTestResult(results);

            if (success)
            {
                Console.WriteLine("Speedtest complete!");
            }
            else
            {
                Console.WriteLine("Speedtest failed!");
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello SpeedTestLogger!");

            var config = new LoggerConfiguration();
            var runner = new SpeedTestRunner(config.LoggerLocation);

            runner.RunSpeedTest();
            var testData = runner.RunSpeedTest();
            var results  = new TestResult
            {
                SessionId = new Guid(),
                User      = config.UserId,
                Device    = config.LoggerId,
                Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
                Data      = testData
            };
        }
Example #6
0
        static async Task HandleSpeedTestMessage(Message message, CancellationToken token)
        {
            var messageBody = Encoding.UTF8.GetString(message.Body);

            if (messageBody != "RUN_SPEEDTEST")
            {
                return;
            }

            Console.WriteLine($"Starting speedtest: { message.SessionId }");
            Console.WriteLine($"Timestamp: { System.DateTime.Now}");

            var runner   = new SpeedTestRunner(_config.LoggerLocation);
            var testData = runner.RunSpeedTest();

            Console.WriteLine("Got download: {0} Mbps and upload: {1} Mbps", testData.Speeds.Download, testData.Speeds.Upload);
            var results = new TestResult
            {
                SessionId = new Guid(),
                User      = _config.UserId,
                Device    = _config.LoggerId,
                Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
                Data      = testData
            };

            var success = false;

            using (var client = new SpeedTestApiClient(_config.ApiUrl))
            {
                success = await client.PublishTestResult(results);
            }

            if (success)
            {
                Console.WriteLine("Speedtest complete!");
            }
            else
            {
                Console.WriteLine("Speedtest failed!");
            }
        }
Example #7
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello SpeedTestLogger!");

            var config = new LoggerConfiguration();
            var runner = new SpeedTestRunner(config.LoggerLocation);

            runner.RunSpeedTest();


            var testData = runner.RunSpeedTest();
            var results  = new TestResult
            {
                SessionId = new Guid(),
                User      = config.UserId,
                Device    = config.LoggerId,
                Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
                Data      = testData
            };


            var success = false;

            using (var client = new SpeedTestApiClient(config.ApiUrl))
            {
                success = await client.PublishTestResult(results);
            }

            if (success)
            {
                Console.WriteLine("Speedtest complete!");
            }
            else
            {
                Console.WriteLine("Speedtest failed!");
            }


            //var results = new TestResult
            //{
            //    SessionId = new Guid(),
            //    User = "******",
            //    Device = 1,
            //    Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
            //    Data = testData
            //};


            //v2
            //Console.WriteLine("Hello SpeedTestLogger!");

            //var location = new RegionInfo("nb-NO");
            //var runner = new SpeedTestRunner(location);
            //runner.RunSpeedTest();


            //v1
            //var client = new SpeedTestClient();
            //var settings = client.GetSettings();

            //Console.WriteLine("Finding best test servers");

            //var location = new RegionInfo("nb-NO");
            //var tenLocalServers = settings.Servers
            //    .Where(s => s.Country.Equals(location.EnglishName))
            //    .Take(10);

            //var serversOrdersByLatency = tenLocalServers
            //    .Select(s =>
            //    {
            //        s.Latency = client.TestServerLatency(s);
            //        return s;
            //    })
            //    .OrderBy(s => s.Latency);

            //var server = serversOrdersByLatency.First();


            //Console.WriteLine("Testing download speed");
            //var downloadSpeed = client.TestDownloadSpeed(server, settings.Download.ThreadsPerUrl);
            //Console.WriteLine("Download speed was: {0} Mbps", Math.Round(downloadSpeed / 1024, 2));

            //Console.WriteLine("Testing upload speed");
            //var uploadSpeed = client.TestUploadSpeed(server, settings.Upload.ThreadsPerUrl);
            //Console.WriteLine("Upload speed was: {0} Mbps", Math.Round(uploadSpeed / 1024, 2));



            //Console.ReadKey();
        }