public static async Task CheckNewNotifications(Action <Lers.Notification> handler) { if (string.IsNullOrEmpty(AppDataStorage.Token) || string.IsNullOrEmpty(AppDataStorage.Uri)) { return; } var appService = new MobileCore(); // Подключаемся к серверу. await appService.ConnectToken(AppDataStorage.Uri, AppDataStorage.Token); Lers.Notification[] newNotifications = null; try { // Получаем дату последнего уведомления. DateTime lastNotifyDate = AppDataStorage.LastNotifyDate; // Получаем список новых уведомлений. newNotifications = await GetNewNotifications(appService, lastNotifyDate); } catch { // Подключение к серверу больше не требуется. appService.Disconnect(); } if (newNotifications != null && newNotifications.Length > 0) { #if (DEBUG) { handler(newNotifications.Last()); } #endif long lastNotifyId = AppDataStorage.LastNotifyId; if (lastNotifyId > 0) { // Уведомляем обо всех событиях, у которых Id больше чем последний. // Так же пропускаем те уведомления, которые уже прочитаны. foreach (var notification in newNotifications .Where(x => x.Id > lastNotifyId && !x.IsRead)) { handler(notification); } } AppDataStorage.LastNotifyDate = newNotifications.First().DateTime; AppDataStorage.LastNotifyId = newNotifications.First().Id; } }
public App() { InitializeComponent(); Core = new Core.MobileCore(); Core.LoginRequired += Core_LoginRequired; ShowLoginPage(); AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; }
public LoginPage() { this.coreService = App.Core; InitializeComponent(); this.BindingContext = this; Uri uri = new Uri(AppDataStorage.Uri); this.serverAddressInput.Text = uri.Host; this.sslSwitch.IsToggled = uri.Scheme == Lers.LersScheme.Secure; this.loginInput.Text = AppDataStorage.Login; }
/// <summary> /// Конструктор. /// </summary> /// <param name="core"></param> /// <param name="measurePoint"></param> public MeasurePointPoller(MobileCore core, MeasurePoint measurePoint) { this.core = core ?? throw new ArgumentNullException(nameof(core)); this.measurePoint = measurePoint ?? throw new ArgumentNullException(nameof(measurePoint)); }