Пример #1
0
        private async AsyncTask LoadProjects()
        {
            try
            {
                var syncConfig = new SyncConfiguration(
                    $"user={ App.realmApp.CurrentUser.Id }",
                    App.realmApp.CurrentUser);
                // :code-block-start:user-realm-config
                // :state-start: final
                userRealm = await Realm.GetInstanceAsync(syncConfig);

                // :state-end: :state-uncomment-start: start
                //// TODO: instatiate the userRealm by calling GetInstanceAsync
                //// userRealm = await ...
                // :state-uncomment-end:
                // :code-block-end:
                // :code-block-start:find-user
                // :state-start: final
                user = userRealm.All <User>().ToList().Where(u => u.Id ==
                                                             App.realmApp.CurrentUser.Id).FirstOrDefault();
                // :state-end: :state-uncomment-start: start
                //// TODO: find the user in the userRealm
                //// start with userRealm.All<User>(). and use ToList() and Where()
                // :state-uncomment-end:
                // :code-block-end:
                if (user != null)
                {
                    SetUpProjectList();
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error Loading Projects", ex.Message, "OK");
            }
        }
Пример #2
0
        private async AsyncTask LoadProjects()
        {
            try
            {
                var syncConfig = new SyncConfiguration(
                    $"user={ App.RealmApp.CurrentUser.Id }",
                    App.RealmApp.CurrentUser);
                // :code-block-start:user-realm-config
                // :state-start: final
                userRealm = await Realm.GetInstanceAsync(syncConfig);

                // :state-end: :state-uncomment-start: start
                //// TODO: instatiate the userRealm by calling GetInstanceAsync
                //// userRealm = await ...
                // :state-uncomment-end:
                // :code-block-end:
                // :code-block-start:find-user
                // :state-start: final
                user = userRealm.Find <User>(App.RealmApp.CurrentUser.Id);
                // :state-end: :state-uncomment-start: start
                //// TODO: find the user in the userRealm
                //// Because the user's ID is the Primary Key, we can easily
                //// find the user by passing the ID to userRealm.Find<User>().
                // :state-uncomment-end:
                // :code-block-end:
                if (user != null)
                {
                    SetUpProjectList();
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error Loading Projects", ex.Message, "OK");
            }
        }
Пример #3
0
        private async AsyncTask LoadProjects()
        {
            try
            {
                var syncConfig = new SyncConfiguration(
                    $"user={ App.RealmApp.CurrentUser.Id }",
                    App.RealmApp.CurrentUser);
                // :code-block-start:user-realm-config
                // :state-start: final
                userRealm = await Realm.GetInstanceAsync(syncConfig);

                // :state-end: :state-uncomment-start: start
                //// TODO: instatiate the userRealm by calling GetInstanceAsync
                //// userRealm = await ...
                // :state-uncomment-end:
                // :code-block-end:
                // :code-block-start:find-user
                // :state-start: final
                user = userRealm.Find <User>(App.RealmApp.CurrentUser.Id);
                // :state-end: :state-uncomment-start: start
                //// TODO: find the user in the userRealm
                //// Because the user's ID is the Primary Key, we can easily
                //// find the user by passing the ID to userRealm.Find<User>().
                //// user = ...
                // :state-uncomment-end:
                // :code-block-end:

                if (user == null && !Constants.AlreadyWarnedAboutBackendSetup)
                {
                    // Either the trigger hasn't completed yet, has failed,
                    // or was never created on the backend
                    // So let's wait a few seconds and check again...
                    await System.Threading.Tasks.Task.Delay(5000);

                    user = userRealm.Find <User>(App.RealmApp.CurrentUser.Id);
                    if (user == null)
                    {
                        Console.WriteLine("NO USER OBJECT: This error occurs if " +
                                          "you do not have the trigger configured on the backend " +
                                          "or when there is a network connectivity issue. See " +
                                          "https://www.mongodb.com/docs/realm/tutorial/realm-app/#triggers");

                        await DisplayAlert("No User object",
                                           "The User object for this user was not found on the server. " +
                                           "If this is a new user acocunt, the backend trigger may not have completed, " +
                                           "or the tirgger doesn't exist. Check your backend set up and logs.", "OK");

                        Constants.AlreadyWarnedAboutBackendSetup = true;
                    }
                }
                SetUpProjectList();
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error Loading Projects", ex.Message, "OK");
            }
        }