Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the percent, then calls the stored progress object's "Report"
        /// </summary>
        /// <param name="pct">percent progress, 0 to 100</param>
        /// <param name="newStatus">Updated status string, null for no update</param>
        public void Report(double pct, string newStatus = null)
        {
            if (pct > 100)
            {
                pct = 100;
            }
            // drop large spikes that may have been triggered by multithreading
            if (_useForwardOnlyLogic && pct - _percent > 70 && !(pct.Equals(0.0) && _percent.Equals(100.0)))
            {
                pct = _percent;
            }

            Percent = pct;
            if (newStatus != null)
            {
                Status = newStatus;
            }
            ProgressObj.Report(this);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Updates the percent, then calls the stored progress object's "Report"
 /// </summary>
 /// <param name="pct">percent progress, 0 to 100</param>
 public void Report(double pct)
 {
     Percent = pct;
     ProgressObj.Report(this);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Updates the status, then calls the stored progress object's "Report"
 /// </summary>
 /// <param name="newStatus">Updated status string</param>
 public void Report(string newStatus)
 {
     Status = newStatus;
     ProgressObj.Report(this);
 }