Skip to content
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

Fix basic replication configuration C# snippet #919

Open
wants to merge 1 commit into
base: release/3.2
Choose a base branch
from
Open
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
132 changes: 75 additions & 57 deletions modules/csharp/examples/code_snippets/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,81 @@ public void datatype_mutable_array()
// end::datatype_mutable_array[]
}

public void SetupReplication()
{
var db = _Database;

// tag::p2p-act-rep-func[]
// tag::p2p-act-rep-initialize[]
// initialize the replicator configuration
var endpoint = new URLEndpoint(new Uri("wss://listener.com:4984/otherDB")); // <.>
var config = new ReplicatorConfiguration(endpoint); // <.>

// Start adding collections to use
var collectionConfig = new CollectionConfiguration();

// tag::p2p-act-rep-config-conflict-full[]
// tag::p2p-act-rep-config-conflict-custom[]
// optionally use custom resolver
collectionConfig.ConflictResolver = new LocalWinConflictResolver();

// end::p2p-act-rep-config-conflict-custom[]
// end::p2p-act-rep-config-conflict-full[]
config.AddCollection(db.GetDefaultCollection(), collectionConfig);

// end::p2p-act-rep-initialize[]
// tag::p2p-act-rep-config-type[]
// Set replicator type
config.ReplicatorType = ReplicatorType.PushAndPull;

// end::p2p-act-rep-config-type[]
// tag::autopurge-override[]
// Set autopurge option
// here we override its default
config.EnableAutoPurge = false; // <.>

// end::autopurge-override[]
// tag::p2p-act-rep-config-cont[]
// Configure Sync Mode
config.Continuous = true;

// end::p2p-act-rep-config-cont[]
// tag::p2p-act-rep-config-self-cert[]
// Configure Server Security -- only accept self-signed certs
config.AcceptOnlySelfSignedServerCertificate = true; // <.>

// end::p2p-act-rep-config-self-cert[]
// Configure Client Security
// tag::p2p-act-rep-auth[]
// Configure basic auth using user credentials
config.Authenticator = new BasicAuthenticator("Our Username", "Our Password"); // <.>

// tag::p2p-act-rep-start-full[]
// Initialize and start a replicator
// Initialize replicator with configuration data
var replicator = new Replicator(config); // <.>

// tag::p2p-act-rep-add-change-listener[]
// tag::p2p-act-rep-add-change-listener-label[]
//Optionally add a change listener // <.>
// end::p2p-act-rep-add-change-listener-label[]
var listenerToken = replicator.AddChangeListener((sender, args) =>
{
if (args.Status.Activity == ReplicatorActivityLevel.Stopped) {
Console.WriteLine("Replication stopped");
}
});

// end::p2p-act-rep-add-change-listener[]
// tag::p2p-act-rep-start[]
// Start replicator
replicator.Start(); // <.>

// end::p2p-act-rep-start[]
// end::p2p-act-rep-start-full[]
// end::p2p-act-rep-func[]
}

static void Main(string[] args)
{
// NOTE: PLEASE PLEASE PLEASE do not break the compilation of this file. It is
Expand Down Expand Up @@ -2464,63 +2539,6 @@ public Document Resolve(Conflict conflict)
// end::merge-conflict-resolver[]
}

#warning p2p-act-rep-func used, but contains nothing
// tag::p2p-act-rep-func[]

#warning p2p-act-rep-config-type used, but contains nothing
// tag::p2p-act-rep-config-type[]

// end::p2p-act-rep-config-type[]

#warning autopurge-override used, but contains nothing
// tag::autopurge-override[]
// Set autopurge option
// here we override its default

// end::autopurge-override[]

#warning p2p-act-rep-config-cont used, but contains nothing
// tag::p2p-act-rep-config-cont[]
// Configure Sync Mode

// end::p2p-act-rep-config-cont[]

#warning p2p-act-rep-config-self-cert used, but contains nothing
// tag::p2p-act-rep-config-self-cert[]
// Configure Server Security -- only accept self-signed certs

// end::p2p-act-rep-config-self-cert[]

// Configure Client Security // <.>

#warning p2p-act-rep-auth used, but contains nothing
// tag::p2p-act-rep-auth[]
// Configure basic auth using user credentials

// end::p2p-act-rep-auth[]

#warning p2p-act-rep-start-full used, but contains nothing
// tag::p2p-act-rep-start-full[]
// Initialize and start a replicator
// Initialize replicator with configuration data

#warning p2p-act-rep-add-change-listener used, but contains nothing
// tag::p2p-act-rep-add-change-listener[]
#warning p2p-act-rep-add-change-listener-label used, but contains nothing
// tag::p2p-act-rep-add-change-listener-label[]
//Optionally add a change listener // <.>
// end::p2p-act-rep-add-change-listener-label[]

// end::p2p-act-rep-add-change-listener[]

#warning p2p-act-rep-start used, but contains nothing
// tag::p2p-act-rep-start[]
// Start replicator

// end::p2p-act-rep-start[]
// end::p2p-act-rep-start-full[]
// end::p2p-act-rep-func[]

#warning p2p-act-rep-config-cacert used, but contains nothing
// tag::p2p-act-rep-config-cacert[]
// Configure Server Security -- only accept CA certs
Expand Down