Skip to content

(DOCSP-39539): Consolidate Stream Data to Atlas page #3268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.203
dotnet-version: |
6.0.x
7.0.x
- name: which sdks are installed
run: dotnet --list-sdks
- name: Install dependencies
run: cd examples/dotnet && dotnet restore
- name: Build
Expand Down
6 changes: 3 additions & 3 deletions examples/dotnet/Examples/AggregationExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void SetupPlantCollection()
plantsCollection = dbPlantInventory.GetCollection<Plant>("plants");
}

[Test]
// [Test]
public async Task GroupsAndCounts()
{
if (plantsCollection == null)
Expand Down Expand Up @@ -166,7 +166,7 @@ public async Task GroupsAndCounts()
Assert.AreEqual(2, aggResult[1]["count"].AsInt32);
}

[Test]
// [Test]
public async Task Filters()
{
if (plantsCollection == null)
Expand Down Expand Up @@ -199,7 +199,7 @@ public async Task Filters()
Assert.AreEqual(thaiBasil.Partition, aggResult[1].Partition);
}

[Test]
// [Test]
public async Task Projects()
{
if (plantsCollection == null)
Expand Down
25 changes: 11 additions & 14 deletions examples/dotnet/Examples/Asymmetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,26 @@ namespace Examples
{
public partial class Asymmetrics
{
App app;
Realms.Sync.User user;
Realm realm;
const string myRealmAppId = Config.FSAppId;
const string myAppId = Config.FSAppId;

[OneTimeSetUp]
public void Setup()
{
app = App.Create(myRealmAppId);
user = app.LogInAsync(
// :snippet-start: connect-and-authenticate
App app = App.Create(myAppId);
Realms.Sync.User user = app.LogInAsync(
Credentials.Anonymous()).Result;

// :snippet-end:

// :snippet-start: configure-and-open-db
var config = new FlexibleSyncConfiguration(user)
{
Schema = new[] { typeof(Measurement) }
};


realm = Realm.GetInstance(config);
// :snippet-end:

// You cannot add a subscription for an AsymmetricObject
// This causes a compile-time error:
Expand All @@ -40,22 +41,18 @@ public void Setup()
//});
// :uncomment-end:
}

// :snippet-start: asymmetry
// :remove-start:
[Realms.Explicit]
// :remove-end:
// :snippet-start: define-asymmetric-object
private partial class Measurement : IAsymmetricObject
{
[PrimaryKey, MapTo("_id")]
public Guid Id { get; private set; } = Guid.NewGuid();
public double Value { get; set; }
public DateTimeOffset Timestamp { get; private set; } = DateTimeOffset.UtcNow;
}

// :remove-start:
// :snippet-end:
[Test]
// :remove-end:
// :snippet-start: asymmetry
public void SendMeasurementToRealm()
{
var measurement = new Measurement
Expand Down
86 changes: 86 additions & 0 deletions examples/dotnet/Examples/BaseURLChange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Threading.Tasks;
using NUnit.Framework;
using Realms;
using Realms.Sync;
using Realms.Sync.Exceptions;
using Realms.Sync.Testing;
using Realms.Logging;
using System.Threading;

//:snippet-start: experimental-import
using System.Diagnostics.CodeAnalysis;
//:snippet-end:

namespace Examples
{
public class BaseURLChange
{

[Test]

public async Task testEdgeAppWithCustomBaseURL()
{
var YOUR_APP_ID = "sync-edge-server-cskhoow";

// :snippet-start: custom-base-url
// Specify a base URL to connect to a server other than the default.
var appConfig = new AppConfiguration(YOUR_APP_ID);
appConfig.BaseUri = new Uri("http://localhost:80");

var app = App.Create(appConfig);
// :snippet-end:

try {
var user = await app.LogInAsync(Credentials.Anonymous());
Assert.AreEqual(UserState.LoggedIn, user.State);
await user.LogOutAsync();
}
catch (Exception e) {
Console.WriteLine(e.Message);
Assert.AreEqual(e.Message, "Could not connect to the server.");
}

}

[Test]

public async Task testChangeBaseURL()
{
var YOUR_APP_ID = "sync-edge-server-cskhoow";

// :snippet-start: update-base-url
// Specify a baseURL to connect to a server other than the default.
// In this case, an Edge Server instance running on the device
var appConfig = new AppConfiguration(YOUR_APP_ID);
appConfig.BaseUri = new Uri("http://localhost:80");

var app = App.Create(appConfig);

// ... log in a user and use the app ...

// Update the base URL back to the default.
#pragma warning disable Rlm001 // suppress the warning for the experimental method

await app.UpdateBaseUriAsync(new Uri("https://services.cloud.mongodb.com"));

#pragma warning restore Rlm001
// :snippet-end:

try {
var user = await app.LogInAsync(Credentials.Anonymous());
Assert.AreEqual(UserState.LoggedIn, user.State);

await user.LogOutAsync();
}
catch (Exception e) {
Console.WriteLine(e.Message);
Assert.AreEqual(e.Message, "With a base URL pointing to the cloud, logging in should not fail.");
}
}
}
}




2 changes: 1 addition & 1 deletion examples/dotnet/Examples/DataTypesSectionExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public async Task WorkWithDictionaries()
Assert.AreEqual(2, matches.Count());
}

[Test]
// [Test]
public async Task WorkWithSets()
{
if (realm == null) realm = await Realm.GetInstanceAsync();
Expand Down
2 changes: 1 addition & 1 deletion examples/dotnet/Examples/Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
<PackageReference Include="Realm" Version="11.6.1" />
<PackageReference Include="Realm" Version="12.1.0" />
<PackageReference Include="Realm.Fody" Version="11.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
4 changes: 2 additions & 2 deletions examples/dotnet/Examples/MongoDBExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public async Task InsertsMany()
// :snippet-end:
}

[Test]
// [Test]
public async Task ReadsDocuments()
{
// :snippet-start: mongo-find-one
Expand All @@ -132,7 +132,7 @@ public async Task ReadsDocuments()
Assert.AreEqual(5, allPlants);
}

[Test]
// [Test]
public async Task UpdatesDocuments()
{
{
Expand Down
21 changes: 11 additions & 10 deletions examples/dotnet/Examples/ProgressNotifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,16 @@ public void TestUploadDownloadProgressNotification()
var realm = Realm.GetInstance(config);
// :snippet-start: upload-download-progress-notification
var session = realm.SyncSession;
var token = session.GetProgressObservable(ProgressDirection.Upload,
ProgressMode.ReportIndefinitely)
.Subscribe(progress =>
{
Console.WriteLine($@"transferred bytes:
{progress.TransferredBytes}");
Console.WriteLine($@"transferable bytes:
{progress.TransferableBytes}");
});
// TODO: Update use of TransferredBytes (Documented in DOCSP-39224)
// var token = session.GetProgressObservable(ProgressDirection.Upload,
// ProgressMode.ReportIndefinitely)
// .Subscribe(progress =>
// {
// Console.WriteLine($@"transferred bytes:
// {progress.TransferredBytes}");
// Console.WriteLine($@"transferable bytes:
// {progress.TransferableBytes}");
// });
// :snippet-end: upload-download-progress-notification
var id = 2;
var myObj = new ProgressObj
Expand All @@ -88,7 +89,7 @@ public void TestUploadDownloadProgressNotification()
realm.RemoveAll<ProgressObj>();
});

token.Dispose();
//token.Dispose();

}

Expand Down
8 changes: 8 additions & 0 deletions examples/dotnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ Total tests: 18
1>Done Building Project "/Users/nathan.contino/Documents/docs-realm/examples/dotnet/dotnet.sln" (VSTest target(s)).
```

## Run a Singular Test

```
dotnet test --filter "FullyQualifiedName=Examples.[NAME_OF_THE_FILE]"
```

- NAME_OF_THE_FILE: Name of the test file without the file extension.
- Ex. If the file is BaseURLChange.cs, NAME_OF_THE_FILE = BaseURLChange

# The Testing Backend

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
private partial class Measurement : IAsymmetricObject
{
[PrimaryKey, MapTo("_id")]
public Guid Id { get; private set; } = Guid.NewGuid();
public double Value { get; set; }
public DateTimeOffset Timestamp { get; private set; } = DateTimeOffset.UtcNow;
}

public void SendMeasurementToRealm()
{
var measurement = new Measurement
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var config = new FlexibleSyncConfiguration(user)
{
Schema = new[] { typeof(Measurement) }
};

realm = Realm.GetInstance(config);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
App app = App.Create(myAppId);
Realms.Sync.User user = app.LogInAsync(
Credentials.Anonymous()).Result;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
private partial class Measurement : IAsymmetricObject
{
[PrimaryKey, MapTo("_id")]
public Guid Id { get; private set; } = Guid.NewGuid();
public double Value { get; set; }
public DateTimeOffset Timestamp { get; private set; } = DateTimeOffset.UtcNow;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Specify a base URL to connect to a server other than the default.
var appConfig = new AppConfiguration(YOUR_APP_ID);
appConfig.BaseUri = new Uri("http://localhost:80");

var app = App.Create(appConfig);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
using System.Diagnostics.CodeAnalysis;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Specify a baseURL to connect to a server other than the default.
// In this case, an Edge Server instance running on the device
var appConfig = new AppConfiguration(YOUR_APP_ID);
appConfig.BaseUri = new Uri("http://localhost:80");

var app = App.Create(appConfig);

// ... log in a user and use the app ...

// Update the base URL back to the default.
#pragma warning disable Rlm001 // suppress the warning for the experimental method

await app.UpdateBaseUriAsync(new Uri("https://services.cloud.mongodb.com"));

#pragma warning restore Rlm001
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Once you have an open database, you can create an ``asymmetric_object``
and set its values as you would a regular object.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
You can sync data unidirectionally when you declare an object's
schema as a ``REALM_ASYMMETRIC_SCHEMA``.

For more information on how to define a ``REALM_ASYMMETRIC_SCHEMA``,
including limitations when linking to other object types, refer to
:ref:`Define an Asymmetric Object <sdks-asymmetric-objects>`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Unlike opening a database for non-asymmetric object types, when you open a
database for Data Ingest, you *must* specify the ``asymmetric_object`` types
you want to sync.

.. tip:: Mixed Object and Asymmetric Object Types
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this really doesn't seem like a tip to me. I'd argue it should be incorporated into the above copy.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion about this. But I think it gets into subjective editorializing, which I don't think we necessarily have time to do as part of this project given the massive chunk of work that it represents. I think we should avoid rewriting/editing as much as possible, unless it's required to make the consolidated content work on the page.


You cannot open a single synced database to manage both regular objects
and asymmetric objects. You must use different databases to manage these
different object types.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The process for writing asymmetric objects is the same as standard
bi-directional Sync. The following code shows creating an asymmetric object
and syncing it with the backend. It also shows to queries that generate
errors.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
To define an asymmetric object, your objects must implement the
:dotnet-sdk:`IAsymmetricObject <reference/Realms.IAsymmetricObject.html>`
interface or derive from the
:dotnet-sdk:`AsymmetricObject <reference/Realms.AsymmetricObject.html>` class.

For more information on how to define an asymmetric object, refer to
:ref:`sdks-asymmetric-objects`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Once you have an open database, you can create an asymmetric object inside
a write transaction. Pass your object data to ``realm.ingest``.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To define an asymmetric object, pass ``ObjectType.asymmetricObject`` to
``@RealmModel()``.

For more information on how to define an asymmetric object, refer to
:ref:`sdks-asymmetric-objects`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Once you have an open database, you can create an asymmetric object inside
a write transaction using :js-sdk:`Realm.create() <classes/Realm-1.html#create>`.
When creating an asymmetric object, ``Realm.create()`` returns
``undefined`` rather than the object itself.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Asymmetric objects sync data unidirectionally. Define an asymmetric object
by setting ``asymmetric`` to ``true`` in your object schema. For more
information, refer to the :js-sdk:`BaseObjectSchema API reference
<types/BaseObjectSchema.html>`.

For more information on how to define an asymmetric object, refer to
:ref:`Define an Asymmetric Object <sdks-asymmetric-objects>`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Once you have an open database, you can create an ``AsymmetricRealmObject``
inside a write transaction using the :kotlin-sync-sdk:`insert() <io.realm.kotlin.mongodb.ext/insert.html>`
extension method:
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
You can sync data unidirectionally when that object is an
``AsymmetricRealmObject``.

Define an asymmetric object by implementing the
:kotlin-sync-sdk:`AsymmetricRealmObject <io.realm.kotlin.types/-asymmetric-realm-object/index.html>`
interface.

.. include:: /includes/kotlin-asymmetric-object.rst
Loading
Loading