/// <summary>
 /// React to changes in internet connectivity
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void Connectivity_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
 {
     IsNotConnected = e.NetworkAccess != NetworkAccess.Internet;
     LogoutCommand.RaiseCanExecuteChanged();
     SyncCommand.RaiseCanExecuteChanged();
     DeleteProjectCommand.RaiseCanExecuteChanged();
 }
 /// <summary>
 /// Set the current project on appearing
 /// </summary>
 public void OnAppearing()
 {
     Task.Run(() =>
     {
         string projId = Preferences.Get("currentProject", @"");
         SyncCommand.RaiseCanExecuteChanged();
         App.CurrentProjectId = projId;
         try
         {
             this.SetProject(projId);
         }
         catch (Exception exp)
         {
             Console.WriteLine("Couldn't set project " + exp);
         }
     });
 }
        /// <summary>
        /// Initialise the project page
        /// </summary>
        public ProjectsPageVM()
        {
            Title = "Projekt";
            //Create commands
            SyncCommand          = new SyncCommand(this);
            DeleteProjectCommand = new DeleteProjectCommand(this);
            CopyBDCGUIDCommand   = new BDCGUIDCommand(this);
            LogoutCommand        = new LogoutCommand(this);
            CurrentAppVersion    = VersionTracking.CurrentVersion.ToString() + "(" + VersionTracking.CurrentBuild.ToString() + ")";

            MessagingCenter.Subscribe <Application>(App.Current, "RefreshRecords", (sender) =>
            {
                ChangesMessageVisible = Project.ProjectHasUnsavedChanges(App.CurrentProjectId);
            });

            MessagingCenter.Subscribe <Application>(App.Current, "RefreshGeometries", (sender) =>
            {
                ChangesMessageVisible = Project.ProjectHasUnsavedChanges(App.CurrentProjectId);
            });

            //Get user or log new one in
            if (App.CurrentUser != null)
            {
                CheckProjectAvailability();
                Connectivity.ConnectivityChanged += Connectivity_ConnectivityChanged;
            }
            else
            {
                App.Current.MainPage.Navigation.PushAsync(new MainPage(), true);
            }

            //Subscribe to messages
            MessagingCenter.Subscribe <Application>(App.Current, "SetProject", (sender) =>
            {
                var newId = Preferences.Get("currentProject", "");
                this.SetProject(newId);
            });

            Activity = "";
            MessagingCenter.Subscribe <Application, string>(App.Current, "SyncMessage", (sender, arg) =>
            {
                Activity = arg;
            });
        }