Exemplo n.º 1
0
        public async Task TestWaitForChangesToDownloadAsync()
        {
            var appConfig = new AppConfiguration(myRealmAppId)
            {
                DefaultRequestTimeout = TimeSpan.FromMilliseconds(1500)
            };

            app    = App.Create(appConfig);
            user   = app.LogInAsync(Credentials.Anonymous()).Result;
            config = new PartitionSyncConfiguration("myPartition", user);
            try
            {
                // :code-block-start: wait-for-changes-to-download-async-progress-notification
                // :uncomment-start:
                // using Realms.Sync;

                // :uncomment-end:
                var realm = Realm.GetInstance(config);
                await realm.SyncSession.WaitForDownloadAsync();

                // :code-block-end:
                realm.Dispose();
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 2
0
        public async System.Threading.Tasks.Task Setup()
        {
            // :code-block-start: initialize-realm
            app = App.Create(myRealmAppId);
            // :code-block-end:
            user = app.LogInAsync(Credentials.EmailPassword("*****@*****.**", "foobar")).Result;
            // :code-block-start: open-synced-realm
            config = new SyncConfiguration("myPartition", user);
            var realm = await Realm.GetInstanceAsync(config);

            // :code-block-end:
            // :code-block-start: open-synced-realm-sync
            var synchronousRealm = Realm.GetInstance(config);
            // :code-block-end:
            // :code-block-start: create
            var testTask = new Task
            {
                Name   = "Do this thing",
                Status = TaskStatus.Open.ToString()
            };

            realm.Write(() =>
            {
                realm.Add(testTask);
            });
            // :code-block-end:
            testTaskId = testTask._id;
            return;
        }
Exemplo n.º 3
0
        public async System.Threading.Tasks.Task Setup()
        {
            app    = App.Create(myRealmAppId);
            user   = app.LogInAsync(Credentials.EmailPassword("*****@*****.**", "foobar")).Result;
            config = new SyncConfiguration("myPart", user);
            var realm = await Realm.GetInstanceAsync(config);

            var synchronousRealm = Realm.GetInstance(config);
            var testTask         = new Task
            {
                Name   = "Do this thing",
                Status = TaskStatus.Open.ToString()
            };

            realm.Write(() =>
            {
                realm.Add(testTask);
            });
            testTaskId = testTask.Id;

            /* var schemas = config.ObjectClasses;
             * foreach (var schema in schemas)
             * {
             *   Console.WriteLine(schema.FullName);
             * }*/


            return;
        }
Exemplo n.º 4
0
        public async System.Threading.Tasks.Task Setup()
        {
            var appConfig = new AppConfiguration(myRealmAppId)
            {
                LogLevel = LogLevel.Debug,
                DefaultRequestTimeout = TimeSpan.FromMilliseconds(1500)
            };

            app = App.Create(appConfig);
            user = await app.LogInAsync(Credentials.EmailPassword("*****@*****.**", "foobar"));
            return;
        }
Exemplo n.º 5
0
        public async Task handleErrors()
        {
            // :code-block-start: set-log-level
            var appConfig = new AppConfiguration(myRealmAppId)
            {
                LogLevel = LogLevel.Debug,
                // :hide-start:
                DefaultRequestTimeout = TimeSpan.FromMilliseconds(1500)
                                        // :hide-end:
            };

            // :code-block-end:
            app  = App.Create(appConfig);
            user = await app.LogInAsync(Credentials.Anonymous());

            config = new SyncConfiguration("myPartition", user);
            var realm = await Realm.GetInstanceAsync(config);

            // :code-block-start: handle-errors
            Session.Error += (session, errorArgs) =>
            {
                var sessionException = (SessionException)errorArgs.Exception;
                switch (sessionException.ErrorCode)
                {
                case ErrorCode.AccessTokenExpired:
                case ErrorCode.BadUserAuthentication:
                    // Ask user for credentials
                    break;

                case ErrorCode.PermissionDenied:
                    // Tell the user they don't have permissions to work with that Realm
                    // :hide-start:
                    didTriggerErrorHandler = true;
                    // :hide-end:
                    break;

                case ErrorCode.Unknown:
                    // Likely the app version is too old, prompt for update
                    break;
                    // ...
                }
            };
            // :code-block-end:
            TestingExtensions.SimulateError(realm.GetSession(),
                                            ErrorCode.PermissionDenied, "No permission to work with the Realm", false);

            // Close the Realm before doing the reset as it'll need
            // to be deleted and all objects obtained from it will be
            // invalidated.
            realm.Dispose();

            Assert.IsTrue(didTriggerErrorHandler);
        }
Exemplo n.º 6
0
        public async Task ResetsTheClient()
        {
            app = App.Create(myRealmAppId);

            user = app.LogInAsync(Credentials.EmailPassword("*****@*****.**", "foobar")).Result;

            config = new PartitionSyncConfiguration("myPart", user);
            //:hide-start:
            config.Schema = new[] { typeof(User) };
            //:hide-end:
            var realm = await Realm.GetInstanceAsync(config);

            // :code-block-start: handle
            Session.Error += (sender, err) =>
            {
                if (err.Exception is ClientResetException clientResetEx)
                {
                    var session = (Session)sender;
                    Console.WriteLine("Client Reset requested for " +
                                      session.Path + "due to " + clientResetEx.Message);

                    // Prompt user to perform client reset immediately. If they don't do it,
                    // they won't receive any data from the server until they restart the app
                    // and all changes they make will be discarded when the app restarts.
                    var didUserConfirmReset = true;
                    if (didUserConfirmReset)
                    {
                        // Close the Realm before doing the reset as it'll need
                        // to be deleted and all objects obtained from it will be
                        // invalidated.
                        realm.Dispose();
                        var didReset = clientResetEx.InitiateClientReset();
                        if (didReset)
                        {
                            // Navigate the user back to the main page or reopen the
                            // the Realm and reinitialize the current page.
                        }
                        else
                        {
                            // Reset failed - notify user that they'll need to restart the app.
                        }
                        // :hide-start:
                        Assert.IsTrue(didReset);
                        // :hide-end:
                    }
                }
            };
            // :code-block-end:
            TestingExtensions.SimulateError(realm.SyncSession,
                                            ErrorCode.DivergingHistories, "diverging histories!", false);
        }
Exemplo n.º 7
0
        public async System.Threading.Tasks.Task LotsaStuff()
        {
            string userEmail = "*****@*****.**";

            // :code-block-start: initialize-realm
            // :hide-start:

            /*:replace-with:
             * var myRealmAppId = "<your_app_id>";
             * var app = App.Create(myRealmAppId);
             * :code-block-end:*/
            // :code-block-start: appConfig
            var appConfig = new AppConfiguration(myRealmAppId)
            {
                LogLevel = LogLevel.Debug,
                DefaultRequestTimeout = TimeSpan.FromMilliseconds(1500)
            };

            app = App.Create(appConfig);
            //:code-block-end:
            // :code-block-start: register-user
            await app.EmailPasswordAuth.RegisterUserAsync(userEmail, "sekrit");

            //:code-block-end:
            // :code-block-start: confirm-user
            await app.EmailPasswordAuth.ConfirmUserAsync("<token>", "<token-id>");

            //:code-block-end:
            // :code-block-start: reset-user-1
            await app.EmailPasswordAuth.SendResetPasswordEmailAsync(userEmail);

            //:code-block-end:
            string myNewPassword = "";
            // :code-block-start: reset-user-2
            await app.EmailPasswordAuth.ResetPasswordAsync(
                myNewPassword, "<token>", "<token-id>");

            //:code-block-end:
            // :code-block-start: reset-user-3
            await app.EmailPasswordAuth.CallResetPasswordFunctionAsync(
                userEmail, myNewPassword,
                "<security-question-1-answer>",
                "<security-question-2-answer>");

            //:code-block-end:

            user = await app.LogInAsync(Credentials.EmailPassword("*****@*****.**", "foobar"));
        }
Exemplo n.º 8
0
        public async Task TestUploadDownloadProgressNotification()
        {
            var progressNotificationTriggered = false;
            var appConfig = new AppConfiguration(myRealmAppId)
            {
                DefaultRequestTimeout = TimeSpan.FromMilliseconds(1500)
            };

            app    = App.Create(appConfig);
            user   = app.LogInAsync(Credentials.Anonymous()).Result;
            config = new SyncConfiguration("myPartition", user);
            var realm = await Realm.GetInstanceAsync(config);

            // :code-block-start: upload-download-progress-notification
            var session = realm.GetSession();
            var token   = session.GetProgressObservable(ProgressDirection.Upload,
                                                        ProgressMode.ReportIndefinitely)
                          .Subscribe(progress =>
            {
                // :hide-start:
                progressNotificationTriggered = true;
                // :hide-end:
                Console.WriteLine($"transferred bytes: {progress.TransferredBytes}");
                Console.WriteLine($"transferable bytes: {progress.TransferableBytes}");
            });
            // :code-block-end: upload-download-progress-notification
            var id    = 2;
            var myObj = new ProgressObj
            {
                Id = id
            };

            realm.Write(() =>
            {
                realm.Add(myObj);
            });
            realm.Write(() =>
            {
                realm.RemoveAll <ProgressObj>();
            });
            // :code-block-start: remove-progress-notification
            token.Dispose();
            // :code-block-end: remove-progress-notification

            Assert.IsTrue(progressNotificationTriggered);
        }
Exemplo n.º 9
0
        public async Task Setup()
        {
            app  = App.Create(myRealmAppId);
            user = await app.LogInAsync(Credentials.EmailPassword("*****@*****.**", "foobar"));

            config = new PartitionSyncConfiguration("myPart", user);

            // :code-block-start: mongo-setup
            mongoClient      = user.GetMongoClient("mongodb-atlas");
            dbPlantInventory = mongoClient.GetDatabase("inventory");
            plantsCollection = dbPlantInventory.GetCollection <Plant>("plants");
            // :code-block-end:

            await InsertsOne();
            await InsertsMany();

            return;
        }
Exemplo n.º 10
0
        public async System.Threading.Tasks.Task Setup()
        {
            app    = App.Create(myRealmAppId);
            user   = app.LogInAsync(Credentials.EmailPassword("*****@*****.**", "foobar")).Result;
            config = new SyncConfiguration("myPart", user);
            var realm = await Realm.GetInstanceAsync(config);

            var synchronousRealm = Realm.GetInstance(config);
            var testTask         = new Task
            {
                Name      = "Do this thing",
                Partition = "myPart",
                Status    = TaskStatus.Open.ToString()
            };

            realm.Write(() =>
            {
                realm.Add(testTask);
            });
            testTaskId = testTask.Id;

            return;
        }
Exemplo n.º 11
0
        public async Task Setup()
        {
            app    = App.Create(myRealmAppId);
            user   = app.LogInAsync(Credentials.EmailPassword("*****@*****.**", "foobar")).Result;
            config = new PartitionSyncConfiguration("myPart", user);
            //:hide-start:
            config.Schema = new[] { typeof(Plant) };
            //:hide-end:
            SetupPlantCollection();

            await plantsCollection.DeleteManyAsync();

            venus = new Plant
            {
                Name      = "Venus Flytrap",
                Sunlight  = Sunlight.Full.ToString(),
                Color     = PlantColor.White.ToString(),
                Type      = PlantType.Perennial.ToString(),
                Partition = "Store 42"
            };
            sweetBasil = new Plant
            {
                Name      = "Sweet Basil",
                Sunlight  = Sunlight.Partial.ToString(),
                Color     = PlantColor.Green.ToString(),
                Type      = PlantType.Annual.ToString(),
                Partition = "Store 42"
            };
            thaiBasil = new Plant
            {
                Name      = "Thai Basil",
                Sunlight  = Sunlight.Partial.ToString(),
                Color     = PlantColor.Green.ToString(),
                Type      = PlantType.Perennial.ToString(),
                Partition = "Store 42"
            };
            helianthus = new Plant
            {
                Name      = "Helianthus",
                Sunlight  = Sunlight.Full.ToString(),
                Color     = PlantColor.Yellow.ToString(),
                Type      = PlantType.Annual.ToString(),
                Partition = "Store 42"
            };
            petunia = new Plant
            {
                Name      = "Petunia",
                Sunlight  = Sunlight.Full.ToString(),
                Color     = PlantColor.Purple.ToString(),
                Type      = PlantType.Annual.ToString(),
                Partition = "Store 47"
            };

            var listofPlants = new List <Plant>
            {
                venus,
                sweetBasil,
                thaiBasil,
                helianthus,
                petunia
            };

            var insertResult = await plantsCollection.InsertManyAsync(listofPlants);



            return;
        }