public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { // create a new window instance based on the screen size Window = new UIWindow(UIScreen.MainScreen.Bounds); // set root view controller var rootController = new AlarmsController(); var navController = new UINavigationController(rootController); Window.RootViewController = navController; // make the window visible Window.MakeKeyAndVisible(); return(true); }
private async static Task <bool> ProcessAlarm(Guid thingId, byte[] message) { var _context = _serviceScopeFactory.CreateScope().ServiceProvider.GetRequiredService <ApplicationDbContext>(); var _alarm = new AlarmsController(_context, _hubContext); var thing = _context.Thing.AsNoTracking().Where(thing => thing.ThingId.Equals(thingId)).FirstOrDefault(); if (thing == null) { _logger.LogWarning($"Thing with Id {thingId} not found"); return(false); } else if (!thing.Features.HasFlag(FeatureType.Alarm)) { _logger.LogWarning($"Thing with Id {thingId} does not have the specified feature {FeatureType.Alarm}"); return(false); } try { string messageReceived = Encoding.Default.GetString(message); AlarmDTO alarm = new() { ThingId = thingId }; if (messageReceived.Contains("Open")) { alarm.Type = AlarmType.Open; } else if (messageReceived.Contains("Closed")) { alarm.Type = AlarmType.Close; } else if (messageReceived.Contains("id")) { alarm.Type = AlarmType.Read; } else { _logger.LogError($"Message from Thing with Id {thingId} not processed"); return(false); } await _telegramBotClient.SendTextMessageAsync(_telegramBotChatId, messageReceived); try { await _alarm.PostAlarm(alarm); } catch (DbUpdateException ex) { _logger.LogError(ex.Message); return(false); } } catch (Exception ex) { _logger.LogError(ex.Message); return(false); } return(true); }