public async Task ZonesCheck(Token token, UTMService utmService) { if (isConnected == false) { _utmService = utmService; var action = new Action <object, string, object>(OnMessage); await _UTMLiveService.Connect(token?.access_token, action); isConnected = true; } }
public DroneSim(IOptions <DroneOpts> droneOpts, IOptions <UTMOpts> utmOpts) { _drone = new Drone { Id = droneOpts.Value.id, OperationId = droneOpts.Value.operationid, Velocity = droneOpts.Value.velocity, Location = droneOpts.Value.location, HomeLocation = droneOpts.Value.homelocation }; this._utmService = new UTMService( utmOpts.Value.clientid, utmOpts.Value.clientsecret, utmOpts.Value.username, utmOpts.Value.password ); }
public async Task WeatherCheck(UTMService utmService) { List <Flight> flights = await utmService.Operation.GetFlightsInAllOperationsAsync(); var distinctFlights = flights?.GroupBy(flight => flight.uas.uniqueIdentifier).Select(uas => uas.First()).ToList(); distinctFlights?.ForEach(async flight => { var flightCoordinates = flight.coordinate; var weatherResponse = await _weatherService.GetWeatherAtCoord(latitude: flightCoordinates.latitude.ToString(), longitude: flightCoordinates.longitude.ToString()); var process = new Process(); var key = $"{flight.uasOperation}-{flight.uas.uniqueIdentifier}-weather"; var cachedProcess = await _redisService.Get <State>(key); if (cachedProcess != null) { process.CurrentState = cachedProcess.CurrentState; } else { cachedProcess = new State(); } var validatedRule = _weatherRule.ValidateRule(weatherResponse); if (!validatedRule.Success && (process.CurrentState == ProcessState.Active || process.CurrentState == ProcessState.Inactive)) { process.MoveNext(); } else { process.MovePrev(); } if (process.CurrentState == ProcessState.Raised && !cachedProcess.Triggered && !cachedProcess.Handled) { cachedProcess.Triggered = true; await SendAlert(new Alert { droneId = flight.uas.uniqueIdentifier, type = "weather-alert", reason = validatedRule.Message }); } cachedProcess.CurrentState = process.CurrentState; await _redisService.Set(key, cachedProcess); }); }
static async Task Main(string[] args) { var services = new ServiceCollection(); ConfigureServices(services); var serviceProvider = services.BuildServiceProvider(); var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", false) .Build(); var utmService = new UTMService(config["UTM:clientid"], config["UTM:clientsecret"], config["UTM:username"], config["UTM:password"]); var token = await utmService.Tokens.Auth(); Scheduler.IntervalInMinutes(1, async() => { Console.WriteLine($"Running weather check at: {DateTime.Now}"); await serviceProvider.GetService <IWeatherRunner>().WeatherCheck(utmService); }); Scheduler.IntervalInMinutes(0.5, async() => { Console.WriteLine($"Running collision and no-flyzone check at: {DateTime.Now}"); await serviceProvider.GetService <ICollisionAndNoFlyZoneRunner>().ZonesCheck(token, utmService); }); // Handle Control+C or Control+Break Console.CancelKeyPress += (o, e) => { Console.WriteLine("Exit"); // Allow the manin thread to continue and exit... waitHandle.Set(); }; // Wait waitHandle.WaitOne(); }