Exemplo n.º 1
0
        public override Task <CosmosResponseMessage> DeleteConflictAsync(
            PartitionKey partitionKey,
            CosmosConflictSettings conflict,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (partitionKey == null)
            {
                throw new ArgumentNullException(nameof(partitionKey));
            }

            if (conflict == null)
            {
                throw new ArgumentNullException(nameof(conflict));
            }

            Uri conflictLink = this.clientContext.CreateLink(
                parentLink: this.container.LinkUri.OriginalString,
                uriPathSegment: Paths.ConflictsPathSegment,
                id: conflict.Id);

            return(this.clientContext.ProcessResourceOperationStreamAsync(
                       resourceUri: conflictLink,
                       resourceType: ResourceType.Conflict,
                       operationType: OperationType.Delete,
                       requestOptions: null,
                       cosmosContainerCore: this.container,
                       partitionKey: partitionKey,
                       streamPayload: null,
                       requestEnricher: null,
                       cancellationToken: cancellationToken));
        }
Exemplo n.º 2
0
        public override async Task <ItemResponse <T> > ReadCurrentAsync <T>(
            PartitionKey partitionKey,
            CosmosConflictSettings cosmosConflict,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (partitionKey == null)
            {
                throw new ArgumentNullException(nameof(partitionKey));
            }

            if (cosmosConflict == null)
            {
                throw new ArgumentNullException(nameof(cosmosConflict));
            }

            // SourceResourceId is RID based on Conflicts, so we need to obtain the db and container rid
            CosmosDatabaseCore databaseCore       = (CosmosDatabaseCore)this.container.Database;
            string             databaseResourceId = await databaseCore.GetRIDAsync(cancellationToken);

            string containerResourceId = await this.container.GetRIDAsync(cancellationToken);

            Uri dbLink = this.clientContext.CreateLink(
                parentLink: string.Empty,
                uriPathSegment: Paths.DatabasesPathSegment,
                id: databaseResourceId);

            Uri containerLink = this.clientContext.CreateLink(
                parentLink: dbLink.OriginalString,
                uriPathSegment: Paths.CollectionsPathSegment,
                id: containerResourceId);

            Uri itemLink = this.clientContext.CreateLink(
                parentLink: containerLink.OriginalString,
                uriPathSegment: Paths.DocumentsPathSegment,
                id: cosmosConflict.SourceResourceId);

            Task <CosmosResponseMessage> response = this.clientContext.ProcessResourceOperationStreamAsync(
                resourceUri: itemLink,
                resourceType: ResourceType.Document,
                operationType: OperationType.Read,
                requestOptions: null,
                cosmosContainerCore: this.container,
                partitionKey: partitionKey,
                streamPayload: null,
                requestEnricher: null,
                cancellationToken: cancellationToken);

            return(await this.clientContext.ResponseFactory.CreateItemResponseAsync <T>(response));
        }
Exemplo n.º 3
0
        public override T ReadConflictContent <T>(CosmosConflictSettings cosmosConflict)
        {
            if (cosmosConflict == null)
            {
                throw new ArgumentNullException(nameof(cosmosConflict));
            }

            // cosmosConflict.Content is string and converted to stream on demand for de-serialization
            if (!string.IsNullOrEmpty(cosmosConflict.Content))
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    using (StreamWriter writer = new StreamWriter(stream))
                    {
                        writer.Write(cosmosConflict.Content);
                        writer.Flush();
                        stream.Position = 0;
                        return(this.clientContext.CosmosSerializer.FromStream <T>(stream));
                    }
                }
            }

            return(default(T));
        }
 /// <summary>
 /// Reads the content of the Conflict resource in the Azure Cosmos DB service.
 /// </summary>
 /// <param name="cosmosConflict">The conflict for which we want to read the content of.</param>
 /// <returns>The content of the conflict.</returns>
 /// <seealso cref="CosmosConflictSettings"/>
 /// <example>
 /// <code language="c#">
 /// <![CDATA[
 /// FeedIterator<CosmosConflictSettings> conflictIterator = await cosmosContainer.Conflicts.GetConflictsIterator();
 /// while (conflictIterator.HasMoreResults)
 /// {
 ///     foreach(CosmosConflictSettings item in await conflictIterator.FetchNextSetAsync())
 ///     {
 ///         MyClass intendedChanges = cosmosContainer.Conflicts.ReadConflictContent<MyClass>(item);
 ///         ItemResponse<MyClass> currentState = await cosmosContainer.Conflicts.ReadCurrentAsync<MyClass>(intendedChanges.MyPartitionKey, item);
 ///     }
 /// }
 /// ]]>
 /// </code>
 /// </example>
 public abstract T ReadConflictContent <T>(CosmosConflictSettings cosmosConflict);
 /// <summary>
 /// Reads the item that originated the conflict.
 /// </summary>
 /// <param name="partitionKey">The partition key for the item.</param>
 /// <param name="cosmosConflict">The conflict for which we want to read the item.</param>
 /// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param>
 /// <returns>The current state of the item associated with the conflict.</returns>
 /// <seealso cref="CosmosConflictSettings"/>
 /// <example>
 /// <code language="c#">
 /// <![CDATA[
 /// FeedIterator<CosmosConflictSettings> conflictIterator = await cosmosContainer.Conflicts.GetConflictsIterator();
 /// while (conflictIterator.HasMoreResults)
 /// {
 ///     foreach(CosmosConflictSettings item in await conflictIterator.FetchNextSetAsync())
 ///     {
 ///         MyClass intendedChanges = cosmosContainer.Conflicts.ReadConflictContent<MyClass>(item);
 ///         ItemResponse<MyClass> currentState = await cosmosContainer.Conflicts.ReadCurrentAsync<MyClass>(intendedChanges.MyPartitionKey, item);
 ///     }
 /// }
 /// ]]>
 /// </code>
 /// </example>
 public abstract Task <ItemResponse <T> > ReadCurrentAsync <T>(
     object partitionKey,
     CosmosConflictSettings cosmosConflict,
     CancellationToken cancellationToken = default(CancellationToken));
 /// <summary>
 /// Delete a conflict from the Azure Cosmos service as an asynchronous operation.
 /// </summary>
 /// <param name="partitionKey">The partition key for the conflict.</param>
 /// <param name="conflict">The conflict to delete.</param>
 /// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param>
 /// <returns>A Task representing the asynchronous operation.</returns>
 /// <seealso cref="CosmosConflictSettings"/>
 public abstract Task <CosmosResponseMessage> DeleteConflictAsync(
     object partitionKey,
     CosmosConflictSettings conflict,
     CancellationToken cancellationToken = default(CancellationToken));