Beispiel #1
0
        public async Task InitListView()
        {
            Realm RealmContext = null;

            try
            {
                if (User.AllLoggedIn.Count() > 1)
                {
                    foreach (var _u in User.AllLoggedIn)
                    {
                        await _u.LogOutAsync();
                    }
                }
                if (User.Current == null)
                {
                    if (await MyRealm.Login(API_USERNAME, API_PASSWORD) == null)
                    {
                        return;
                    }
                }
                RealmContext = MyRealm.RealmContext;
                using (var transaction = RealmContext.BeginWrite())
                {
                    RealmContext.RemoveAll <TrackMessage>();
                    RealmContext.Add(new TrackMessage {
                        Id = 0, Text = "Please wait, service starting"
                    });
                    transaction.Commit();
                }
                listView.ItemsSource = TrackMessage = RealmContext.All <TrackMessage>();
            }
            catch (Exception e) { Console.WriteLine($"{Constants.TAG} Erreur {e.GetType().FullName} {e.Message}"); }
        }
Beispiel #2
0
 private async void Clicked(object sender, EventArgs e)
 {
     if (sender == StartButton || sender == StopButton)
     {
         MessagingCenter.Send(new ToTrackerMessage(sender == StartButton), nameof(ToTrackerMessage));
     }
     else if (sender == CreateButton)
     {
         if (await MyRealm.Login(API_USERNAME, API_PASSWORD, true) != null)
         {
             await InitListView();
         }
     }
 }
Beispiel #3
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();
            var realm = await MyRealm.OpenRealm();

            if (realm != null)
            {
                listView.ItemsSource = realm.All <CounterMessage>();
            }
            StartButton.Clicked += Clicked;
            StopButton.Clicked  += Clicked;
            MessagingCenter.Subscribe <ServiceMessage>(this, nameof(ServiceMessage), (message) => {
                if (message.MessageType == Constants.TypeMessage.ServiceStarted && realm != null)
                {
                    realm.Write(() => realm.Add(new CounterMessage {
                        Text = "Service ready"
                    }));
                }
            });
        }