### Example .NET Version Log Source: https://github.com/couchbase/couchbase-lite-net/blob/master/CONTRIBUTING.md This is an example of version information that might be printed to logs in a .NET environment. It includes the version and a Git commit ID. ```text Manager: Starting Manager version: Unofficial (master: 74293bf) ``` -------------------------------- ### Couchbase Lite .NET Replication Setup Source: https://github.com/couchbase/couchbase-lite-net/blob/master/packaging/nuget/README.md Demonstrates setting up a replicator to synchronize data with a remote endpoint, including authentication. Ensure the URLEndpoint and authenticator are correctly configured. ```csharp // Create replicator to push and pull changes to and from the cloud var targetEndpoint = new URLEndpoint(new Uri("ws://localhost:4984/getting-started-db")); var replConfig = new ReplicatorConfiguration(targetEndpoint); replConfig.AddCollection(database.GetDefaultCollection()); // Add authentication replConfig.Authenticator = new BasicAuthenticator("john", "pass"); // Create replicator var replicator = new Replicator(replConfig); replicator.AddChangeListener((sender, args) => { if (args.Status.Error != null) { Console.WriteLine($"Error :: {args.Status.Error}"); } }); replicator.Start(); // Later, stop and dispose the replicator *before* closing/disposing the database ``` -------------------------------- ### c4log_getDomain Source: https://github.com/couchbase/couchbase-lite-net/blob/master/src/LiteCore/src/LiteCore.Shared/Interop/raw_literals.txt Gets or creates a C4LogDomain based on its name. This is used for managing logging contexts within LiteCore. ```APIDOC ## c4log_getDomain ### Description Gets or creates a C4LogDomain based on its name. ### Signature `public static extern C4LogDomain* c4log_getDomain(byte* name, [MarshalAs(UnmanagedType.U1)]bool create);` ### Parameters * `name` (byte*) - A pointer to the name of the log domain. * `create` (bool) - If true, creates the domain if it does not exist. ### Returns `C4LogDomain*` - A pointer to the C4LogDomain. ``` -------------------------------- ### c4dbobs_getChanges Source: https://github.com/couchbase/couchbase-lite-net/blob/master/src/LiteCore/src/LiteCore.Shared/Interop/raw_literals.txt Retrieves changes from a C4CollectionObserver. This function is used to get updates related to database observations. ```APIDOC ## c4dbobs_getChanges ### Description Retrieves changes from a C4CollectionObserver. ### Signature `public static extern C4CollectionObservation c4dbobs_getChanges(C4CollectionObserver* observer, [Out]C4CollectionChange[] outChanges, uint maxChanges);` ### Parameters * `observer` (C4CollectionObserver*) - A pointer to the C4CollectionObserver. * `outChanges` ([Out]C4CollectionChange[]) - An array to store the C4CollectionChange objects representing the observed changes. * `maxChanges` (uint) - The maximum number of changes to retrieve. ### Returns `C4CollectionObservation` - An object containing information about the retrieved changes. ``` -------------------------------- ### Build the .NET Solution Source: https://github.com/couchbase/couchbase-lite-net/blob/master/AGENTS.md Use this command to build the entire Couchbase Lite .NET solution. ```bash # Build the solution dotnet build src/Couchbase.Lite.sln ``` -------------------------------- ### Basic Couchbase Lite .NET Operations Source: https://github.com/couchbase/couchbase-lite-net/blob/master/packaging/nuget/README.md Demonstrates creating a database, collection, adding, retrieving, and updating documents. Ensure the database and collection are properly initialized before use. ```csharp using System; using Couchbase.Lite; using Couchbase.Lite.Query; using Couchbase.Lite.Sync; // Get the database (and create it if it doesn't exist) var database = new Database("mydb"); var collection = database.GetDefaultCollection(); // Create a new document (i.e. a record) in the database var id = default(string); using var createdDoc = new MutableDocument(); createdDoc.SetFloat("version", 2.0f) .SetString("type", "SDK"); // Save it to the database collection.Save(createdDoc); id = createdDoc.Id; // Update a document using var doc = collection.GetDocument(id); using var mutableDoc = doc.ToMutable(); createdDoc.SetString("language", "C#"); collection.Save(createdDoc); using var docAgain = collection.GetDocument(id); Console.WriteLine($"Document ID :: {docAgain.Id}"); Console.WriteLine($"Learning {docAgain.GetString("language")}"); ``` -------------------------------- ### Couchbase Lite .NET Querying Source: https://github.com/couchbase/couchbase-lite-net/blob/master/packaging/nuget/README.md Shows how to create and execute queries using both the fluent API and SQL++. Ensure the collection and query expressions are correctly defined. ```csharp // Create a query to fetch documents of type SDK // i.e. SELECT * FROM database WHERE type = "SDK" using var query = QueryBuilder.Select(SelectResult.All()) .From(DataSource.Collection(collection)) .Where(Expression.Property("type").EqualTo(Expression.String("SDK"))); // Alternatively, using SQL++, with _ referring to the database using var sqlppQuery = collection.CreateQuery("SELECT * FROM _ WHERE type = 'SDK'"); // Run the query var result = query.Execute(); Console.WriteLine($"Number of rows :: {result.AllResults().Count}"); ``` -------------------------------- ### Build a Single .NET Project Source: https://github.com/couchbase/couchbase-lite-net/blob/master/AGENTS.md Use this command to build a specific project within the Couchbase Lite .NET solution. ```bash # Build a single project dotnet build src/Couchbase.Lite/Couchbase.Lite.csproj ``` -------------------------------- ### C# Bracket Placement Guidelines Source: https://github.com/couchbase/couchbase-lite-net/blob/master/Notes/StyleGuidelines.md Demonstrates the standard placement of brackets for various code constructs including namespaces, classes, methods, control flow statements, and lambda expressions. ```csharp namespace { class { Method() { if { } else { } while { } for { } using { } try { } catch { } finally { } (closure) => { } } } } ``` -------------------------------- ### Run Core .NET Tests Source: https://github.com/couchbase/couchbase-lite-net/blob/master/AGENTS.md Execute the core console tests for Couchbase Lite .NET. This is the fastest way to run tests. ```bash # Console core tests (fastest) dotnet test src/Couchbase.Lite.Tests.NetCore/Couchbase.Lite.Tests.NetCore.csproj ``` -------------------------------- ### FLDictKey_Init Source: https://github.com/couchbase/couchbase-lite-net/blob/master/src/LiteCore/src/LiteCore.Shared/Interop/bridge_literals.txt Initializes an FLDictKey from a string. This is intended for use with constant strings due to unmanaged memory allocation. ```APIDOC ## FLDictKey_Init ### Description Initializes an FLDictKey from a string. Use with constants as it allocates unmanaged memory. ### Signature public static FLDictKey FLDictKey_Init(string str) ### Parameters - **str** (string): The string to initialize the FLDictKey with. ### Returns (FLDictKey): The initialized FLDictKey. ``` -------------------------------- ### Initialize FLDictKey from String Source: https://github.com/couchbase/couchbase-lite-net/blob/master/src/LiteCore/src/LiteCore.Shared/Interop/bridge_literals.txt Initializes an FLDictKey from a constant string. Note: This allocates unmanaged heap memory and should only be used with string literals. ```csharp // Note: Allocates unmanaged heap memory; should only be used with constants public static FLDictKey FLDictKey_Init(string str) { return NativeRaw.FLDictKey_Init(FLSlice.Constant(str)); } ``` -------------------------------- ### Run a Single .NET Test Source: https://github.com/couchbase/couchbase-lite-net/blob/master/AGENTS.md Use this command to run a specific test by its fully qualified name within the Couchbase Lite .NET test suite. ```bash # Run a single test dotnet test src/Couchbase.Lite.Tests.NetCore/Couchbase.Lite.Tests.NetCore.csproj --filter "FullyQualifiedName~TestMethodName" ``` -------------------------------- ### Put C4Document Source: https://github.com/couchbase/couchbase-lite-net/blob/master/src/LiteCore/src/LiteCore.Shared/Interop/bridge_literals.txt Inserts or updates a C4Document in a database. Handles potential common ancestor conflicts by returning an index. ```csharp public static C4Document* c4doc_put(C4Database *database, C4DocPutRequest *request, ulong* outCommonAncestorIndex, C4Error *outError) { var uintptr = new UIntPtr(); var retVal = NativeRaw.c4doc_put(database, request, &uintptr, outError); if(outCommonAncestorIndex != null) { *outCommonAncestorIndex = uintptr.ToUInt64(); } return retVal; } ``` -------------------------------- ### Convert JSON5 to JSON Source: https://github.com/couchbase/couchbase-lite-net/blob/master/src/LiteCore/src/LiteCore.Shared/Interop/bridge_literals.txt Converts a JSON5 formatted string to a standard JSON string. Provides error information if conversion fails. ```csharp public static string? FLJSON5_ToJSON(string json5, FLSlice* outErrorMessage, UIntPtr* outErrPos, FLError* err) { using(var json5_ = new C4String(json5)) { using(var retVal = NativeRaw.FLJSON5_ToJSON((FLSlice)json5_.AsFLSlice(), outErrorMessage, outErrPos, err)) { return ((FLSlice)retVal).CreateString(); } } } ``` -------------------------------- ### Write to C4WriteStream Source: https://github.com/couchbase/couchbase-lite-net/blob/master/src/LiteCore/src/LiteCore.Shared/Interop/bridge_literals.txt Writes a byte array to a C4WriteStream. The length parameter specifies the number of bytes to write. ```csharp public static bool c4stream_write(C4WriteStream* stream, byte[] bytes, ulong length, C4Error* outError) { return NativeRaw.c4stream_write(stream, bytes, (UIntPtr)length, outError); } ``` -------------------------------- ### c4doc_put Source: https://github.com/couchbase/couchbase-lite-net/blob/master/src/LiteCore/src/LiteCore.Shared/Interop/bridge_literals.txt Puts a document into a C4Database. This function handles the creation or update of documents. ```APIDOC ## c4doc_put ### Description Puts a document into a C4Database, handling creation or updates. ### Signature public static C4Document* c4doc_put(C4Database *database, C4DocPutRequest *request, ulong* outCommonAncestorIndex, C4Error *outError) ### Parameters - **database** (C4Database *): The database to put the document into. - **request** (C4DocPutRequest *): The request object containing document data and metadata. - **outCommonAncestorIndex** (ulong*): Pointer to store the common ancestor index if applicable. - **outError** (C4Error *): Pointer to a C4Error structure to store any error information. ### Returns (C4Document *): A pointer to the C4Document if successful, otherwise null. ``` -------------------------------- ### c4stream_write Source: https://github.com/couchbase/couchbase-lite-net/blob/master/src/LiteCore/src/LiteCore.Shared/Interop/raw_literals.txt Writes a byte array to a C4WriteStream. This function is essential for sending data through a stream. ```APIDOC ## c4stream_write ### Description Writes a byte array to a C4WriteStream. ### Signature `[return: MarshalAs(UnmanagedType.U1)] public static extern bool c4stream_write(C4WriteStream* stream, byte[] bytes, UIntPtr length, C4Error* outError);` ### Parameters * `stream` (C4WriteStream*) - A pointer to the C4WriteStream to write to. * `bytes` (byte[]) - The byte array containing the data to write. * `length` (UIntPtr) - The number of bytes to write from the array. * `outError` (C4Error*) - A pointer to a C4Error structure to store any error information. ### Returns `bool` - True if the write operation was successful, false otherwise. ``` -------------------------------- ### Read from C4ReadStream Source: https://github.com/couchbase/couchbase-lite-net/blob/master/src/LiteCore/src/LiteCore.Shared/Interop/bridge_literals.txt Reads data from a C4ReadStream into a byte buffer. Ensure the buffer is large enough to hold the requested count. ```csharp public static ulong c4stream_read(C4ReadStream *stream, byte[] buffer, int count, C4Error *outError) { return NativeRaw.c4stream_read(stream, buffer, (UIntPtr)count, outError).ToUInt64(); } ``` -------------------------------- ### FLDict_GetWithKeys Source: https://github.com/couchbase/couchbase-lite-net/blob/master/src/LiteCore/src/LiteCore.Shared/Interop/raw_literals.txt Retrieves values from an FLDict based on a provided array of keys. This is useful for accessing multiple specific fields within a dictionary. ```APIDOC ## FLDict_GetWithKeys ### Description Retrieves values from an FLDict based on a provided array of keys. ### Signature `public static extern UIntPtr FLDict_GetWithKeys(FLDict* dict, [Out]FLDictKey[] keys, [Out]FLValue[] values, UIntPtr count);` ### Parameters * `dict` (FLDict*) - A pointer to the FLDict to retrieve values from. * `keys` ([Out]FLDictKey[]) - An array of FLDictKey objects representing the keys to look for. * `values` ([Out]FLValue[]) - An array to store the FLValue objects corresponding to the keys. * `count` (UIntPtr) - The number of keys and values to process. ### Returns `UIntPtr` - The number of key-value pairs successfully retrieved. ``` -------------------------------- ### c4stream_write Source: https://github.com/couchbase/couchbase-lite-net/blob/master/src/LiteCore/src/LiteCore.Shared/Interop/bridge_literals.txt Writes data from a byte array to a C4WriteStream. This function is used for sending data through a stream. ```APIDOC ## c4stream_write ### Description Writes data from a byte array to a C4WriteStream. ### Signature public static bool c4stream_write(C4WriteStream* stream, byte[] bytes, ulong length, C4Error* outError) ### Parameters - **stream** (C4WriteStream*): The write stream to write to. - **bytes** (byte[]): The byte array containing the data to write. - **length** (ulong): The number of bytes to write. - **outError** (C4Error*): Pointer to a C4Error structure to store any error information. ### Returns (bool): True if the write operation was successful, false otherwise. ``` -------------------------------- ### c4stream_read Source: https://github.com/couchbase/couchbase-lite-net/blob/master/src/LiteCore/src/LiteCore.Shared/Interop/bridge_literals.txt Reads data from a C4ReadStream into a buffer. This is a low-level function for stream data retrieval. ```APIDOC ## c4stream_read ### Description Reads data from a C4ReadStream into a buffer. ### Signature public static ulong c4stream_read(C4ReadStream *stream, byte[] buffer, int count, C4Error *outError) ### Parameters - **stream** (C4ReadStream *): The read stream to read from. - **buffer** (byte[]): The buffer to store the read data. - **count** (int): The maximum number of bytes to read. - **outError** (C4Error *): Pointer to a C4Error structure to store any error information. ### Returns (ulong): The number of bytes read. ``` -------------------------------- ### FLJSON5_ToJSON Source: https://github.com/couchbase/couchbase-lite-net/blob/master/src/LiteCore/src/LiteCore.Shared/Interop/bridge_literals.txt Converts a JSON5 string to a JSON string. Handles potential errors during conversion. ```APIDOC ## FLJSON5_ToJSON ### Description Converts a JSON5 formatted string to a standard JSON string. ### Signature public static string? FLJSON5_ToJSON(string json5, FLSlice* outErrorMessage, UIntPtr* outErrPos, FLError* err) ### Parameters - **json5** (string): The JSON5 string to convert. - **outErrorMessage** (FLSlice*): Pointer to store an error message if conversion fails. - **outErrPos** (UIntPtr*): Pointer to store the position of the error in the input string. - **err** (FLError*): Pointer to store the error code. ### Returns (string?): The converted JSON string, or null if an error occurred. ``` -------------------------------- ### c4stream_read Source: https://github.com/couchbase/couchbase-lite-net/blob/master/src/LiteCore/src/LiteCore.Shared/Interop/raw_literals.txt Reads data from a C4ReadStream into a byte buffer. This function is used for retrieving data chunks from a stream. ```APIDOC ## c4stream_read ### Description Reads data from a C4ReadStream into a byte buffer. ### Signature `public static extern UIntPtr c4stream_read(C4ReadStream* stream, [Out]byte[] buffer, UIntPtr maxBytesToRead, C4Error* outError);` ### Parameters * `stream` (C4ReadStream*) - A pointer to the C4ReadStream to read from. * `buffer` ([Out]byte[]) - The byte array to store the read data. * `maxBytesToRead` (UIntPtr) - The maximum number of bytes to read. * `outError` (C4Error*) - A pointer to a C4Error structure to store any error information. ### Returns `UIntPtr` - The number of bytes actually read from the stream. ``` -------------------------------- ### FLEncoder_GetErrorMessage Source: https://github.com/couchbase/couchbase-lite-net/blob/master/src/LiteCore/src/LiteCore.Shared/Interop/raw_literals.txt Retrieves the error message from an FLEncoder. This function is used for debugging and understanding encoding failures. ```APIDOC ## FLEncoder_GetErrorMessage ### Description Retrieves the error message from an FLEncoder. ### Signature `[return: MarshalAs(UnmanagedType.LPStr)] public static extern string FLEncoder_GetErrorMessage(FLEncoder* encoder);` ### Parameters * `encoder` (FLEncoder*) - A pointer to the FLEncoder instance. ### Returns `string` - The error message associated with the encoder. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.