コード例 #1
0
        public Task <ResponseMessage> DeleteAsync(
            CosmosDiagnosticsContext diagnosticsContext,
            ConflictProperties conflict,
            PartitionKey partitionKey,
            ITrace trace,
            CancellationToken cancellationToken = default)
        {
            if (conflict == null)
            {
                throw new ArgumentNullException(nameof(conflict));
            }

            string conflictLink = this.ClientContext.CreateLink(
                parentLink: this.container.LinkUri,
                uriPathSegment: Paths.ConflictsPathSegment,
                id: conflict.Id);

            return(this.ClientContext.ProcessResourceOperationStreamAsync(
                       resourceUri: conflictLink,
                       resourceType: ResourceType.Conflict,
                       operationType: OperationType.Delete,
                       requestOptions: null,
                       cosmosContainerCore: this.container,
                       feedRange: new FeedRangePartitionKey(partitionKey),
                       streamPayload: null,
                       requestEnricher: null,
                       diagnosticsContext: diagnosticsContext,
                       trace: trace,
                       cancellationToken: cancellationToken));
        }
コード例 #2
0
        public override Task <ResponseMessage> DeleteAsync(
            ConflictProperties conflict,
            PartitionKey partitionKey,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            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));
        }
コード例 #3
0
 public override Task <ItemResponse <T> > ReadCurrentAsync <T>(
     ConflictProperties cosmosConflict,
     PartitionKey partitionKey,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(TaskHelper.RunInlineIfNeededAsync(() => this.conflicts.ReadCurrentAsync <T>(cosmosConflict, partitionKey, cancellationToken)));
 }
コード例 #4
0
 public override Task <ResponseMessage> DeleteAsync(
     ConflictProperties conflict,
     PartitionKey partitionKey,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(TaskHelper.RunInlineIfNeededAsync(() => this.conflicts.DeleteAsync(conflict, partitionKey, cancellationToken)));
 }
コード例 #5
0
 public override Task <ItemResponse <T> > ReadCurrentAsync <T>(
     ConflictProperties cosmosConflict,
     PartitionKey partitionKey,
     CancellationToken cancellationToken = default)
 {
     return(this.ClientContext.OperationHelperAsync(
                operationName: nameof(ReadCurrentAsync),
                requestOptions: null,
                task: (trace) => base.ReadCurrentAsync <T>(cosmosConflict, partitionKey, trace, cancellationToken)));
 }
コード例 #6
0
 public override Task <ResponseMessage> DeleteAsync(
     ConflictProperties conflict,
     PartitionKey partitionKey,
     CancellationToken cancellationToken = default)
 {
     return(this.ClientContext.OperationHelperAsync(
                operationName: nameof(DeleteAsync),
                requestOptions: null,
                task: (trace) => base.DeleteAsync(conflict, partitionKey, trace, cancellationToken)));
 }
コード例 #7
0
        public async Task <ItemResponse <T> > ReadCurrentAsync <T>(
            ConflictProperties cosmosConflict,
            PartitionKey partitionKey,
            ITrace trace,
            CancellationToken cancellationToken = default)
        {
            if (cosmosConflict == null)
            {
                throw new ArgumentNullException(nameof(cosmosConflict));
            }

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

            string containerResourceId = await this.container.GetCachedRIDAsync(
                forceRefresh : false,
                trace,
                cancellationToken : cancellationToken);

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

            string containerLink = this.ClientContext.CreateLink(
                parentLink: dbLink,
                uriPathSegment: Paths.CollectionsPathSegment,
                id: containerResourceId);

            string itemLink = this.ClientContext.CreateLink(
                parentLink: containerLink,
                uriPathSegment: Paths.DocumentsPathSegment,
                id: cosmosConflict.SourceResourceId);

            ResponseMessage response = await this.ClientContext.ProcessResourceOperationStreamAsync(
                resourceUri : itemLink,
                resourceType : ResourceType.Document,
                operationType : OperationType.Read,
                requestOptions : null,
                cosmosContainerCore : this.container,
                feedRange : new FeedRangePartitionKey(partitionKey),
                streamPayload : null,
                requestEnricher : null,
                trace : trace,
                cancellationToken : cancellationToken);

            return(this.ClientContext.ResponseFactory.CreateItemResponse <T>(response));
        }
コード例 #8
0
        public override async Task <ItemResponse <T> > ReadCurrentAsync <T>(
            ConflictProperties cosmosConflict,
            PartitionKey partitionKey,
            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
            DatabaseCore databaseCore       = (DatabaseCore)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 <ResponseMessage> 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));
        }
コード例 #9
0
        public override T ReadConflictContent <T>(ConflictProperties 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.SerializerCore.FromStream <T>(stream));
                    }
                }
            }

            return(default);
コード例 #10
0
 /// <summary>
 /// Reads the content of the Conflict resource in the Azure Cosmos DB service.
 /// </summary>
 /// <param name="conflict">The conflict for which we want to read the content of.</param>
 /// <returns>The content of the conflict.</returns>
 /// <seealso cref="ConflictProperties"/>
 /// <example>
 /// <code language="c#">
 /// <![CDATA[
 /// FeedIterator<ConflictProperties> conflictIterator = await conflicts.GetConflictsIterator();
 /// while (conflictIterator.HasMoreResults)
 /// {
 ///     foreach(ConflictProperties item in await conflictIterator.FetchNextSetAsync())
 ///     {
 ///         MyClass intendedChanges = conflicts.ReadConflictContent<MyClass>(item);
 ///         ItemResponse<MyClass> currentState = await conflicts.ReadCurrentAsync<MyClass>(intendedChanges.MyPartitionKey, item);
 ///     }
 /// }
 /// ]]>
 /// </code>
 /// </example>
 public abstract T ReadConflictContent <T>(ConflictProperties conflict);
コード例 #11
0
 /// <summary>
 /// Reads the item that originated the conflict.
 /// </summary>
 /// <param name="partitionKey">The partition key for the item.</param>
 /// <param name="conflict">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="ConflictProperties"/>
 /// <example>
 /// <code language="c#">
 /// <![CDATA[
 /// FeedIterator<ConflictProperties> conflictIterator = await conflicts.GetConflictsIterator();
 /// while (conflictIterator.HasMoreResults)
 /// {
 ///     foreach(ConflictProperties item in await conflictIterator.FetchNextSetAsync())
 ///     {
 ///         MyClass intendedChanges = conflicts.ReadConflictContent<MyClass>(item);
 ///         ItemResponse<MyClass> currentState = await conflicts.ReadCurrentAsync<MyClass>(intendedChanges.MyPartitionKey, item);
 ///     }
 /// }
 /// ]]>
 /// </code>
 /// </example>
 public abstract Task <ItemResponse <T> > ReadCurrentAsync <T>(
     PartitionKey partitionKey,
     ConflictProperties conflict,
     CancellationToken cancellationToken = default(CancellationToken));
コード例 #12
0
 /// <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="ConflictProperties"/>
 public abstract Task <ResponseMessage> DeleteConflictAsync(
     PartitionKey partitionKey,
     ConflictProperties conflict,
     CancellationToken cancellationToken = default(CancellationToken));
コード例 #13
0
 public override T ReadConflictContent <T>(ConflictProperties cosmosConflict)
 {
     return(base.ReadConflictContent <T>(cosmosConflict));
 }