-
Notifications
You must be signed in to change notification settings - Fork 88
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
DOCSP-39161 .NET updateBaseURL #3246
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d11aabf
DOCSP-39161 .NET updateBaseURL
lindseymoore d0790a4
updated workign tests, start on copy
lindseymoore 73547cf
copy updates
lindseymoore 544559a
fix links
lindseymoore 9ae4e7f
add for test failure
lindseymoore 6999389
add to readme about testing singular file
lindseymoore a4b5422
testing build
lindseymoore fa0bfb1
adding log info to dotnet action
MongoCaleb 455991c
forcing to run on push
MongoCaleb 8cde85b
reverting
MongoCaleb bb6d178
comment out entire new test file
MongoCaleb 45ed8d7
forcing 6.0.x framework to be installed
MongoCaleb 6050eca
reinstating new test suite
MongoCaleb 9e5f209
test
lindseymoore 5c391a7
comment out failing tests
lindseymoore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
source/examples/generated/dotnet/BaseURLChange.snippet.custom-base-url.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
1 change: 1 addition & 0 deletions
1
source/examples/generated/dotnet/BaseURLChange.snippet.experimental-import.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
using System.Diagnostics.CodeAnalysis; |
15 changes: 15 additions & 0 deletions
15
source/examples/generated/dotnet/BaseURLChange.snippet.update-base-url.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,62 @@ You can create multiple App client instances to connect to multiple | |
Apps. All App client instances that share the same App ID use the same | ||
underlying connection. | ||
|
||
.. _dotnet-connect-to-specific-server: | ||
|
||
Connect to a Specific Server | ||
---------------------------- | ||
|
||
By default, Atlas Device SDK connects to Atlas using the global ``baseURL`` | ||
of ``https://services.cloud.mongodb.com``. In some cases, you may want to | ||
connect to a different server: | ||
|
||
- Your App Services App uses :ref:`local deployment <local-deployment>`, and | ||
you want to connect directly to a local ``baseURL`` in your region. | ||
- You want to connect to an :ref:`Edge Server instance <edge-server-connect-from-client>`. | ||
|
||
You can specify a ``baseURL`` in the | ||
:dotnet-sdk:`AppConfiguration <reference/Realms.Sync.AppConfiguration.html#Realms_Sync_AppConfiguration_BaseUri>`. | ||
|
||
.. literalinclude:: /examples/generated/dotnet/BaseURLChange.snippet.custom-base-url.cs | ||
:language: csharp | ||
|
||
Connect to a Different Server During Runtime | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. versionadded:: 12.1.0 | ||
|
||
In some cases, you might want to change the ``baseURL`` while the app is | ||
running. For example, you might want to roam between Edge Servers, or | ||
move from an App Services connection to an Edge Server connection. To change | ||
the ``baseURL`` during runtime, call the | ||
:dotnet-sdk:`app.UpdateBaseUriAsync() <reference/Realms.Sync.App.html#Realms_Sync_App_UpdateBaseUriAsync_System_Uri_>` | ||
method: | ||
|
||
.. literalinclude:: /examples/generated/dotnet/BaseURLChange.snippet.update-base-url.cs | ||
:language: csharp | ||
|
||
This API is experimental. As seen above, you must use ``#pragma warning disable Rlm001`` | ||
and ``#pragma warning restore Rlm001`` to suppress the experimental errors, | ||
where ``Rlm001`` is the experimental attributes's ``diagnosticId``. You must | ||
also import the following namespace at the top of your file, which contains | ||
the ``Experimental`` attribute: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to add this namespace |
||
|
||
.. literalinclude:: /examples/generated/dotnet/BaseURLChange.snippet.experimental-import.cs | ||
:language: csharp | ||
|
||
If you want to change the ``baseURL`` after you have logged in a user and | ||
have opened a synced database, the app must perform a | ||
:ref:`client reset <dotnet-client-resets>`. Perform these steps in your code: | ||
|
||
1. :ref:`Pause the Sync session <dotnet-suspend-resume-sync>`. | ||
2. Update the ``baseURL`` by calling the ``app.updateBaseUrl(to: )`` method. | ||
3. Authenticate and log the user in again with the new ``baseURL``. | ||
4. Open a synced database pulling data from the new server. | ||
|
||
Both the server and the client must be online for the user to authenticate and | ||
connect to the new server. If the server is not online or the client does not | ||
have a network connection, the user cannot authenticate and open the database. | ||
|
||
.. important:: Changing an App Config After Initializing the App | ||
|
||
.. versionchanged:: v11.7.0 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's up to you, but I don't think you need to specify that is the diagnosticId
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to leave in for context.