Class Session
An object encapsulating a Realm Object Server session. Sessions represent the communication between the client (and a local Realm file on disk), and the server (and a remote Realm at a given URL stored on a Realm Object Server). Sessions are always created by the SDK and vended out through various APIs. The lifespans of sessions associated with Realms are managed automatically.
Namespace: Realms.Sync
Assembly: Realm.Sync.dll
Syntax
public class Session : object
Properties
| Improve this Doc View SourcePath
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. |
ServerUri
Gets the
Declaration
public Uri ServerUri { get; }
Property Value
Type | Description |
---|---|
Uri | The |
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. |
User
Gets the User defined by the SyncConfiguration that is used to connect to the Realm Object Server.
Declaration
public User User { get; }
Property Value
Type | Description |
---|---|
User | The User that was used to create the Realm's SyncConfiguration. |
Methods
| Improve this Doc View SourceEquals(Object)
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj |
Returns
Type | Description |
---|---|
Boolean |
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 |
GetProgressObservable(ProgressDirection, ProgressMode)
Gets an
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
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
Reconnect()
Attempts to reconnect all sessions.
Declaration
public static void Reconnect()
Remarks
By default, the sync engine will attempt to reconnect sessions at incrementing intervals. This method is useful when you are monitoring connectivity yourself, using e.g. Connectivity Plugin or through the native connectivity API and you wish to cancel that delay and try to reconnect immediately.
WaitForDownloadAsync()
Waits for the Session to finish all pending downloads.
Declaration
public Task WaitForDownloadAsync()
Returns
Type | Description |
---|---|
Task | A |
WaitForUploadAsync()
Waits for the Session to finish all pending uploads.
Declaration
public Task WaitForUploadAsync()
Returns
Type | Description |
---|---|
Task | A |
Events
| Improve this Doc View SourceError
Triggered when an error occurs on a session. The sender
argument will be the session which has errored.
Declaration
public static event EventHandler<ErrorEventArgs> Error
Event Type
Type | Description |
---|---|
EventHandler<ErrorEventArgs> |