static async Task Main(string[] args) { var config = new LoggerConfiguration(); var runner = new SpeedTestRunner(config.LoggerLocation); 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 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); }
public LoggerHost(KubeMQClient queue, SpeedTestRunner runner, SpeedTestApiClient apiClient, LoggerHostConfiguration config, IHostApplicationLifetime lifetime) { _queue = queue; _runner = runner; _apiClient = apiClient; _config = config; _lifetime = lifetime; }
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!"); } }
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(); }