Search Results for

    Show / Hide Table of Contents

    Class Session

    An object encapsulating a synchronization session. Sessions represent the communication between the client (and a local Realm file on disk), and MongoDB Atlas. Sessions are always created by the SDK and vended out through various APIs. The lifespans of sessions associated with Realms are managed automatically.

    Inheritance
    Object
    Session
    Implements
    INotifyPropertyChanged
    Namespace: Realms.Sync
    Assembly: Realm.dll
    Syntax
    public class Session : INotifyPropertyChanged

    Properties

    | Improve this Doc View Source

    ConnectionState

    Gets the session’s current connection state.

    Declaration
    public ConnectionState ConnectionState { get; }
    Property Value
    Type Description
    ConnectionState

    An enum value indicating the connection state of the session.

    | Improve this Doc View Source

    Path

    Gets the on-disk path of the Realm file backing the Realm this Session represents.

    Declaration
    public string Path { get; }
    Property Value
    Type Description
    String

    The file path.

    | Improve this Doc View Source

    State

    Gets the session’s current state.

    Declaration
    public SessionState State { get; }
    Property Value
    Type Description
    SessionState

    An enum value indicating the state of the session.

    | Improve this Doc View Source

    User

    Gets the User defined by the SyncConfigurationBase that is used to connect to MongoDB Atlas.

    Declaration
    public User User { get; }
    Property Value
    Type Description
    User

    The User that was used to create the Realm's SyncConfigurationBase.

    Methods

    | Improve this Doc View Source

    GetProgressObservable(ProgressDirection, ProgressMode)

    Gets an IObservable<T> that can be used to track upload or download progress.

    Declaration
    public IObservable<SyncProgress> GetProgressObservable(ProgressDirection direction, ProgressMode mode)
    Parameters
    Type Name Description
    ProgressDirection direction

    The transfer direction (upload or download) to track in the subscription callback.

    ProgressMode mode

    The desired behavior of this progress notification block.

    Returns
    Type Description
    IObservable<SyncProgress>

    An observable that you can subscribe to and receive progress updates.

    Remarks

    To start receiving notifications, you should call Subscribe(IObserver<T>) on the returned object. The token returned from Subscribe(IObserver<T>) should be retained as long as progress notifications are desired. To stop receiving notifications, call Dispose() on the token. You don't need to keep a reference to the observable itself. The progress callback will always be called once immediately upon subscribing in order to provide the latest available status information.

    Examples
    class ProgressNotifyingViewModel
    {
        private IDisposable notificationToken;
    
        public void ShowProgress()
        {
            var observable = session.GetProgressObservable(ProgressDirection.Upload, ProgressMode.ReportIndefinitely);
            notificationToken = observable.Subscribe(progress =>
            {
                // Update relevant properties by accessing
                // progress.TransferredBytes and progress.TransferableBytes
            });
        }
    
        public void HideProgress()
        {
            notificationToken?.Dispose();
            notificationToken = null;
        }
    }

    In this example we're using ObservableExtensions.Subscribe found in the Reactive Extensions class library. If you prefer not to take a dependency on it, you can create a class that implements IObserver<T> and use it to subscribe instead.

    | Improve this Doc View Source

    Start()

    Attempts to resume the session and enable synchronization with the server.

    Declaration
    public void Start()
    Remarks

    All sessions will be active by default and calling this method only makes sense if Stop() was called before that.

    | Improve this Doc View Source

    Stop()

    Stops any synchronization with the server until the Realm is re-opened again after fully closing it.
    Synchronization can be re-enabled by calling Start() again.

    Declaration
    public void Stop()
    Remarks

    If the session is already stopped, calling this method will do nothing.

    | Improve this Doc View Source

    WaitForDownloadAsync()

    Waits for the Session to finish all pending downloads.

    Declaration
    public Task WaitForDownloadAsync()
    Returns
    Type Description
    Task

    An awaitable Task that will be completed when all pending downloads for this Session are completed.

    Exceptions
    Type Condition
    InvalidOperationException

    Thrown when a faulted session is waited on.

    | Improve this Doc View Source

    WaitForUploadAsync()

    Waits for the Session to finish all pending uploads.

    Declaration
    public Task WaitForUploadAsync()
    Returns
    Type Description
    Task

    An awaitable Task that will be completed when all pending uploads for this Session are completed.

    Exceptions
    Type Condition
    InvalidOperationException

    Thrown when a faulted session is waited on.

    Events

    | Improve this Doc View Source

    Error

    Triggered when an error occurs on a session. The sender argument will be the session which has errored.

    Declaration
    [Obsolete("Use SyncConfigurationBase.OnSessionError in conjunction with SyncConfigurationBase.ClientResetHandler instead.")]
    public static event EventHandler<ErrorEventArgs> Error
    Event Type
    Type Description
    EventHandler<ErrorEventArgs>
    | Improve this Doc View Source

    PropertyChanged

    Occurs when a property value changes.

    Declaration
    public event PropertyChangedEventHandler PropertyChanged
    Event Type
    Type Description
    PropertyChangedEventHandler

    Implements

    System.ComponentModel.INotifyPropertyChanged

    Extension Methods

    TestingExtensions.SimulateError(Session, ErrorCode, String, Boolean)
    TestingExtensions.SimulateClientReset(Session, String)
    TestingExtensions.SimulateAutomaticClientResetFailure(Session, String)
    • Improve this Doc
    • View Source
    In This Article
    Back to top Copyright © 2020 Realm
    Generated by DocFX