editorcofig: Adds editorcofig rules for all the VS defaults (#1827)

* Update editorconfig rules

* Applied changes

* Fix internal build caused by missing using statement

* Update tests
This commit is contained in:
j82w 2020-09-18 11:53:35 -07:00 коммит произвёл GitHub
Родитель 3e5f0bcec4
Коммит 40ceaffa84
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
274 изменённых файлов: 3150 добавлений и 1770 удалений

Просмотреть файл

@ -1,66 +1,207 @@
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
###############################
# Core EditorConfig Options #
###############################
root = true
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true
# All files
[*]
indent_style = space
# C# files
[*.cs]
# Code files
[*.cs]
#### Core EditorConfig Options ####
# Indentation and spacing
indent_size = 4
indent_style = space
tab_width = 4
trim_trailing_whitespace = true
###############################
# .NET Coding Conventions #
###############################
[*.cs]
# Organize usings
# New line preferences
end_of_line = crlf
insert_final_newline = false
#### .NET Coding Conventions ####
# Organize usings
dotnet_separate_import_directive_groups = false
dotnet_sort_system_directives_first = true
file_header_template = unset
# this. preferences
dotnet_style_qualification_for_field = true:error
dotnet_style_qualification_for_property = true:error
dotnet_style_qualification_for_method = true:error
# this. and Me. preferences
dotnet_style_qualification_for_event = true:error
dotnet_style_qualification_for_field = true:error
dotnet_style_qualification_for_method = true:error
dotnet_style_qualification_for_property = true:error
# New line preferences
csharp_new_line_before_open_brace = all
# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
# Indentation preferences
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = flush_left
# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:error
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:error
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:error
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:error
# Space preferences
csharp_space_after_keywords_in_control_flow_statements = true
# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:error
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:error
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:error
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:error
# Expression-level preferences
dotnet_style_coalesce_expression = true:error
dotnet_style_collection_initializer = true:error
dotnet_style_explicit_tuple_names = true:error
dotnet_style_null_propagation = true:error
dotnet_style_object_initializer = true:error
dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_prefer_auto_properties = true:error
dotnet_style_prefer_compound_assignment = true:error
dotnet_style_prefer_conditional_expression_over_assignment = true:error
dotnet_style_prefer_conditional_expression_over_return = false:silent
dotnet_style_prefer_inferred_anonymous_type_member_names = true:error
dotnet_style_prefer_inferred_tuple_names = true:error
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:error
dotnet_style_prefer_simplified_boolean_expressions = true:error
dotnet_style_prefer_simplified_interpolation = true:error
# Expression-level preferences
dotnet_style_prefer_auto_properties = true:error
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:error
# Field preferences
dotnet_style_readonly_field = true:error
# CSharp code style settings:
# Parameter preferences
dotnet_code_quality_unused_parameters = all:error
#### C# Coding Conventions ####
# var preferences
csharp_style_var_elsewhere = false:error
csharp_style_var_for_built_in_types = false:error
csharp_style_var_when_type_is_apparent = false:error
csharp_style_var_elsewhere = false:error
# Patern matching
csharp_style_pattern_matching_over_is_with_cast_check = true:error
# Expression-bodied members
csharp_style_expression_bodied_accessors = true:error
csharp_style_expression_bodied_constructors = false:error
csharp_style_expression_bodied_indexers = true:error
csharp_style_expression_bodied_lambdas = true:error
csharp_style_expression_bodied_local_functions = false:error
csharp_style_expression_bodied_methods = false:error
csharp_style_expression_bodied_operators = false:error
csharp_style_expression_bodied_properties = true:error
# Pattern matching preferences
csharp_style_pattern_matching_over_as_with_null_check = true:error
csharp_style_pattern_matching_over_is_with_cast_check = true:error
csharp_style_prefer_switch_expression = true:error
# Null-checking preferences
csharp_style_conditional_delegate_call = true:error
# Modifier preferences
csharp_prefer_static_local_function = true:error
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent
# Code-block preferences
csharp_prefer_braces = true:silent
csharp_prefer_simple_using_statement = true:silent
# Expression-level preferences
csharp_prefer_simple_default_expression = true:error
csharp_style_deconstructed_variable_declaration = true:error
csharp_style_inlined_variable_declaration = true:error
csharp_style_pattern_local_over_anonymous_function = true:error
csharp_style_prefer_index_operator = true:error
csharp_style_prefer_range_operator = true:error
csharp_style_throw_expression = true:error
csharp_style_unused_value_assignment_preference = discard_variable:error
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
# 'using' directive preferences
csharp_using_directive_placement = inside_namespace :error
#### C# Formatting Rules ####
# New line preferences
csharp_new_line_before_catch = true
csharp_new_line_before_else = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = all
csharp_new_line_between_query_expression_clauses = true
# Indentation preferences
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = true
csharp_indent_labels = one_less_than_current
csharp_indent_switch_labels = true
# Space preferences
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false
# Wrapping preferences
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
#### Naming styles ####
# Naming rules
dotnet_naming_rule.interface_should_be_begins_with_i.severity = error
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
dotnet_naming_rule.types_should_be_pascal_case.severity = error
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = error
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
# Symbol specifications
dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =
# Naming styles
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case
## Naming Conventions
# Async methods should have [Async] suffix
[*.cs]
dotnet_naming_rule.async_method_must_end_with_async.symbols = async_methods
dotnet_naming_symbols.async_methods.applicable_kinds = method
dotnet_naming_symbols.async_methods.applicable_accessibilities = *

Просмотреть файл

@ -11,7 +11,7 @@ namespace Microsoft.Azure.Cosmos.Encryption
/// </summary>
public sealed class AzureKeyVaultKeyWrapMetadata : EncryptionKeyWrapMetadata
{
internal static string TypeConstant = "akv";
internal const string TypeConstant = "akv";
/// <summary>
/// Creates a new instance of metadata that the Azure Key Vault can use to wrap and unwrap keys.

Просмотреть файл

@ -80,7 +80,7 @@ namespace Microsoft.Azure.Cosmos.Encryption
if (!KeyVaultKeyUriProperties.TryParse(new Uri(metadata.Value), out KeyVaultKeyUriProperties keyVaultUriProperties))
{
throw new ArgumentException("KeyVault Key Uri {0} is invalid.",metadata.Value);
throw new ArgumentException("KeyVault Key Uri {0} is invalid.", metadata.Value);
}
if (!await this.keyVaultAccessClient.ValidatePurgeProtectionAndSoftDeleteSettingsAsync(keyVaultUriProperties, cancellationToken))

Просмотреть файл

@ -8,7 +8,7 @@ namespace Microsoft.Azure.Cosmos.Encryption
internal class KeyVaultAccessException : RequestFailedException
{
public KeyVaultAccessException(int statusCode, string keyVaultErrorCode, string? errorMessage, Exception? innerException)
public KeyVaultAccessException(int statusCode, string keyVaultErrorCode, string errorMessage, Exception innerException)
: base(statusCode, keyVaultErrorCode, errorMessage, innerException)
{
}

Просмотреть файл

@ -56,27 +56,12 @@ namespace Microsoft.Azure.Cosmos
throw new ArgumentOutOfRangeException(nameof(maxBatchByteSize));
}
if (executor == null)
{
throw new ArgumentNullException(nameof(executor));
}
if (retrier == null)
{
throw new ArgumentNullException(nameof(retrier));
}
if (serializerCore == null)
{
throw new ArgumentNullException(nameof(serializerCore));
}
this.batchOperations = new List<ItemBatchOperation>(maxBatchOperationCount);
this.executor = executor;
this.retrier = retrier;
this.executor = executor ?? throw new ArgumentNullException(nameof(executor));
this.retrier = retrier ?? throw new ArgumentNullException(nameof(retrier));
this.maxBatchByteSize = maxBatchByteSize;
this.maxBatchOperationCount = maxBatchOperationCount;
this.serializerCore = serializerCore;
this.serializerCore = serializerCore ?? throw new ArgumentNullException(nameof(serializerCore));
}
public virtual bool TryAdd(ItemBatchOperation operation)
@ -122,7 +107,7 @@ namespace Microsoft.Azure.Cosmos
public virtual async Task DispatchAsync(
BatchPartitionMetric partitionMetric,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
this.interlockIncrementCheck.EnterLockCheck();
@ -183,7 +168,7 @@ namespace Microsoft.Azure.Cosmos
{
response.DiagnosticsContext = batchResponse.DiagnosticsContext;
}
if (!response.IsSuccessStatusCode)
{
Documents.ShouldRetryResult shouldRetry = await itemBatchOperation.Context.ShouldRetryAsync(response, cancellationToken);

Просмотреть файл

@ -27,7 +27,7 @@ namespace Microsoft.Azure.Cosmos
{
private const int DefaultDispatchTimerInSeconds = 1;
private const int TimerWheelBucketCount = 20;
private readonly static TimeSpan TimerWheelResolution = TimeSpan.FromMilliseconds(50);
private static readonly TimeSpan TimerWheelResolution = TimeSpan.FromMilliseconds(50);
private readonly ContainerInternal cosmosContainer;
private readonly CosmosClientContext cosmosClientContext;
@ -78,7 +78,7 @@ namespace Microsoft.Azure.Cosmos
public virtual async Task<TransactionalBatchOperationResult> AddAsync(
ItemBatchOperation operation,
ItemRequestOptions itemRequestOptions = null,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (operation == null)
{
@ -113,7 +113,7 @@ namespace Microsoft.Azure.Cosmos
internal virtual async Task ValidateOperationAsync(
ItemBatchOperation operation,
ItemRequestOptions itemRequestOptions = null,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (itemRequestOptions != null)
{

Просмотреть файл

@ -16,7 +16,7 @@ namespace Microsoft.Azure.Cosmos
{
// Keeping same performance tuned value of Bulk V2.
internal const int DefaultMaxBulkRequestBodySizeInBytes = 220201;
private ConcurrentDictionary<string, BatchAsyncContainerExecutor> executorsPerContainer = new ConcurrentDictionary<string, BatchAsyncContainerExecutor>();
private readonly ConcurrentDictionary<string, BatchAsyncContainerExecutor> executorsPerContainer = new ConcurrentDictionary<string, BatchAsyncContainerExecutor>();
public BatchAsyncContainerExecutor GetExecutorForContainer(
ContainerInternal container,

Просмотреть файл

@ -34,6 +34,9 @@ namespace Microsoft.Azure.Cosmos
private readonly int congestionDecreaseFactor = 5;
private readonly int maxDegreeOfConcurrency;
private readonly TimerWheel timerWheel;
private readonly SemaphoreSlim limiter;
private readonly BatchPartitionMetric oldPartitionMetric;
private readonly BatchPartitionMetric partitionMetric;
private volatile BatchAsyncBatcher currentBatcher;
private TimerWheelTimer currentTimer;
@ -41,12 +44,9 @@ namespace Microsoft.Azure.Cosmos
private TimerWheelTimer congestionControlTimer;
private Task congestionControlTask;
private SemaphoreSlim limiter;
private int congestionDegreeOfConcurrency = 1;
private long congestionWaitTimeInMilliseconds = 1000;
private BatchPartitionMetric oldPartitionMetric;
private BatchPartitionMetric partitionMetric;
public BatchAsyncStreamer(
int maxBatchOperationCount,

Просмотреть файл

@ -201,7 +201,7 @@ namespace Microsoft.Azure.Cosmos
}
public override Task<TransactionalBatchResponse> ExecuteAsync(
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
return this.ExecuteAsync(
requestOptions: null,
@ -216,7 +216,7 @@ namespace Microsoft.Azure.Cosmos
/// <returns>An awaitable <see cref="TransactionalBatchResponse"/> which contains the completion status and results of each operation.</returns>
public override Task<TransactionalBatchResponse> ExecuteAsync(
TransactionalBatchRequestOptions requestOptions,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
return this.container.ClientContext.OperationHelperAsync(
nameof(ExecuteAsync),

Просмотреть файл

@ -6,7 +6,6 @@ namespace Microsoft.Azure.Cosmos
{
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
@ -92,10 +91,7 @@ namespace Microsoft.Azure.Cosmos
return this.body;
}
set
{
this.body = value;
}
set => this.body = value;
}
/// <summary>

Просмотреть файл

@ -23,7 +23,7 @@ namespace Microsoft.Azure.Cosmos
private readonly IDocumentClientRetryPolicy retryPolicy;
private TaskCompletionSource<TransactionalBatchOperationResult> taskCompletionSource = new TaskCompletionSource<TransactionalBatchOperationResult>();
private readonly TaskCompletionSource<TransactionalBatchOperationResult> taskCompletionSource = new TaskCompletionSource<TransactionalBatchOperationResult>();
public ItemBatchOperationContext(
string partitionKeyRangeId,

Просмотреть файл

@ -25,10 +25,13 @@ namespace Microsoft.Azure.Cosmos
this.Operations = operations;
}
internal bool IsSplit() => this.ServerResponse != null &&
this.ServerResponse.StatusCode == HttpStatusCode.Gone
&& (this.ServerResponse.SubStatusCode == Documents.SubStatusCodes.CompletingSplit
|| this.ServerResponse.SubStatusCode == Documents.SubStatusCodes.CompletingPartitionMigration
|| this.ServerResponse.SubStatusCode == Documents.SubStatusCodes.PartitionKeyRangeGone);
internal bool IsSplit()
{
return this.ServerResponse != null &&
this.ServerResponse.StatusCode == HttpStatusCode.Gone
&& (this.ServerResponse.SubStatusCode == Documents.SubStatusCodes.CompletingSplit
|| this.ServerResponse.SubStatusCode == Documents.SubStatusCodes.CompletingPartitionMigration
|| this.ServerResponse.SubStatusCode == Documents.SubStatusCodes.PartitionKeyRangeGone);
}
}
}

Просмотреть файл

@ -97,7 +97,7 @@ namespace Microsoft.Azure.Cosmos
TransactionalBatchOperationResult result = this.resultsByOperationIndex[index];
T resource = default(T);
T resource = default;
if (result.ResourceStream != null)
{
resource = this.SerializerCore.FromStream<T>(result.ResourceStream);

Просмотреть файл

@ -5,10 +5,8 @@
namespace Microsoft.Azure.Cosmos
{
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Documents;
internal sealed class PartitionKeyRangeServerBatchRequest : ServerBatchRequest
{

Просмотреть файл

@ -4,7 +4,6 @@
namespace Microsoft.Azure.Cosmos
{
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading;
@ -217,7 +216,7 @@ namespace Microsoft.Azure.Cosmos
/// <returns>The transactional batch instance with the operation added.</returns>
public abstract TransactionalBatch PatchItem(
string id,
IReadOnlyList<PatchOperation> patchOperations,
System.Collections.Generic.IReadOnlyList<PatchOperation> patchOperations,
TransactionalBatchItemRequestOptions requestOptions = null);
#endif
@ -249,7 +248,7 @@ namespace Microsoft.Azure.Cosmos
/// Use <see cref="TransactionalBatchResponse.IsSuccessStatusCode"/> on the response returned to ensure that the transactional batch succeeded.
/// </remarks>
public abstract Task<TransactionalBatchResponse> ExecuteAsync(
CancellationToken cancellationToken = default(CancellationToken));
CancellationToken cancellationToken = default);
/// <summary>
/// Executes the transactional batch at the Azure Cosmos service as an asynchronous operation.
@ -281,6 +280,6 @@ namespace Microsoft.Azure.Cosmos
/// </remarks>
public abstract Task<TransactionalBatchResponse> ExecuteAsync(
TransactionalBatchRequestOptions requestOptions,
CancellationToken cancellationToken = default(CancellationToken));
CancellationToken cancellationToken = default);
}
}

Просмотреть файл

@ -47,15 +47,17 @@ namespace Microsoft.Azure.Cosmos
return null;
}
RequestOptions requestOptions = itemRequestOptions as RequestOptions;
TransactionalBatchItemRequestOptions batchItemRequestOptions = new TransactionalBatchItemRequestOptions();
batchItemRequestOptions.IndexingDirective = itemRequestOptions.IndexingDirective;
batchItemRequestOptions.IfMatchEtag = itemRequestOptions.IfMatchEtag;
batchItemRequestOptions.IfNoneMatchEtag = itemRequestOptions.IfNoneMatchEtag;
batchItemRequestOptions.Properties = itemRequestOptions.Properties;
batchItemRequestOptions.EnableContentResponseOnWrite = itemRequestOptions.EnableContentResponseOnWrite;
batchItemRequestOptions.EnableContentResponseOnRead = itemRequestOptions.EnableContentResponseOnRead;
batchItemRequestOptions.IsEffectivePartitionKeyRouting = itemRequestOptions.IsEffectivePartitionKeyRouting;
RequestOptions requestOptions = itemRequestOptions;
TransactionalBatchItemRequestOptions batchItemRequestOptions = new TransactionalBatchItemRequestOptions
{
IndexingDirective = itemRequestOptions.IndexingDirective,
IfMatchEtag = itemRequestOptions.IfMatchEtag,
IfNoneMatchEtag = itemRequestOptions.IfNoneMatchEtag,
Properties = itemRequestOptions.Properties,
EnableContentResponseOnWrite = itemRequestOptions.EnableContentResponseOnWrite,
EnableContentResponseOnRead = itemRequestOptions.EnableContentResponseOnRead,
IsEffectivePartitionKeyRouting = itemRequestOptions.IsEffectivePartitionKeyRouting
};
return batchItemRequestOptions;
}
}

Просмотреть файл

@ -208,7 +208,7 @@ namespace Microsoft.Azure.Cosmos
RetryAfter = this.RetryAfter,
RequestCharge = this.RequestCharge,
};
ResponseMessage responseMessage = new ResponseMessage(
statusCode: this.StatusCode,
requestMessage: null,

Просмотреть файл

@ -148,13 +148,7 @@ namespace Microsoft.Azure.Cosmos
/// </summary>
/// <param name="index">0-based index of the operation in the batch whose result needs to be returned.</param>
/// <returns>Result of operation at the provided index in the batch.</returns>
public virtual TransactionalBatchOperationResult this[int index]
{
get
{
return this.results[index];
}
}
public virtual TransactionalBatchOperationResult this[int index] => this.results[index];
/// <summary>
/// Gets the result of the operation at the provided index in the batch - the returned result has a Resource of provided type.
@ -166,7 +160,7 @@ namespace Microsoft.Azure.Cosmos
{
TransactionalBatchOperationResult result = this.results[index];
T resource = default(T);
T resource = default;
if (result.ResourceStream != null)
{
resource = this.SerializerCore.FromStream<T>(result.ResourceStream);
@ -378,9 +372,10 @@ namespace Microsoft.Azure.Cosmos
responseMessage.Headers,
responseMessage.DiagnosticsContext,
serverRequest.Operations,
serializer);
response.results = results;
serializer)
{
results = results
};
return response;
}

Просмотреть файл

@ -120,7 +120,10 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
}
}
public override CosmosElement GetCosmosElementContinuationToken() => CosmosElement.Parse(this.FeedRangeContinuation.ToString());
public override CosmosElement GetCosmosElementContinuationToken()
{
return CosmosElement.Parse(this.FeedRangeContinuation.ToString());
}
private async Task<ResponseMessage> ReadNextInternalAsync(
CosmosDiagnosticsContext diagnosticsScope,

Просмотреть файл

@ -5,7 +5,6 @@
namespace Microsoft.Azure.Cosmos.ChangeFeed
{
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.CosmosElements;
@ -35,14 +34,17 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
public override bool HasMoreResults => this.hasMoreResultsInternal;
public override CosmosElement GetCosmosElementContinuationToken() => throw new NotImplementedException();
public override CosmosElement GetCosmosElementContinuationToken()
{
throw new NotImplementedException();
}
/// <summary>
/// Get the next set of results from the cosmos service
/// </summary>
/// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param>
/// <returns>A change feed response from cosmos service</returns>
public override async Task<ResponseMessage> ReadNextAsync(CancellationToken cancellationToken = default(CancellationToken))
public override async Task<ResponseMessage> ReadNextAsync(CancellationToken cancellationToken = default)
{
ResponseMessage responseMessage = await this.clientContext.ProcessResourceOperationStreamAsync(
cosmosContainerCore: this.container,

Просмотреть файл

@ -14,15 +14,29 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
{
}
public override FeedRange Visit(ChangeFeedStartFromNow startFromNow) => startFromNow.FeedRange;
public override FeedRange Visit(ChangeFeedStartFromNow startFromNow)
{
return startFromNow.FeedRange;
}
public override FeedRange Visit(ChangeFeedStartFromTime startFromTime) => startFromTime.FeedRange;
public override FeedRange Visit(ChangeFeedStartFromTime startFromTime)
{
return startFromTime.FeedRange;
}
public override FeedRange Visit(ChangeFeedStartFromContinuation startFromContinuation)
=> throw new NotSupportedException($"{nameof(ChangeFeedStartFromContinuation)} does not have a feed range.");
{
throw new NotSupportedException($"{nameof(ChangeFeedStartFromContinuation)} does not have a feed range.");
}
public override FeedRange Visit(ChangeFeedStartFromBeginning startFromBeginning) => startFromBeginning.FeedRange;
public override FeedRange Visit(ChangeFeedStartFromBeginning startFromBeginning)
{
return startFromBeginning.FeedRange;
}
public override FeedRange Visit(ChangeFeedStartFromContinuationAndFeedRange startFromContinuationAndFeedRange) => startFromContinuationAndFeedRange.FeedRange;
public override FeedRange Visit(ChangeFeedStartFromContinuationAndFeedRange startFromContinuationAndFeedRange)
{
return startFromContinuationAndFeedRange.FeedRange;
}
}
}

Просмотреть файл

@ -34,7 +34,10 @@ namespace Microsoft.Azure.Cosmos
/// Creates a <see cref="ChangeFeedStartFrom"/> that tells the ChangeFeed operation to start reading changes from this moment onward.
/// </summary>
/// <returns>A <see cref="ChangeFeedStartFrom"/> that tells the ChangeFeed operation to start reading changes from this moment onward.</returns>
public static ChangeFeedStartFrom Now() => Now(FeedRangeEpk.FullRange);
public static ChangeFeedStartFrom Now()
{
return Now(FeedRangeEpk.FullRange);
}
/// <summary>
/// Creates a <see cref="ChangeFeedStartFrom"/> that tells the ChangeFeed operation to start reading changes from this moment onward.
@ -56,7 +59,10 @@ namespace Microsoft.Azure.Cosmos
/// </summary>
/// <param name="dateTimeUtc">The time (in UTC) to start reading from.</param>
/// <returns>A <see cref="ChangeFeedStartFrom"/> that tells the ChangeFeed operation to start reading changes from some point in time onward.</returns>
public static ChangeFeedStartFrom Time(DateTime dateTimeUtc) => Time(dateTimeUtc, FeedRangeEpk.FullRange);
public static ChangeFeedStartFrom Time(DateTime dateTimeUtc)
{
return Time(dateTimeUtc, FeedRangeEpk.FullRange);
}
/// <summary>
/// Creates a <see cref="ChangeFeedStartFrom"/> that tells the ChangeFeed operation to start reading changes from some point in time onward.
@ -79,13 +85,19 @@ namespace Microsoft.Azure.Cosmos
/// </summary>
/// <param name="continuationToken">The continuation to resume from.</param>
/// <returns>A <see cref="ChangeFeedStartFrom"/> that tells the ChangeFeed operation to start reading changes from a save point.</returns>
public static ChangeFeedStartFrom ContinuationToken(string continuationToken) => new ChangeFeedStartFromContinuation(continuationToken);
public static ChangeFeedStartFrom ContinuationToken(string continuationToken)
{
return new ChangeFeedStartFromContinuation(continuationToken);
}
/// <summary>
/// Creates a <see cref="ChangeFeedStartFrom"/> that tells the ChangeFeed operation to start from the beginning of time.
/// </summary>
/// <returns>A <see cref="ChangeFeedStartFrom"/> that tells the ChangeFeed operation to start reading changes from the beginning of time.</returns>
public static ChangeFeedStartFrom Beginning() => Beginning(FeedRangeEpk.FullRange);
public static ChangeFeedStartFrom Beginning()
{
return Beginning(FeedRangeEpk.FullRange);
}
/// <summary>
/// Creates a <see cref="ChangeFeedStartFrom"/> that tells the ChangeFeed operation to start from the beginning of time.

Просмотреть файл

@ -26,8 +26,14 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
/// </summary>
public FeedRangeInternal FeedRange { get; }
internal override void Accept(ChangeFeedStartFromVisitor visitor) => visitor.Visit(this);
internal override void Accept(ChangeFeedStartFromVisitor visitor)
{
visitor.Visit(this);
}
internal override TResult Accept<TResult>(ChangeFeedStartFromVisitor<TResult> visitor) => visitor.Visit(this);
internal override TResult Accept<TResult>(ChangeFeedStartFromVisitor<TResult> visitor)
{
return visitor.Visit(this);
}
}
}

Просмотреть файл

@ -32,8 +32,14 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
/// </summary>
public string Continuation { get; }
internal override void Accept(ChangeFeedStartFromVisitor visitor) => visitor.Visit(this);
internal override void Accept(ChangeFeedStartFromVisitor visitor)
{
visitor.Visit(this);
}
internal override TResult Accept<TResult>(ChangeFeedStartFromVisitor<TResult> visitor) => visitor.Visit(this);
internal override TResult Accept<TResult>(ChangeFeedStartFromVisitor<TResult> visitor)
{
return visitor.Visit(this);
}
}
}

Просмотреть файл

@ -21,8 +21,14 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
public FeedRangeInternal FeedRange { get; }
internal override void Accept(ChangeFeedStartFromVisitor visitor) => visitor.Visit(this);
internal override void Accept(ChangeFeedStartFromVisitor visitor)
{
visitor.Visit(this);
}
internal override TResult Accept<TResult>(ChangeFeedStartFromVisitor<TResult> visitor) => visitor.Visit(this);
internal override TResult Accept<TResult>(ChangeFeedStartFromVisitor<TResult> visitor)
{
return visitor.Visit(this);
}
}
}

Просмотреть файл

@ -26,8 +26,14 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
/// </summary>
public FeedRangeInternal FeedRange { get; }
internal override void Accept(ChangeFeedStartFromVisitor visitor) => visitor.Visit(this);
internal override void Accept(ChangeFeedStartFromVisitor visitor)
{
visitor.Visit(this);
}
internal override TResult Accept<TResult>(ChangeFeedStartFromVisitor<TResult> visitor) => visitor.Visit(this);
internal override TResult Accept<TResult>(ChangeFeedStartFromVisitor<TResult> visitor)
{
return visitor.Visit(this);
}
}
}

Просмотреть файл

@ -38,8 +38,14 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
/// </summary>
public FeedRangeInternal FeedRange { get; }
internal override void Accept(ChangeFeedStartFromVisitor visitor) => visitor.Visit(this);
internal override void Accept(ChangeFeedStartFromVisitor visitor)
{
visitor.Visit(this);
}
internal override TResult Accept<TResult>(ChangeFeedStartFromVisitor<TResult> visitor) => visitor.Visit(this);
internal override TResult Accept<TResult>(ChangeFeedStartFromVisitor<TResult> visitor)
{
return visitor.Visit(this);
}
}
}

Просмотреть файл

@ -44,10 +44,21 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
string minInclusive,
string maxExclusive)
{
if (string.IsNullOrWhiteSpace(containerRid)) throw new ArgumentNullException(nameof(containerRid));
if (string.IsNullOrWhiteSpace(containerRid))
{
throw new ArgumentNullException(nameof(containerRid));
}
// MinInclusive can be an empty string
if (minInclusive == null) throw new ArgumentNullException(nameof(minInclusive));
if (string.IsNullOrWhiteSpace(maxExclusive)) throw new ArgumentNullException(nameof(maxExclusive));
if (minInclusive == null)
{
throw new ArgumentNullException(nameof(minInclusive));
}
if (string.IsNullOrWhiteSpace(maxExclusive))
{
throw new ArgumentNullException(nameof(maxExclusive));
}
return StandByFeedContinuationToken.SerializeTokens(new CompositeContinuationToken[1] { StandByFeedContinuationToken.CreateCompositeContinuationTokenForRange(minInclusive, maxExclusive, null) });
}
@ -66,8 +77,15 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
string initialStandByFeedContinuationToken,
PartitionKeyRangeCacheDelegate pkRangeCacheDelegate)
{
if (string.IsNullOrWhiteSpace(containerRid)) throw new ArgumentNullException(nameof(containerRid));
if (pkRangeCacheDelegate == null) throw new ArgumentNullException(nameof(pkRangeCacheDelegate));
if (string.IsNullOrWhiteSpace(containerRid))
{
throw new ArgumentNullException(nameof(containerRid));
}
if (pkRangeCacheDelegate == null)
{
throw new ArgumentNullException(nameof(pkRangeCacheDelegate));
}
this.containerRid = containerRid;
this.pkRangeCacheDelegate = pkRangeCacheDelegate;
@ -118,7 +136,10 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
private void HandleSplit(IReadOnlyList<Documents.PartitionKeyRange> keyRanges)
{
if (keyRanges == null) throw new ArgumentNullException(nameof(keyRanges));
if (keyRanges == null)
{
throw new ArgumentNullException(nameof(keyRanges));
}
// Update current
Documents.PartitionKeyRange firstRange = keyRanges[0];

Просмотреть файл

@ -34,7 +34,10 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
ChangeFeedStartFrom changeFeedStartFrom,
ChangeFeedRequestOptions options)
{
if (container == null) throw new ArgumentNullException(nameof(container));
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}
this.clientContext = clientContext;
this.container = container;
@ -54,7 +57,7 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
/// </summary>
/// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param>
/// <returns>A query response from cosmos service</returns>
public override async Task<ResponseMessage> ReadNextAsync(CancellationToken cancellationToken = default(CancellationToken))
public override async Task<ResponseMessage> ReadNextAsync(CancellationToken cancellationToken = default)
{
string firstNotModifiedKeyRangeId = null;
string currentKeyRangeId;
@ -153,7 +156,7 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
/// </summary>
internal async Task<bool> ShouldRetryFailureAsync(
ResponseMessage response,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (response.IsSuccessStatusCode || response.StatusCode == HttpStatusCode.NotModified)
{

Просмотреть файл

@ -89,10 +89,7 @@ namespace Microsoft.Azure.Cosmos
/// </summary>
public DateTime? StartTime
{
get
{
return this.startTime;
}
get => this.startTime;
set
{

Просмотреть файл

@ -22,10 +22,25 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.Bootstrapping
public BootstrapperCore(PartitionSynchronizer synchronizer, DocumentServiceLeaseStore leaseStore, TimeSpan lockTime, TimeSpan sleepTime)
{
if (synchronizer == null) throw new ArgumentNullException(nameof(synchronizer));
if (leaseStore == null) throw new ArgumentNullException(nameof(leaseStore));
if (lockTime <= TimeSpan.Zero) throw new ArgumentException("should be positive", nameof(lockTime));
if (sleepTime <= TimeSpan.Zero) throw new ArgumentException("should be positive", nameof(sleepTime));
if (synchronizer == null)
{
throw new ArgumentNullException(nameof(synchronizer));
}
if (leaseStore == null)
{
throw new ArgumentNullException(nameof(leaseStore));
}
if (lockTime <= TimeSpan.Zero)
{
throw new ArgumentException("should be positive", nameof(lockTime));
}
if (sleepTime <= TimeSpan.Zero)
{
throw new ArgumentException("should be positive", nameof(sleepTime));
}
this.synchronizer = synchronizer;
this.leaseStore = leaseStore;
@ -38,7 +53,10 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.Bootstrapping
while (true)
{
bool initialized = await this.leaseStore.IsInitializedAsync().ConfigureAwait(false);
if (initialized) break;
if (initialized)
{
break;
}
bool isLockAcquired = await this.leaseStore.AcquireInitializationLockAsync(this.lockTime).ConfigureAwait(false);

Просмотреть файл

@ -37,8 +37,15 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
ChangesEstimationHandler initialEstimateDelegate,
TimeSpan? estimatorPeriod)
{
if (initialEstimateDelegate == null) throw new ArgumentNullException(nameof(initialEstimateDelegate));
if (estimatorPeriod.HasValue && estimatorPeriod.Value <= TimeSpan.Zero) throw new ArgumentOutOfRangeException(nameof(estimatorPeriod));
if (initialEstimateDelegate == null)
{
throw new ArgumentNullException(nameof(initialEstimateDelegate));
}
if (estimatorPeriod.HasValue && estimatorPeriod.Value <= TimeSpan.Zero)
{
throw new ArgumentOutOfRangeException(nameof(estimatorPeriod));
}
this.initialEstimateDelegate = initialEstimateDelegate;
this.estimatorPeriod = estimatorPeriod;
@ -62,8 +69,15 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
ChangeFeedProcessorOptions changeFeedProcessorOptions,
ContainerInternal monitoredContainer)
{
if (monitoredContainer == null) throw new ArgumentNullException(nameof(monitoredContainer));
if (leaseContainer == null && customDocumentServiceLeaseStoreManager == null) throw new ArgumentNullException(nameof(leaseContainer));
if (monitoredContainer == null)
{
throw new ArgumentNullException(nameof(monitoredContainer));
}
if (leaseContainer == null && customDocumentServiceLeaseStoreManager == null)
{
throw new ArgumentNullException(nameof(leaseContainer));
}
this.documentServiceLeaseStoreManager = customDocumentServiceLeaseStoreManager;
this.leaseContainer = leaseContainer;

Просмотреть файл

@ -46,8 +46,10 @@ namespace Microsoft.Azure.Cosmos
ChangeFeedProcessorOptions,
ContainerInternal> applyBuilderConfiguration)
{
this.changeFeedLeaseOptions = new ChangeFeedLeaseOptions();
this.changeFeedLeaseOptions.LeasePrefix = processorName;
this.changeFeedLeaseOptions = new ChangeFeedLeaseOptions
{
LeasePrefix = processorName
};
this.monitoredContainer = container;
this.changeFeedProcessor = changeFeedProcessor;
this.applyBuilderConfiguration = applyBuilderConfiguration;
@ -92,7 +94,10 @@ namespace Microsoft.Azure.Cosmos
/// <returns>The instance of <see cref="ChangeFeedProcessorBuilder"/> to use.</returns>
public ChangeFeedProcessorBuilder WithPollInterval(TimeSpan pollInterval)
{
if (pollInterval == null) throw new ArgumentNullException(nameof(pollInterval));
if (pollInterval == null)
{
throw new ArgumentNullException(nameof(pollInterval));
}
this.changeFeedProcessorOptions = this.changeFeedProcessorOptions ?? new ChangeFeedProcessorOptions();
this.changeFeedProcessorOptions.FeedPollDelay = pollInterval;
@ -130,7 +135,10 @@ namespace Microsoft.Azure.Cosmos
/// <returns>The instance of <see cref="ChangeFeedProcessorBuilder"/> to use.</returns>
public ChangeFeedProcessorBuilder WithStartTime(DateTime startTime)
{
if (startTime == null) throw new ArgumentNullException(nameof(startTime));
if (startTime == null)
{
throw new ArgumentNullException(nameof(startTime));
}
this.changeFeedProcessorOptions = this.changeFeedProcessorOptions ?? new ChangeFeedProcessorOptions();
this.changeFeedProcessorOptions.StartTime = startTime;
@ -144,7 +152,10 @@ namespace Microsoft.Azure.Cosmos
/// <returns>An instance of <see cref="ChangeFeedProcessorBuilder"/>.</returns>
public ChangeFeedProcessorBuilder WithMaxItems(int maxItemCount)
{
if (maxItemCount <= 0) throw new ArgumentOutOfRangeException(nameof(maxItemCount));
if (maxItemCount <= 0)
{
throw new ArgumentOutOfRangeException(nameof(maxItemCount));
}
this.changeFeedProcessorOptions = this.changeFeedProcessorOptions ?? new ChangeFeedProcessorOptions();
this.changeFeedProcessorOptions.MaxItemCount = maxItemCount;
@ -158,9 +169,20 @@ namespace Microsoft.Azure.Cosmos
/// <returns>The instance of <see cref="ChangeFeedProcessorBuilder"/> to use.</returns>
public ChangeFeedProcessorBuilder WithLeaseContainer(Container leaseContainer)
{
if (leaseContainer == null) throw new ArgumentNullException(nameof(leaseContainer));
if (this.leaseContainer != null) throw new InvalidOperationException("The builder already defined a lease container.");
if (this.LeaseStoreManager != null) throw new InvalidOperationException("The builder already defined an in-memory lease container instance.");
if (leaseContainer == null)
{
throw new ArgumentNullException(nameof(leaseContainer));
}
if (this.leaseContainer != null)
{
throw new InvalidOperationException("The builder already defined a lease container.");
}
if (this.LeaseStoreManager != null)
{
throw new InvalidOperationException("The builder already defined an in-memory lease container instance.");
}
this.leaseContainer = (ContainerInternal)leaseContainer;
return this;
@ -175,8 +197,15 @@ namespace Microsoft.Azure.Cosmos
/// <returns>The instance of <see cref="ChangeFeedProcessorBuilder"/> to use.</returns>
internal virtual ChangeFeedProcessorBuilder WithInMemoryLeaseContainer()
{
if (this.leaseContainer != null) throw new InvalidOperationException("The builder already defined a lease container.");
if (this.LeaseStoreManager != null) throw new InvalidOperationException("The builder already defined an in-memory lease container instance.");
if (this.leaseContainer != null)
{
throw new InvalidOperationException("The builder already defined a lease container.");
}
if (this.LeaseStoreManager != null)
{
throw new InvalidOperationException("The builder already defined an in-memory lease container instance.");
}
if (string.IsNullOrEmpty(this.InstanceName))
{
@ -204,7 +233,10 @@ namespace Microsoft.Azure.Cosmos
internal virtual ChangeFeedProcessorBuilder WithMonitoredContainerRid(string monitoredContainerRid)
{
if (monitoredContainerRid != null) throw new ArgumentNullException(nameof(monitoredContainerRid));
if (monitoredContainerRid != null)
{
throw new ArgumentNullException(nameof(monitoredContainerRid));
}
this.monitoredContainerRid = monitoredContainerRid;
return this;

Просмотреть файл

@ -30,7 +30,10 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
public ChangeFeedProcessorCore(ChangeFeedObserverFactory<T> observerFactory)
{
if (observerFactory == null) throw new ArgumentNullException(nameof(observerFactory));
if (observerFactory == null)
{
throw new ArgumentNullException(nameof(observerFactory));
}
this.observerFactory = observerFactory;
}
@ -44,9 +47,20 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
ChangeFeedProcessorOptions changeFeedProcessorOptions,
ContainerInternal monitoredContainer)
{
if (monitoredContainer == null) throw new ArgumentNullException(nameof(monitoredContainer));
if (customDocumentServiceLeaseStoreManager == null && leaseContainer == null) throw new ArgumentNullException(nameof(leaseContainer));
if (instanceName == null) throw new ArgumentNullException("InstanceName is required for the processor to initialize.");
if (monitoredContainer == null)
{
throw new ArgumentNullException(nameof(monitoredContainer));
}
if (customDocumentServiceLeaseStoreManager == null && leaseContainer == null)
{
throw new ArgumentNullException(nameof(leaseContainer));
}
if (instanceName == null)
{
throw new ArgumentNullException("InstanceName is required for the processor to initialize.");
}
this.documentServiceLeaseStoreManager = customDocumentServiceLeaseStoreManager;
this.leaseContainer = leaseContainer;
@ -109,7 +123,7 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed
}
RequestOptionsFactory requestOptionsFactory = isPartitioned && !isMigratedFixed ?
(RequestOptionsFactory)new PartitionedByIdCollectionRequestOptionsFactory() :
new PartitionedByIdCollectionRequestOptionsFactory() :
(RequestOptionsFactory)new SinglePartitionRequestOptionsFactory();
DocumentServiceLeaseStoreManagerBuilder leaseStoreManagerBuilder = new DocumentServiceLeaseStoreManagerBuilder()

Просмотреть файл

@ -64,15 +64,15 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.Configuration
/// <seealso cref="ChangeFeedOptions.StartTime"/>
public DateTime? StartTime
{
get
{
return this.startTime;
}
get => this.startTime;
set
{
if (value.HasValue && value.Value.Kind == DateTimeKind.Unspecified)
{
throw new ArgumentException("StartTime cannot have DateTimeKind.Unspecified", nameof(value));
}
this.startTime = value;
}
}

Просмотреть файл

@ -16,9 +16,10 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.DocDBErrors
string valueSubStatus = exception.ResponseHeaders.Get(subStatusHeaderName);
if (!string.IsNullOrEmpty(valueSubStatus))
{
int subStatusCode;
if (int.TryParse(valueSubStatus, NumberStyles.Integer, CultureInfo.InvariantCulture, out subStatusCode))
if (int.TryParse(valueSubStatus, NumberStyles.Integer, CultureInfo.InvariantCulture, out int subStatusCode))
{
return (SubStatusCodes)subStatusCode;
}
}
return SubStatusCodes.Unknown;

Просмотреть файл

@ -23,7 +23,11 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedManagement
public EqualPartitionsBalancingStrategy(string hostName, int minPartitionCount, int maxPartitionCount, TimeSpan leaseExpirationInterval)
{
if (hostName == null) throw new ArgumentNullException(nameof(hostName));
if (hostName == null)
{
throw new ArgumentNullException(nameof(hostName));
}
this.hostName = hostName;
this.minPartitionCount = minPartitionCount;
this.maxPartitionCount = maxPartitionCount;
@ -32,15 +36,17 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedManagement
public override IEnumerable<DocumentServiceLease> SelectLeasesToTake(IEnumerable<DocumentServiceLease> allLeases)
{
var workerToPartitionCount = new Dictionary<string, int>();
var expiredLeases = new List<DocumentServiceLease>();
var allPartitions = new Dictionary<string, DocumentServiceLease>();
Dictionary<string, int> workerToPartitionCount = new Dictionary<string, int>();
List<DocumentServiceLease> expiredLeases = new List<DocumentServiceLease>();
Dictionary<string, DocumentServiceLease> allPartitions = new Dictionary<string, DocumentServiceLease>();
this.CategorizeLeases(allLeases, allPartitions, expiredLeases, workerToPartitionCount);
int partitionCount = allPartitions.Count;
int workerCount = workerToPartitionCount.Count;
if (partitionCount <= 0)
{
return Enumerable.Empty<DocumentServiceLease>();
}
int target = this.CalculateTargetPartitionCount(partitionCount, workerCount);
int myCount = workerToPartitionCount[this.hostName];
@ -59,7 +65,9 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedManagement
Math.Max(partitionsNeededForMe, 0));
if (partitionsNeededForMe <= 0)
{
return Enumerable.Empty<DocumentServiceLease>();
}
if (expiredLeases.Count > 0)
{
@ -101,7 +109,7 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedManagement
private int CalculateTargetPartitionCount(int partitionCount, int workerCount)
{
var target = 1;
int target = 1;
if (partitionCount > workerCount)
{
target = (int)Math.Ceiling((double)partitionCount / workerCount);
@ -138,9 +146,8 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedManagement
}
else
{
var count = 0;
string assignedTo = lease.Owner;
if (workerToPartitionCount.TryGetValue(assignedTo, out count))
if (workerToPartitionCount.TryGetValue(assignedTo, out int count))
{
workerToPartitionCount[assignedTo] = count + 1;
}

Просмотреть файл

@ -53,8 +53,11 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedManagement
{
try
{
var renewedLease = await this.leaseManager.RenewAsync(this.lease).ConfigureAwait(false);
if (renewedLease != null) this.lease = renewedLease;
DocumentServiceLease renewedLease = await this.leaseManager.RenewAsync(this.lease).ConfigureAwait(false);
if (renewedLease != null)
{
this.lease = renewedLease;
}
DefaultTrace.TraceInformation("Lease with token {0}: renewed lease with result {1}", this.lease.CurrentLeaseToken, renewedLease != null);
}

Просмотреть файл

@ -57,7 +57,11 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedManagement
try
{
DocumentServiceLease updatedLease = await this.leaseManager.AcquireAsync(lease).ConfigureAwait(false);
if (updatedLease != null) lease = updatedLease;
if (updatedLease != null)
{
lease = updatedLease;
}
DefaultTrace.TraceInformation("Lease with token {0}: acquired", lease.CurrentLeaseToken);
}
catch (Exception)
@ -92,8 +96,7 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedManagement
private async Task RemoveLeaseAsync(DocumentServiceLease lease)
{
TaskCompletionSource<bool> worker;
if (!this.currentlyOwnedPartitions.TryRemove(lease.CurrentLeaseToken, out worker))
if (!this.currentlyOwnedPartitions.TryRemove(lease.CurrentLeaseToken, out TaskCompletionSource<bool> worker))
{
return;
}

Просмотреть файл

@ -26,9 +26,20 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedManagement
LoadBalancingStrategy partitionLoadBalancingStrategy,
TimeSpan leaseAcquireInterval)
{
if (partitionController == null) throw new ArgumentNullException(nameof(partitionController));
if (leaseContainer == null) throw new ArgumentNullException(nameof(leaseContainer));
if (partitionLoadBalancingStrategy == null) throw new ArgumentNullException(nameof(partitionLoadBalancingStrategy));
if (partitionController == null)
{
throw new ArgumentNullException(nameof(partitionController));
}
if (leaseContainer == null)
{
throw new ArgumentNullException(nameof(leaseContainer));
}
if (partitionLoadBalancingStrategy == null)
{
throw new ArgumentNullException(nameof(partitionLoadBalancingStrategy));
}
this.partitionController = partitionController;
this.leaseContainer = leaseContainer;

Просмотреть файл

@ -18,7 +18,10 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedManagement
/// <param name="remainingWork">The amount of documents remaining to be processed</param>
public RemainingLeaseTokenWork(string leaseToken, long remainingWork)
{
if (string.IsNullOrEmpty(leaseToken)) throw new ArgumentNullException(nameof(leaseToken));
if (string.IsNullOrEmpty(leaseToken))
{
throw new ArgumentNullException(nameof(leaseToken));
}
this.LeaseToken = leaseToken;
this.RemainingWork = remainingWork;

Просмотреть файл

@ -17,7 +17,6 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedManagement
using Microsoft.Azure.Cosmos.ChangeFeed.LeaseManagement;
using Microsoft.Azure.Cosmos.ChangeFeed.Utils;
using Microsoft.Azure.Cosmos.Core.Trace;
using Microsoft.Azure.Cosmos.Query.Core;
using Microsoft.Azure.Documents;
using Newtonsoft.Json.Linq;
@ -58,7 +57,10 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedManagement
public override async Task<long> GetEstimatedRemainingWorkAsync(CancellationToken cancellationToken)
{
IReadOnlyList<RemainingLeaseTokenWork> leaseTokens = await this.GetEstimatedRemainingWorkPerLeaseTokenAsync(cancellationToken);
if (leaseTokens.Count == 0) return 1;
if (leaseTokens.Count == 0)
{
return 1;
}
return leaseTokens.Sum(leaseToken => leaseToken.RemainingWork);
}
@ -83,7 +85,11 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedManagement
DocumentServiceLease item = partition.Current;
try
{
if (string.IsNullOrEmpty(item?.CurrentLeaseToken)) continue;
if (string.IsNullOrEmpty(item?.CurrentLeaseToken))
{
continue;
}
long result = await this.GetRemainingWorkAsync(item, cancellationToken);
partialResults.Add(new RemainingLeaseTokenWork(item.CurrentLeaseToken, result));
}
@ -158,8 +164,7 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedManagement
private static long TryConvertToNumber(string number)
{
long parsed = 0;
if (!long.TryParse(number, NumberStyles.Number, CultureInfo.InvariantCulture, out parsed))
if (!long.TryParse(number, NumberStyles.Number, CultureInfo.InvariantCulture, out long parsed))
{
DefaultTrace.TraceWarning("Cannot parse number '{0}'.", number);
return 0;

Просмотреть файл

@ -20,9 +20,14 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedProcessing
public AutoCheckpointer(CheckpointFrequency checkpointFrequency, ChangeFeedObserver<T> observer)
{
if (checkpointFrequency == null)
{
throw new ArgumentNullException(nameof(checkpointFrequency));
}
if (observer == null)
{
throw new ArgumentNullException(nameof(observer));
}
this.checkpointFrequency = checkpointFrequency;
this.observer = observer;
@ -59,11 +64,15 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedProcessing
}
if (this.processedDocCount >= this.checkpointFrequency.ProcessedDocumentCount)
{
return true;
}
TimeSpan delta = DateTime.UtcNow - this.lastCheckpointTime;
if (delta >= this.checkpointFrequency.TimeInterval)
{
return true;
}
return false;
}

Просмотреть файл

@ -23,9 +23,14 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedProcessing
public CheckpointerObserverFactory(ChangeFeedObserverFactory<T> observerFactory, CheckpointFrequency checkpointFrequency)
{
if (observerFactory == null)
{
throw new ArgumentNullException(nameof(observerFactory));
}
if (checkpointFrequency == null)
{
throw new ArgumentNullException(nameof(checkpointFrequency));
}
this.observerFactory = observerFactory;
this.checkpointFrequency = checkpointFrequency;
@ -38,7 +43,10 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedProcessing
public override ChangeFeedObserver<T> CreateObserver()
{
ChangeFeedObserver<T> observer = new ObserverExceptionWrappingChangeFeedObserverDecorator<T>(this.observerFactory.CreateObserver());
if (this.checkpointFrequency.ExplicitCheckpoint) return observer;
if (this.checkpointFrequency.ExplicitCheckpoint)
{
return observer;
}
return new AutoCheckpointer<T>(this.checkpointFrequency, observer);
}

Просмотреть файл

@ -37,7 +37,9 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.FeedProcessing
catch (TaskCanceledException canceledException)
{
if (cancellationToken.IsCancellationRequested)
{
throw;
}
Extensions.TraceException(new Exception("exception within estimator", canceledException));

Просмотреть файл

@ -96,7 +96,7 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.Utils
public static async Task<string> GetMonitoredContainerRidAsync(
this Container monitoredContainer,
string suggestedMonitoredRid,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (!string.IsNullOrEmpty(suggestedMonitoredRid))
{

Просмотреть файл

@ -18,7 +18,7 @@ namespace Microsoft.Azure.Cosmos.ChangeFeed.Utils
this IEnumerable<TSource> source,
Func<TSource, Task> worker,
int maxParallelTaskCount = 0,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
Debug.Assert(source != null, "source is null");
Debug.Assert(worker != null, "worker is null");

Просмотреть файл

@ -16,7 +16,7 @@ namespace Microsoft.Azure.Cosmos
public static async Task<HttpResponseMessage> GetAsync(this HttpClient client,
Uri uri,
INameValueCollection additionalHeaders = null,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (uri == null) throw new ArgumentNullException("uri");

Просмотреть файл

@ -5,9 +5,7 @@
namespace Microsoft.Azure.Cosmos
{
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@ -376,7 +374,7 @@ namespace Microsoft.Azure.Cosmos
string id,
int? throughput = null,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(id))
{
@ -388,16 +386,16 @@ namespace Microsoft.Azure.Cosmos
requestOptions,
(diagnostics) =>
{
DatabaseProperties databaseProperties = this.PrepareDatabaseProperties(id);
ThroughputProperties throughputProperties = ThroughputProperties.CreateManualThroughput(throughput);
DatabaseProperties databaseProperties = this.PrepareDatabaseProperties(id);
ThroughputProperties throughputProperties = ThroughputProperties.CreateManualThroughput(throughput);
return this.CreateDatabaseInternalAsync(
databaseProperties: databaseProperties,
throughputProperties: throughputProperties,
requestOptions: requestOptions,
diagnosticsContext: diagnostics,
cancellationToken: cancellationToken);
});
return this.CreateDatabaseInternalAsync(
databaseProperties: databaseProperties,
throughputProperties: throughputProperties,
requestOptions: requestOptions,
diagnosticsContext: diagnostics,
cancellationToken: cancellationToken);
});
}
/// <summary>
@ -422,7 +420,7 @@ namespace Microsoft.Azure.Cosmos
string id,
ThroughputProperties throughputProperties,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(id))
{
@ -480,14 +478,11 @@ namespace Microsoft.Azure.Cosmos
string id,
ThroughputProperties throughputProperties,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(id))
{
throw new ArgumentNullException(nameof(id));
}
return this.ClientContext.OperationHelperAsync(
return string.IsNullOrEmpty(id)
? throw new ArgumentNullException(nameof(id))
: this.ClientContext.OperationHelperAsync(
nameof(CreateDatabaseIfNotExistsAsync),
requestOptions,
async (diagnostics) =>
@ -566,7 +561,7 @@ namespace Microsoft.Azure.Cosmos
string id,
int? throughput = null,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
ThroughputProperties throughputProperties = ThroughputProperties.CreateManualThroughput(throughput);
@ -806,7 +801,7 @@ namespace Microsoft.Azure.Cosmos
DatabaseProperties databaseProperties,
int? throughput = null,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (databaseProperties == null)
{
@ -875,7 +870,7 @@ namespace Microsoft.Azure.Cosmos
DatabaseProperties databaseProperties,
ThroughputProperties throughputProperties,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (databaseProperties == null)
{

Просмотреть файл

@ -32,41 +32,86 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
public bool Value { get; }
public override void Accept(ICosmosElementVisitor cosmosElementVisitor) => cosmosElementVisitor.Visit(this);
public override void Accept(ICosmosElementVisitor cosmosElementVisitor)
{
cosmosElementVisitor.Visit(this);
}
public override TResult Accept<TResult>(ICosmosElementVisitor<TResult> cosmosElementVisitor) => cosmosElementVisitor.Visit(this);
public override TResult Accept<TResult>(ICosmosElementVisitor<TResult> cosmosElementVisitor)
{
return cosmosElementVisitor.Visit(this);
}
public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResult> cosmosElementVisitor, TArg input) => cosmosElementVisitor.Visit(this, input);
public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResult> cosmosElementVisitor, TArg input)
{
return cosmosElementVisitor.Visit(this, input);
}
public override bool Equals(CosmosElement cosmosElement) => cosmosElement is CosmosBoolean cosmosBoolean && this.Equals(cosmosBoolean);
public override bool Equals(CosmosElement cosmosElement)
{
return cosmosElement is CosmosBoolean cosmosBoolean && this.Equals(cosmosBoolean);
}
public bool Equals(CosmosBoolean cosmosBoolean) => this.Value == cosmosBoolean.Value;
public bool Equals(CosmosBoolean cosmosBoolean)
{
return this.Value == cosmosBoolean.Value;
}
public override int GetHashCode() => this.Value ? TrueHash : FalseHash;
public override int GetHashCode()
{
return this.Value ? TrueHash : FalseHash;
}
public int CompareTo(CosmosBoolean cosmosBoolean) => this.Value.CompareTo(cosmosBoolean.Value);
public int CompareTo(CosmosBoolean cosmosBoolean)
{
return this.Value.CompareTo(cosmosBoolean.Value);
}
public static CosmosBoolean Create(bool boolean) => boolean ? CosmosBoolean.True : CosmosBoolean.False;
public static CosmosBoolean Create(bool boolean)
{
return boolean ? CosmosBoolean.True : CosmosBoolean.False;
}
public override void WriteTo(IJsonWriter jsonWriter) => jsonWriter.WriteBoolValue(this.Value);
public override void WriteTo(IJsonWriter jsonWriter)
{
jsonWriter.WriteBoolValue(this.Value);
}
public static new CosmosBoolean CreateFromBuffer(ReadOnlyMemory<byte> buffer) => CosmosElement.CreateFromBuffer<CosmosBoolean>(buffer);
public static new CosmosBoolean CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.CreateFromBuffer<CosmosBoolean>(buffer);
}
public static new CosmosBoolean Parse(string json) => CosmosElement.Parse<CosmosBoolean>(json);
public static new CosmosBoolean Parse(string json)
{
return CosmosElement.Parse<CosmosBoolean>(json);
}
public static bool TryCreateFromBuffer(
ReadOnlyMemory<byte> buffer,
out CosmosBoolean cosmosBoolean) => CosmosElement.TryCreateFromBuffer<CosmosBoolean>(buffer, out cosmosBoolean);
out CosmosBoolean cosmosBoolean)
{
return CosmosElement.TryCreateFromBuffer<CosmosBoolean>(buffer, out cosmosBoolean);
}
public static bool TryParse(
string json,
out CosmosBoolean cosmosBoolean) => CosmosElement.TryParse<CosmosBoolean>(json, out cosmosBoolean);
out CosmosBoolean cosmosBoolean)
{
return CosmosElement.TryParse<CosmosBoolean>(json, out cosmosBoolean);
}
public static new class Monadic
{
public static TryCatch<CosmosBoolean> CreateFromBuffer(ReadOnlyMemory<byte> buffer) => CosmosElement.Monadic.CreateFromBuffer<CosmosBoolean>(buffer);
public static TryCatch<CosmosBoolean> CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.Monadic.CreateFromBuffer<CosmosBoolean>(buffer);
}
public static TryCatch<CosmosBoolean> Parse(string json) => CosmosElement.Monadic.Parse<CosmosBoolean>(json);
public static TryCatch<CosmosBoolean> Parse(string json)
{
return CosmosElement.Monadic.Parse<CosmosBoolean>(json);
}
}
}
#if INTERNAL

Просмотреть файл

@ -41,11 +41,14 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
return Utf8StringHelpers.ToString(jsonWriter.GetResult());
}
public override bool Equals(object obj) => obj is CosmosElement cosmosElement && this.Equals(cosmosElement);
public override bool Equals(object obj)
{
return obj is CosmosElement cosmosElement && this.Equals(cosmosElement);
}
public abstract bool Equals(CosmosElement cosmosElement);
public override abstract int GetHashCode();
public abstract override int GetHashCode();
public int CompareTo(CosmosElement other)
{
@ -121,7 +124,10 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
return TryCatch<TCosmosElement>.FromResult(typedCosmosElement);
}
public static TryCatch<CosmosElement> CreateFromBuffer(ReadOnlyMemory<byte> buffer) => CosmosElement.Monadic.CreateFromBuffer<CosmosElement>(buffer);
public static TryCatch<CosmosElement> CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.Monadic.CreateFromBuffer<CosmosElement>(buffer);
}
public static TryCatch<TCosmosElement> Parse<TCosmosElement>(string serializedCosmosElement)
where TCosmosElement : CosmosElement
@ -142,7 +148,10 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
return CosmosElement.Monadic.CreateFromBuffer<TCosmosElement>(buffer);
}
public static TryCatch<CosmosElement> Parse(string serializedCosmosElement) => CosmosElement.Monadic.Parse<CosmosElement>(serializedCosmosElement);
public static TryCatch<CosmosElement> Parse(string serializedCosmosElement)
{
return CosmosElement.Monadic.Parse<CosmosElement>(serializedCosmosElement);
}
}
public static TCosmosElement CreateFromBuffer<TCosmosElement>(ReadOnlyMemory<byte> buffer)
@ -154,7 +163,10 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
return tryCreateFromBuffer.Result;
}
public static CosmosElement CreateFromBuffer(ReadOnlyMemory<byte> buffer) => CosmosElement.CreateFromBuffer<CosmosElement>(buffer);
public static CosmosElement CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.CreateFromBuffer<CosmosElement>(buffer);
}
public static bool TryCreateFromBuffer<TCosmosElement>(ReadOnlyMemory<byte> buffer, out TCosmosElement cosmosElement)
where TCosmosElement : CosmosElement
@ -248,7 +260,10 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
return a.Equals(b);
}
public static bool operator !=(CosmosElement a, CosmosElement b) => !(a == b);
public static bool operator !=(CosmosElement a, CosmosElement b)
{
return !(a == b);
}
private sealed class CosmosElementToTypeOrder : ICosmosElementVisitor<int>
{
@ -258,14 +273,45 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
{
}
public int Visit(CosmosNull cosmosNull) => 0;
public int Visit(CosmosBoolean cosmosBoolean) => 1;
public int Visit(CosmosNumber cosmosNumber) => 2;
public int Visit(CosmosString cosmosString) => 3;
public int Visit(CosmosArray cosmosArray) => 4;
public int Visit(CosmosObject cosmosObject) => 5;
public int Visit(CosmosGuid cosmosGuid) => 6;
public int Visit(CosmosBinary cosmosBinary) => 7;
public int Visit(CosmosNull cosmosNull)
{
return 0;
}
public int Visit(CosmosBoolean cosmosBoolean)
{
return 1;
}
public int Visit(CosmosNumber cosmosNumber)
{
return 2;
}
public int Visit(CosmosString cosmosString)
{
return 3;
}
public int Visit(CosmosArray cosmosArray)
{
return 4;
}
public int Visit(CosmosObject cosmosObject)
{
return 5;
}
public int Visit(CosmosGuid cosmosGuid)
{
return 6;
}
public int Visit(CosmosBinary cosmosBinary)
{
return 7;
}
}
private sealed class CosmosElementWithinTypeComparer : ICosmosElementVisitor<CosmosElement, int>
@ -276,14 +322,45 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
{
}
public int Visit(CosmosArray cosmosArray, CosmosElement input) => cosmosArray.CompareTo((CosmosArray)input);
public int Visit(CosmosBinary cosmosBinary, CosmosElement input) => cosmosBinary.CompareTo((CosmosBinary)input);
public int Visit(CosmosBoolean cosmosBoolean, CosmosElement input) => cosmosBoolean.CompareTo((CosmosBoolean)input);
public int Visit(CosmosGuid cosmosGuid, CosmosElement input) => cosmosGuid.CompareTo((CosmosGuid)input);
public int Visit(CosmosNull cosmosNull, CosmosElement input) => cosmosNull.CompareTo((CosmosNull)input);
public int Visit(CosmosNumber cosmosNumber, CosmosElement input) => cosmosNumber.CompareTo((CosmosNumber)input);
public int Visit(CosmosObject cosmosObject, CosmosElement input) => cosmosObject.CompareTo((CosmosObject)input);
public int Visit(CosmosString cosmosString, CosmosElement input) => cosmosString.CompareTo((CosmosString)input);
public int Visit(CosmosArray cosmosArray, CosmosElement input)
{
return cosmosArray.CompareTo((CosmosArray)input);
}
public int Visit(CosmosBinary cosmosBinary, CosmosElement input)
{
return cosmosBinary.CompareTo((CosmosBinary)input);
}
public int Visit(CosmosBoolean cosmosBoolean, CosmosElement input)
{
return cosmosBoolean.CompareTo((CosmosBoolean)input);
}
public int Visit(CosmosGuid cosmosGuid, CosmosElement input)
{
return cosmosGuid.CompareTo((CosmosGuid)input);
}
public int Visit(CosmosNull cosmosNull, CosmosElement input)
{
return cosmosNull.CompareTo((CosmosNull)input);
}
public int Visit(CosmosNumber cosmosNumber, CosmosElement input)
{
return cosmosNumber.CompareTo((CosmosNumber)input);
}
public int Visit(CosmosObject cosmosObject, CosmosElement input)
{
return cosmosObject.CompareTo((CosmosObject)input);
}
public int Visit(CosmosString cosmosString, CosmosElement input)
{
return cosmosString.CompareTo((CosmosString)input);
}
}
}
#if INTERNAL

Просмотреть файл

@ -28,15 +28,30 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
public abstract Guid Value { get; }
public override void Accept(ICosmosElementVisitor cosmosElementVisitor) => cosmosElementVisitor.Visit(this);
public override void Accept(ICosmosElementVisitor cosmosElementVisitor)
{
cosmosElementVisitor.Visit(this);
}
public override TResult Accept<TResult>(ICosmosElementVisitor<TResult> cosmosElementVisitor) => cosmosElementVisitor.Visit(this);
public override TResult Accept<TResult>(ICosmosElementVisitor<TResult> cosmosElementVisitor)
{
return cosmosElementVisitor.Visit(this);
}
public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResult> cosmosElementVisitor, TArg input) => cosmosElementVisitor.Visit(this, input);
public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResult> cosmosElementVisitor, TArg input)
{
return cosmosElementVisitor.Visit(this, input);
}
public override bool Equals(CosmosElement cosmosElement) => cosmosElement is CosmosGuid cosmosGuid && this.Equals(cosmosGuid);
public override bool Equals(CosmosElement cosmosElement)
{
return cosmosElement is CosmosGuid cosmosGuid && this.Equals(cosmosGuid);
}
public bool Equals(CosmosGuid cosmosGuid) => this.Value == cosmosGuid.Value;
public bool Equals(CosmosGuid cosmosGuid)
{
return this.Value == cosmosGuid.Value;
}
public override int GetHashCode()
{
@ -45,7 +60,10 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
return (int)hash;
}
public int CompareTo(CosmosGuid cosmosGuid) => this.Value.CompareTo(cosmosGuid.Value);
public int CompareTo(CosmosGuid cosmosGuid)
{
return this.Value.CompareTo(cosmosGuid.Value);
}
public static CosmosGuid Create(
IJsonNavigator jsonNavigator,
@ -54,27 +72,51 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
return new LazyCosmosGuid(jsonNavigator, jsonNavigatorNode);
}
public static CosmosGuid Create(Guid value) => new EagerCosmosGuid(value);
public static CosmosGuid Create(Guid value)
{
return new EagerCosmosGuid(value);
}
public override void WriteTo(IJsonWriter jsonWriter) => jsonWriter.WriteGuidValue(this.Value);
public override void WriteTo(IJsonWriter jsonWriter)
{
jsonWriter.WriteGuidValue(this.Value);
}
public static new CosmosGuid CreateFromBuffer(ReadOnlyMemory<byte> buffer) => CosmosElement.CreateFromBuffer<CosmosGuid>(buffer);
public static new CosmosGuid CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.CreateFromBuffer<CosmosGuid>(buffer);
}
public static new CosmosGuid Parse(string json) => CosmosElement.Parse<CosmosGuid>(json);
public static new CosmosGuid Parse(string json)
{
return CosmosElement.Parse<CosmosGuid>(json);
}
public static bool TryCreateFromBuffer(
ReadOnlyMemory<byte> buffer,
out CosmosGuid cosmosGuid) => CosmosElement.TryCreateFromBuffer<CosmosGuid>(buffer, out cosmosGuid);
out CosmosGuid cosmosGuid)
{
return CosmosElement.TryCreateFromBuffer<CosmosGuid>(buffer, out cosmosGuid);
}
public static bool TryParse(
string json,
out CosmosGuid cosmosGuid) => CosmosElement.TryParse<CosmosGuid>(json, out cosmosGuid);
out CosmosGuid cosmosGuid)
{
return CosmosElement.TryParse<CosmosGuid>(json, out cosmosGuid);
}
public static new class Monadic
{
public static TryCatch<CosmosGuid> CreateFromBuffer(ReadOnlyMemory<byte> buffer) => CosmosElement.Monadic.CreateFromBuffer<CosmosGuid>(buffer);
public static TryCatch<CosmosGuid> CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.Monadic.CreateFromBuffer<CosmosGuid>(buffer);
}
public static TryCatch<CosmosGuid> Parse(string json) => CosmosElement.Monadic.Parse<CosmosGuid>(json);
public static TryCatch<CosmosGuid> Parse(string json)
{
return CosmosElement.Monadic.Parse<CosmosGuid>(json);
}
}
}
#if INTERNAL

Просмотреть файл

@ -27,41 +27,86 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
{
}
public override void Accept(ICosmosElementVisitor cosmosElementVisitor) => cosmosElementVisitor.Visit(this);
public override void Accept(ICosmosElementVisitor cosmosElementVisitor)
{
cosmosElementVisitor.Visit(this);
}
public override TResult Accept<TResult>(ICosmosElementVisitor<TResult> cosmosElementVisitor) => cosmosElementVisitor.Visit(this);
public override TResult Accept<TResult>(ICosmosElementVisitor<TResult> cosmosElementVisitor)
{
return cosmosElementVisitor.Visit(this);
}
public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResult> cosmosElementVisitor, TArg input) => cosmosElementVisitor.Visit(this, input);
public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResult> cosmosElementVisitor, TArg input)
{
return cosmosElementVisitor.Visit(this, input);
}
public override bool Equals(CosmosElement cosmosElement) => cosmosElement is CosmosNull cosmosNull && this.Equals(cosmosNull);
public override bool Equals(CosmosElement cosmosElement)
{
return cosmosElement is CosmosNull cosmosNull && this.Equals(cosmosNull);
}
public bool Equals(CosmosNull cosmosNull) => true;
public bool Equals(CosmosNull cosmosNull)
{
return true;
}
public static CosmosNull Create() => CosmosNull.Singleton;
public static CosmosNull Create()
{
return CosmosNull.Singleton;
}
public override int GetHashCode() => (int)Hash;
public override int GetHashCode()
{
return (int)Hash;
}
public override void WriteTo(IJsonWriter jsonWriter) => jsonWriter.WriteNullValue();
public override void WriteTo(IJsonWriter jsonWriter)
{
jsonWriter.WriteNullValue();
}
public static new CosmosNull CreateFromBuffer(ReadOnlyMemory<byte> buffer) => CosmosElement.CreateFromBuffer<CosmosNull>(buffer);
public static new CosmosNull CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.CreateFromBuffer<CosmosNull>(buffer);
}
public static new CosmosNull Parse(string json) => CosmosElement.Parse<CosmosNull>(json);
public static new CosmosNull Parse(string json)
{
return CosmosElement.Parse<CosmosNull>(json);
}
public static bool TryCreateFromBuffer(
ReadOnlyMemory<byte> buffer,
out CosmosNull cosmosNull) => CosmosElement.TryCreateFromBuffer<CosmosNull>(buffer, out cosmosNull);
out CosmosNull cosmosNull)
{
return CosmosElement.TryCreateFromBuffer<CosmosNull>(buffer, out cosmosNull);
}
public static bool TryParse(
string json,
out CosmosNull cosmosNull) => CosmosElement.TryParse<CosmosNull>(json, out cosmosNull);
out CosmosNull cosmosNull)
{
return CosmosElement.TryParse<CosmosNull>(json, out cosmosNull);
}
public int CompareTo(CosmosNull other) => 0;
public int CompareTo(CosmosNull other)
{
return 0;
}
public static new class Monadic
{
public static TryCatch<CosmosNull> CreateFromBuffer(ReadOnlyMemory<byte> buffer) => CosmosElement.Monadic.CreateFromBuffer<CosmosNull>(buffer);
public static TryCatch<CosmosNull> CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.Monadic.CreateFromBuffer<CosmosNull>(buffer);
}
public static TryCatch<CosmosNull> Parse(string json) => CosmosElement.Monadic.Parse<CosmosNull>(json);
public static TryCatch<CosmosNull> Parse(string json)
{
return CosmosElement.Monadic.Parse<CosmosNull>(json);
}
}
}
#if INTERNAL

Просмотреть файл

@ -31,13 +31,25 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
public abstract TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input);
public override void Accept(ICosmosElementVisitor cosmosElementVisitor) => cosmosElementVisitor.Visit(this);
public override void Accept(ICosmosElementVisitor cosmosElementVisitor)
{
cosmosElementVisitor.Visit(this);
}
public override TResult Accept<TResult>(ICosmosElementVisitor<TResult> cosmosElementVisitor) => cosmosElementVisitor.Visit(this);
public override TResult Accept<TResult>(ICosmosElementVisitor<TResult> cosmosElementVisitor)
{
return cosmosElementVisitor.Visit(this);
}
public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResult> cosmosElementVisitor, TArg input) => cosmosElementVisitor.Visit(this, input);
public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResult> cosmosElementVisitor, TArg input)
{
return cosmosElementVisitor.Visit(this, input);
}
public override bool Equals(CosmosElement cosmosElement) => cosmosElement is CosmosNumber cosmosNumber && this.Equals(cosmosNumber);
public override bool Equals(CosmosElement cosmosElement)
{
return cosmosElement is CosmosNumber cosmosNumber && this.Equals(cosmosNumber);
}
public abstract bool Equals(CosmosNumber cosmosNumber);
@ -55,23 +67,41 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
return this.Accept(CosmosNumberWithinTypeComparer.Singleton, other);
}
public static new CosmosNumber CreateFromBuffer(ReadOnlyMemory<byte> buffer) => CosmosElement.CreateFromBuffer<CosmosNumber>(buffer);
public static new CosmosNumber CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.CreateFromBuffer<CosmosNumber>(buffer);
}
public static new CosmosNumber Parse(string json) => CosmosElement.Parse<CosmosNumber>(json);
public static new CosmosNumber Parse(string json)
{
return CosmosElement.Parse<CosmosNumber>(json);
}
public static bool TryCreateFromBuffer(
ReadOnlyMemory<byte> buffer,
out CosmosNumber cosmosNumber) => CosmosElement.TryCreateFromBuffer<CosmosNumber>(buffer, out cosmosNumber);
out CosmosNumber cosmosNumber)
{
return CosmosElement.TryCreateFromBuffer<CosmosNumber>(buffer, out cosmosNumber);
}
public static bool TryParse(
string json,
out CosmosNumber cosmosNumber) => CosmosElement.TryParse<CosmosNumber>(json, out cosmosNumber);
out CosmosNumber cosmosNumber)
{
return CosmosElement.TryParse<CosmosNumber>(json, out cosmosNumber);
}
public static new class Monadic
{
public static TryCatch<CosmosNumber> CreateFromBuffer(ReadOnlyMemory<byte> buffer) => CosmosElement.Monadic.CreateFromBuffer<CosmosNumber>(buffer);
public static TryCatch<CosmosNumber> CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.Monadic.CreateFromBuffer<CosmosNumber>(buffer);
}
public static TryCatch<CosmosNumber> Parse(string json) => CosmosElement.Monadic.Parse<CosmosNumber>(json);
public static TryCatch<CosmosNumber> Parse(string json)
{
return CosmosElement.Monadic.Parse<CosmosNumber>(json);
}
}
private sealed class CosmosNumberToTypeOrder : ICosmosNumberVisitor<int>
@ -82,14 +112,45 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
{
}
public int Visit(CosmosNumber64 cosmosNumber64) => 0;
public int Visit(CosmosInt8 cosmosInt8) => 1;
public int Visit(CosmosInt16 cosmosInt16) => 2;
public int Visit(CosmosInt32 cosmosInt32) => 3;
public int Visit(CosmosInt64 cosmosInt64) => 4;
public int Visit(CosmosUInt32 cosmosUInt32) => 5;
public int Visit(CosmosFloat32 cosmosFloat32) => 6;
public int Visit(CosmosFloat64 cosmosFloat64) => 7;
public int Visit(CosmosNumber64 cosmosNumber64)
{
return 0;
}
public int Visit(CosmosInt8 cosmosInt8)
{
return 1;
}
public int Visit(CosmosInt16 cosmosInt16)
{
return 2;
}
public int Visit(CosmosInt32 cosmosInt32)
{
return 3;
}
public int Visit(CosmosInt64 cosmosInt64)
{
return 4;
}
public int Visit(CosmosUInt32 cosmosUInt32)
{
return 5;
}
public int Visit(CosmosFloat32 cosmosFloat32)
{
return 6;
}
public int Visit(CosmosFloat64 cosmosFloat64)
{
return 7;
}
}
private sealed class CosmosNumberWithinTypeComparer : ICosmosNumberVisitor<CosmosNumber, int>
@ -100,14 +161,45 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
{
}
public int Visit(CosmosNumber64 cosmosNumber64, CosmosNumber input) => cosmosNumber64.CompareTo((CosmosNumber64)input);
public int Visit(CosmosInt8 cosmosInt8, CosmosNumber input) => cosmosInt8.CompareTo((CosmosInt8)input);
public int Visit(CosmosInt16 cosmosInt16, CosmosNumber input) => cosmosInt16.CompareTo((CosmosInt16)input);
public int Visit(CosmosInt32 cosmosInt32, CosmosNumber input) => cosmosInt32.CompareTo((CosmosInt32)input);
public int Visit(CosmosInt64 cosmosInt64, CosmosNumber input) => cosmosInt64.CompareTo((CosmosInt64)input);
public int Visit(CosmosUInt32 cosmosUInt32, CosmosNumber input) => cosmosUInt32.CompareTo((CosmosUInt32)input);
public int Visit(CosmosFloat32 cosmosFloat32, CosmosNumber input) => cosmosFloat32.CompareTo((CosmosFloat32)input);
public int Visit(CosmosFloat64 cosmosFloat64, CosmosNumber input) => cosmosFloat64.CompareTo((CosmosFloat64)input);
public int Visit(CosmosNumber64 cosmosNumber64, CosmosNumber input)
{
return cosmosNumber64.CompareTo((CosmosNumber64)input);
}
public int Visit(CosmosInt8 cosmosInt8, CosmosNumber input)
{
return cosmosInt8.CompareTo((CosmosInt8)input);
}
public int Visit(CosmosInt16 cosmosInt16, CosmosNumber input)
{
return cosmosInt16.CompareTo((CosmosInt16)input);
}
public int Visit(CosmosInt32 cosmosInt32, CosmosNumber input)
{
return cosmosInt32.CompareTo((CosmosInt32)input);
}
public int Visit(CosmosInt64 cosmosInt64, CosmosNumber input)
{
return cosmosInt64.CompareTo((CosmosInt64)input);
}
public int Visit(CosmosUInt32 cosmosUInt32, CosmosNumber input)
{
return cosmosUInt32.CompareTo((CosmosUInt32)input);
}
public int Visit(CosmosFloat32 cosmosFloat32, CosmosNumber input)
{
return cosmosFloat32.CompareTo((CosmosFloat32)input);
}
public int Visit(CosmosFloat64 cosmosFloat64, CosmosNumber input)
{
return cosmosFloat64.CompareTo((CosmosFloat64)input);
}
}
}
#if INTERNAL

Просмотреть файл

@ -47,9 +47,15 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
public override int Count => this.properties.Count;
public override bool ContainsKey(string key) => this.TryGetValue(key, out _);
public override bool ContainsKey(string key)
{
return this.TryGetValue(key, out _);
}
public override IEnumerator<KeyValuePair<string, CosmosElement>> GetEnumerator() => this.properties.GetEnumerator();
public override IEnumerator<KeyValuePair<string, CosmosElement>> GetEnumerator()
{
return this.properties.GetEnumerator();
}
public override bool TryGetValue(string key, out CosmosElement value)
{

Просмотреть файл

@ -8,7 +8,6 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.Azure.Cosmos.Json;
@ -69,20 +68,26 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
}
}
public override bool ContainsKey(string key) => this.jsonNavigator.TryGetObjectProperty(
this.jsonNavigatorNode,
key,
out _);
public override bool ContainsKey(string key)
{
return this.jsonNavigator.TryGetObjectProperty(
this.jsonNavigatorNode,
key,
out _);
}
public override IEnumerator<KeyValuePair<string, CosmosElement>> GetEnumerator() => this
.jsonNavigator
.GetObjectProperties(this.jsonNavigatorNode)
.Select(
(objectProperty) =>
new KeyValuePair<string, CosmosElement>(
this.jsonNavigator.GetStringValue(objectProperty.NameNode),
CosmosElement.Dispatch(this.jsonNavigator, objectProperty.ValueNode)))
.GetEnumerator();
public override IEnumerator<KeyValuePair<string, CosmosElement>> GetEnumerator()
{
return this
.jsonNavigator
.GetObjectProperties(this.jsonNavigatorNode)
.Select(
(objectProperty) =>
new KeyValuePair<string, CosmosElement>(
this.jsonNavigator.GetStringValue(objectProperty.NameNode),
CosmosElement.Dispatch(this.jsonNavigator, objectProperty.ValueNode)))
.GetEnumerator();
}
public override bool TryGetValue(string key, out CosmosElement value)
{
@ -111,9 +116,15 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
return false;
}
public override void WriteTo(IJsonWriter jsonWriter) => this.jsonNavigator.WriteNode(this.jsonNavigatorNode, jsonWriter);
public override void WriteTo(IJsonWriter jsonWriter)
{
this.jsonNavigator.WriteNode(this.jsonNavigatorNode, jsonWriter);
}
public override IJsonReader CreateReader() => this.jsonNavigator.CreateReader(this.jsonNavigatorNode);
public override IJsonReader CreateReader()
{
return this.jsonNavigator.CreateReader(this.jsonNavigatorNode);
}
}
}
#if INTERNAL

Просмотреть файл

@ -43,11 +43,20 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
public abstract bool TryGetValue(string key, out CosmosElement value);
public override void Accept(ICosmosElementVisitor cosmosElementVisitor) => cosmosElementVisitor.Visit(this);
public override void Accept(ICosmosElementVisitor cosmosElementVisitor)
{
cosmosElementVisitor.Visit(this);
}
public override TResult Accept<TResult>(ICosmosElementVisitor<TResult> cosmosElementVisitor) => cosmosElementVisitor.Visit(this);
public override TResult Accept<TResult>(ICosmosElementVisitor<TResult> cosmosElementVisitor)
{
return cosmosElementVisitor.Visit(this);
}
public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResult> cosmosElementVisitor, TArg input) => cosmosElementVisitor.Visit(this, input);
public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResult> cosmosElementVisitor, TArg input)
{
return cosmosElementVisitor.Visit(this, input);
}
public bool TryGetValue<TCosmosElement>(string key, out TCosmosElement typedCosmosElement)
where TCosmosElement : CosmosElement
@ -74,9 +83,15 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
public abstract IEnumerator<KeyValuePair<string, CosmosElement>> GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
public override bool Equals(CosmosElement cosmosElement) => cosmosElement is CosmosObject cosmosObject && this.Equals(cosmosObject);
public override bool Equals(CosmosElement cosmosElement)
{
return cosmosElement is CosmosObject cosmosObject && this.Equals(cosmosObject);
}
public bool Equals(CosmosObject cosmosObject)
{
@ -135,29 +150,56 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
public static CosmosObject Create(
IJsonNavigator jsonNavigator,
IJsonNavigatorNode jsonNavigatorNode) => new LazyCosmosObject(jsonNavigator, jsonNavigatorNode);
IJsonNavigatorNode jsonNavigatorNode)
{
return new LazyCosmosObject(jsonNavigator, jsonNavigatorNode);
}
public static CosmosObject Create(IReadOnlyDictionary<string, CosmosElement> dictionary) => new EagerCosmosObject(dictionary.ToList());
public static CosmosObject Create(IReadOnlyDictionary<string, CosmosElement> dictionary)
{
return new EagerCosmosObject(dictionary.ToList());
}
public static CosmosObject Create(IReadOnlyList<KeyValuePair<string, CosmosElement>> properties) => new EagerCosmosObject(properties);
public static CosmosObject Create(IReadOnlyList<KeyValuePair<string, CosmosElement>> properties)
{
return new EagerCosmosObject(properties);
}
public static new CosmosObject CreateFromBuffer(ReadOnlyMemory<byte> buffer) => CosmosElement.CreateFromBuffer<CosmosObject>(buffer);
public static new CosmosObject CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.CreateFromBuffer<CosmosObject>(buffer);
}
public static new CosmosObject Parse(string json) => CosmosElement.Parse<CosmosObject>(json);
public static new CosmosObject Parse(string json)
{
return CosmosElement.Parse<CosmosObject>(json);
}
public static bool TryCreateFromBuffer(
ReadOnlyMemory<byte> buffer,
out CosmosObject cosmosObject) => CosmosElement.TryCreateFromBuffer<CosmosObject>(buffer, out cosmosObject);
out CosmosObject cosmosObject)
{
return CosmosElement.TryCreateFromBuffer<CosmosObject>(buffer, out cosmosObject);
}
public static bool TryParse(
string json,
out CosmosObject cosmosObject) => CosmosElement.TryParse<CosmosObject>(json, out cosmosObject);
out CosmosObject cosmosObject)
{
return CosmosElement.TryParse<CosmosObject>(json, out cosmosObject);
}
public static new class Monadic
{
public static TryCatch<CosmosObject> CreateFromBuffer(ReadOnlyMemory<byte> buffer) => CosmosElement.Monadic.CreateFromBuffer<CosmosObject>(buffer);
public static TryCatch<CosmosObject> CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.Monadic.CreateFromBuffer<CosmosObject>(buffer);
}
public static TryCatch<CosmosObject> Parse(string json) => CosmosElement.Monadic.Parse<CosmosObject>(json);
public static TryCatch<CosmosObject> Parse(string json)
{
return CosmosElement.Monadic.Parse<CosmosObject>(json);
}
}
}
#if INTERNAL

Просмотреть файл

@ -33,7 +33,10 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
return false;
}
public override void WriteTo(IJsonWriter jsonWriter) => jsonWriter.WriteStringValue(this.Value);
public override void WriteTo(IJsonWriter jsonWriter)
{
jsonWriter.WriteStringValue(this.Value);
}
}
}
#if INTERNAL

Просмотреть файл

@ -38,11 +38,17 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
public override string Value => this.lazyString.Value;
public override bool TryGetBufferedValue(out Utf8Memory bufferedValue) => this.jsonNavigator.TryGetBufferedStringValue(
this.jsonNavigatorNode,
out bufferedValue);
public override bool TryGetBufferedValue(out Utf8Memory bufferedValue)
{
return this.jsonNavigator.TryGetBufferedStringValue(
this.jsonNavigatorNode,
out bufferedValue);
}
public override void WriteTo(IJsonWriter jsonWriter) => this.jsonNavigator.WriteNode(this.jsonNavigatorNode, jsonWriter);
public override void WriteTo(IJsonWriter jsonWriter)
{
this.jsonNavigator.WriteNode(this.jsonNavigatorNode, jsonWriter);
}
}
}
#if INTERNAL

Просмотреть файл

@ -32,15 +32,30 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
public abstract bool TryGetBufferedValue(out Utf8Memory bufferedUtf8Value);
public override void Accept(ICosmosElementVisitor cosmosElementVisitor) => cosmosElementVisitor.Visit(this);
public override void Accept(ICosmosElementVisitor cosmosElementVisitor)
{
cosmosElementVisitor.Visit(this);
}
public override TResult Accept<TResult>(ICosmosElementVisitor<TResult> cosmosElementVisitor) => cosmosElementVisitor.Visit(this);
public override TResult Accept<TResult>(ICosmosElementVisitor<TResult> cosmosElementVisitor)
{
return cosmosElementVisitor.Visit(this);
}
public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResult> cosmosElementVisitor, TArg input) => cosmosElementVisitor.Visit(this, input);
public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResult> cosmosElementVisitor, TArg input)
{
return cosmosElementVisitor.Visit(this, input);
}
public override bool Equals(CosmosElement cosmosElement) => cosmosElement is CosmosString cosmosString && this.Equals(cosmosString);
public override bool Equals(CosmosElement cosmosElement)
{
return cosmosElement is CosmosString cosmosString && this.Equals(cosmosString);
}
public bool Equals(CosmosString cosmosString) => this.Value == cosmosString.Value;
public bool Equals(CosmosString cosmosString)
{
return this.Value == cosmosString.Value;
}
public override int GetHashCode()
{
@ -50,31 +65,58 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
return (int)hash;
}
public int CompareTo(CosmosString cosmosString) => string.CompareOrdinal(this.Value, cosmosString.Value);
public int CompareTo(CosmosString cosmosString)
{
return string.CompareOrdinal(this.Value, cosmosString.Value);
}
public static CosmosString Create(
IJsonNavigator jsonNavigator,
IJsonNavigatorNode jsonNavigatorNode) => new LazyCosmosString(jsonNavigator, jsonNavigatorNode);
IJsonNavigatorNode jsonNavigatorNode)
{
return new LazyCosmosString(jsonNavigator, jsonNavigatorNode);
}
public static CosmosString Create(string value) => value.Length == 0 ? EagerCosmosString.Empty : new EagerCosmosString(value);
public static CosmosString Create(string value)
{
return value.Length == 0 ? EagerCosmosString.Empty : new EagerCosmosString(value);
}
public static new CosmosString CreateFromBuffer(ReadOnlyMemory<byte> buffer) => CosmosElement.CreateFromBuffer<CosmosString>(buffer);
public static new CosmosString CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.CreateFromBuffer<CosmosString>(buffer);
}
public static new CosmosString Parse(string json) => CosmosElement.Parse<CosmosString>(json);
public static new CosmosString Parse(string json)
{
return CosmosElement.Parse<CosmosString>(json);
}
public static bool TryCreateFromBuffer(
ReadOnlyMemory<byte> buffer,
out CosmosString cosmosString) => CosmosElement.TryCreateFromBuffer<CosmosString>(buffer, out cosmosString);
out CosmosString cosmosString)
{
return CosmosElement.TryCreateFromBuffer<CosmosString>(buffer, out cosmosString);
}
public static bool TryParse(
string json,
out CosmosString cosmosString) => CosmosElement.TryParse<CosmosString>(json, out cosmosString);
out CosmosString cosmosString)
{
return CosmosElement.TryParse<CosmosString>(json, out cosmosString);
}
public static new class Monadic
{
public static TryCatch<CosmosString> CreateFromBuffer(ReadOnlyMemory<byte> buffer) => CosmosElement.Monadic.CreateFromBuffer<CosmosString>(buffer);
public static TryCatch<CosmosString> CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.Monadic.CreateFromBuffer<CosmosString>(buffer);
}
public static TryCatch<CosmosString> Parse(string json) => CosmosElement.Monadic.Parse<CosmosString>(json);
public static TryCatch<CosmosString> Parse(string json)
{
return CosmosElement.Monadic.Parse<CosmosString>(json);
}
}
}
#if INTERNAL

Просмотреть файл

@ -30,26 +30,56 @@ namespace Microsoft.Azure.Cosmos.CosmosElements.Numbers
public abstract float GetValue();
public override void Accept(ICosmosNumberVisitor cosmosNumberVisitor) => cosmosNumberVisitor.Visit(this);
public override void Accept(ICosmosNumberVisitor cosmosNumberVisitor)
{
cosmosNumberVisitor.Visit(this);
}
public override TResult Accept<TResult>(ICosmosNumberVisitor<TResult> cosmosNumberVisitor) => cosmosNumberVisitor.Visit(this);
public override TResult Accept<TResult>(ICosmosNumberVisitor<TResult> cosmosNumberVisitor)
{
return cosmosNumberVisitor.Visit(this);
}
public override TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input) => cosmosNumberVisitor.Visit(this, input);
public override TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input)
{
return cosmosNumberVisitor.Visit(this, input);
}
public override bool Equals(CosmosNumber cosmosNumber) => cosmosNumber is CosmosFloat32 cosmosFloat32 && this.Equals(cosmosFloat32);
public override bool Equals(CosmosNumber cosmosNumber)
{
return cosmosNumber is CosmosFloat32 cosmosFloat32 && this.Equals(cosmosFloat32);
}
public bool Equals(CosmosFloat32 cosmosFloat32) => this.GetValue() == cosmosFloat32.GetValue();
public bool Equals(CosmosFloat32 cosmosFloat32)
{
return this.GetValue() == cosmosFloat32.GetValue();
}
public override int GetHashCode() => (int)MurmurHash3.Hash32(this.GetValue(), 495253708);
public override int GetHashCode()
{
return (int)MurmurHash3.Hash32(this.GetValue(), 495253708);
}
public int CompareTo(CosmosFloat32 cosmosFloat32) => this.GetValue().CompareTo(cosmosFloat32.GetValue());
public int CompareTo(CosmosFloat32 cosmosFloat32)
{
return this.GetValue().CompareTo(cosmosFloat32.GetValue());
}
public override void WriteTo(IJsonWriter jsonWriter) => jsonWriter.WriteFloat32Value(this.GetValue());
public override void WriteTo(IJsonWriter jsonWriter)
{
jsonWriter.WriteFloat32Value(this.GetValue());
}
public static CosmosFloat32 Create(
IJsonNavigator jsonNavigator,
IJsonNavigatorNode jsonNavigatorNode) => new LazyCosmosFloat32(jsonNavigator, jsonNavigatorNode);
IJsonNavigatorNode jsonNavigatorNode)
{
return new LazyCosmosFloat32(jsonNavigator, jsonNavigatorNode);
}
public static CosmosFloat32 Create(float number) => new EagerCosmosFloat32(number);
public static CosmosFloat32 Create(float number)
{
return new EagerCosmosFloat32(number);
}
}
}

Просмотреть файл

@ -30,26 +30,56 @@ namespace Microsoft.Azure.Cosmos.CosmosElements.Numbers
public abstract double GetValue();
public override void Accept(ICosmosNumberVisitor cosmosNumberVisitor) => cosmosNumberVisitor.Visit(this);
public override void Accept(ICosmosNumberVisitor cosmosNumberVisitor)
{
cosmosNumberVisitor.Visit(this);
}
public override TResult Accept<TResult>(ICosmosNumberVisitor<TResult> cosmosNumberVisitor) => cosmosNumberVisitor.Visit(this);
public override TResult Accept<TResult>(ICosmosNumberVisitor<TResult> cosmosNumberVisitor)
{
return cosmosNumberVisitor.Visit(this);
}
public override TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input) => cosmosNumberVisitor.Visit(this, input);
public override TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input)
{
return cosmosNumberVisitor.Visit(this, input);
}
public override bool Equals(CosmosNumber cosmosNumber) => cosmosNumber is CosmosFloat64 cosmosFloat64 && this.Equals(cosmosFloat64);
public override bool Equals(CosmosNumber cosmosNumber)
{
return cosmosNumber is CosmosFloat64 cosmosFloat64 && this.Equals(cosmosFloat64);
}
public bool Equals(CosmosFloat64 cosmosFloat64) => this.GetValue() == cosmosFloat64.GetValue();
public bool Equals(CosmosFloat64 cosmosFloat64)
{
return this.GetValue() == cosmosFloat64.GetValue();
}
public override int GetHashCode() => (int)MurmurHash3.Hash32(this.GetValue(), 470975939);
public override int GetHashCode()
{
return (int)MurmurHash3.Hash32(this.GetValue(), 470975939);
}
public int CompareTo(CosmosFloat64 cosmosFloat64) => this.GetValue().CompareTo(cosmosFloat64.GetValue());
public int CompareTo(CosmosFloat64 cosmosFloat64)
{
return this.GetValue().CompareTo(cosmosFloat64.GetValue());
}
public override void WriteTo(IJsonWriter jsonWriter) => jsonWriter.WriteFloat64Value(this.GetValue());
public override void WriteTo(IJsonWriter jsonWriter)
{
jsonWriter.WriteFloat64Value(this.GetValue());
}
public static CosmosFloat64 Create(
IJsonNavigator jsonNavigator,
IJsonNavigatorNode jsonNavigatorNode) => new LazyCosmosFloat64(jsonNavigator, jsonNavigatorNode);
IJsonNavigatorNode jsonNavigatorNode)
{
return new LazyCosmosFloat64(jsonNavigator, jsonNavigatorNode);
}
public static CosmosFloat64 Create(double number) => new EagerCosmosFloat64(number);
public static CosmosFloat64 Create(double number)
{
return new EagerCosmosFloat64(number);
}
}
}

Просмотреть файл

@ -30,26 +30,56 @@ namespace Microsoft.Azure.Cosmos.CosmosElements.Numbers
public abstract short GetValue();
public override void Accept(ICosmosNumberVisitor cosmosNumberVisitor) => cosmosNumberVisitor.Visit(this);
public override void Accept(ICosmosNumberVisitor cosmosNumberVisitor)
{
cosmosNumberVisitor.Visit(this);
}
public override TResult Accept<TResult>(ICosmosNumberVisitor<TResult> cosmosNumberVisitor) => cosmosNumberVisitor.Visit(this);
public override TResult Accept<TResult>(ICosmosNumberVisitor<TResult> cosmosNumberVisitor)
{
return cosmosNumberVisitor.Visit(this);
}
public override TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input) => cosmosNumberVisitor.Visit(this, input);
public override TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input)
{
return cosmosNumberVisitor.Visit(this, input);
}
public override bool Equals(CosmosNumber cosmosNumber) => cosmosNumber is CosmosInt16 cosmosInt16 && this.Equals(cosmosInt16);
public override bool Equals(CosmosNumber cosmosNumber)
{
return cosmosNumber is CosmosInt16 cosmosInt16 && this.Equals(cosmosInt16);
}
public bool Equals(CosmosInt16 cosmosInt16) => this.GetValue() == cosmosInt16.GetValue();
public bool Equals(CosmosInt16 cosmosInt16)
{
return this.GetValue() == cosmosInt16.GetValue();
}
public override int GetHashCode() => (int)MurmurHash3.Hash32(this.GetValue(), 1176550641);
public override int GetHashCode()
{
return (int)MurmurHash3.Hash32(this.GetValue(), 1176550641);
}
public int CompareTo(CosmosInt16 cosmosInt16) => this.GetValue().CompareTo(cosmosInt16.GetValue());
public int CompareTo(CosmosInt16 cosmosInt16)
{
return this.GetValue().CompareTo(cosmosInt16.GetValue());
}
public override void WriteTo(IJsonWriter jsonWriter) => jsonWriter.WriteInt16Value(this.GetValue());
public override void WriteTo(IJsonWriter jsonWriter)
{
jsonWriter.WriteInt16Value(this.GetValue());
}
public static CosmosInt16 Create(
IJsonNavigator jsonNavigator,
IJsonNavigatorNode jsonNavigatorNode) => new LazyCosmosInt16(jsonNavigator, jsonNavigatorNode);
IJsonNavigatorNode jsonNavigatorNode)
{
return new LazyCosmosInt16(jsonNavigator, jsonNavigatorNode);
}
public static CosmosInt16 Create(short number) => new EagerCosmosInt16(number);
public static CosmosInt16 Create(short number)
{
return new EagerCosmosInt16(number);
}
}
}

Просмотреть файл

@ -30,26 +30,56 @@ namespace Microsoft.Azure.Cosmos.CosmosElements.Numbers
public abstract int GetValue();
public override void Accept(ICosmosNumberVisitor cosmosNumberVisitor) => cosmosNumberVisitor.Visit(this);
public override void Accept(ICosmosNumberVisitor cosmosNumberVisitor)
{
cosmosNumberVisitor.Visit(this);
}
public override TResult Accept<TResult>(ICosmosNumberVisitor<TResult> cosmosNumberVisitor) => cosmosNumberVisitor.Visit(this);
public override TResult Accept<TResult>(ICosmosNumberVisitor<TResult> cosmosNumberVisitor)
{
return cosmosNumberVisitor.Visit(this);
}
public override TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input) => cosmosNumberVisitor.Visit(this, input);
public override TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input)
{
return cosmosNumberVisitor.Visit(this, input);
}
public override bool Equals(CosmosNumber cosmosNumber) => cosmosNumber is CosmosInt32 cosmosInt32 && this.Equals(cosmosInt32);
public override bool Equals(CosmosNumber cosmosNumber)
{
return cosmosNumber is CosmosInt32 cosmosInt32 && this.Equals(cosmosInt32);
}
public bool Equals(CosmosInt32 cosmosInt32) => this.GetValue() == cosmosInt32.GetValue();
public bool Equals(CosmosInt32 cosmosInt32)
{
return this.GetValue() == cosmosInt32.GetValue();
}
public override int GetHashCode() => (int)MurmurHash3.Hash32(this.GetValue(), 1791401667);
public override int GetHashCode()
{
return (int)MurmurHash3.Hash32(this.GetValue(), 1791401667);
}
public int CompareTo(CosmosInt32 cosmosInt32) => this.GetValue().CompareTo(cosmosInt32.GetValue());
public int CompareTo(CosmosInt32 cosmosInt32)
{
return this.GetValue().CompareTo(cosmosInt32.GetValue());
}
public override void WriteTo(IJsonWriter jsonWriter) => jsonWriter.WriteInt32Value(this.GetValue());
public override void WriteTo(IJsonWriter jsonWriter)
{
jsonWriter.WriteInt32Value(this.GetValue());
}
public static CosmosInt32 Create(
IJsonNavigator jsonNavigator,
IJsonNavigatorNode jsonNavigatorNode) => new LazyCosmosInt32(jsonNavigator, jsonNavigatorNode);
IJsonNavigatorNode jsonNavigatorNode)
{
return new LazyCosmosInt32(jsonNavigator, jsonNavigatorNode);
}
public static CosmosInt32 Create(int number) => new EagerCosmosInt32(number);
public static CosmosInt32 Create(int number)
{
return new EagerCosmosInt32(number);
}
}
}

Просмотреть файл

@ -30,26 +30,56 @@ namespace Microsoft.Azure.Cosmos.CosmosElements.Numbers
public abstract long GetValue();
public override void Accept(ICosmosNumberVisitor cosmosNumberVisitor) => cosmosNumberVisitor.Visit(this);
public override void Accept(ICosmosNumberVisitor cosmosNumberVisitor)
{
cosmosNumberVisitor.Visit(this);
}
public override TResult Accept<TResult>(ICosmosNumberVisitor<TResult> cosmosNumberVisitor) => cosmosNumberVisitor.Visit(this);
public override TResult Accept<TResult>(ICosmosNumberVisitor<TResult> cosmosNumberVisitor)
{
return cosmosNumberVisitor.Visit(this);
}
public override TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input) => cosmosNumberVisitor.Visit(this, input);
public override TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input)
{
return cosmosNumberVisitor.Visit(this, input);
}
public override bool Equals(CosmosNumber cosmosNumber) => cosmosNumber is CosmosInt64 cosmosInt64 && this.Equals(cosmosInt64);
public override bool Equals(CosmosNumber cosmosNumber)
{
return cosmosNumber is CosmosInt64 cosmosInt64 && this.Equals(cosmosInt64);
}
public bool Equals(CosmosInt64 cosmosInt64) => this.GetValue() == cosmosInt64.GetValue();
public bool Equals(CosmosInt64 cosmosInt64)
{
return this.GetValue() == cosmosInt64.GetValue();
}
public override int GetHashCode() => (int)MurmurHash3.Hash32(this.GetValue(), 2562566505);
public override int GetHashCode()
{
return (int)MurmurHash3.Hash32(this.GetValue(), 2562566505);
}
public int CompareTo(CosmosInt64 cosmosInt64) => this.GetValue().CompareTo(cosmosInt64.GetValue());
public int CompareTo(CosmosInt64 cosmosInt64)
{
return this.GetValue().CompareTo(cosmosInt64.GetValue());
}
public override void WriteTo(IJsonWriter jsonWriter) => jsonWriter.WriteInt64Value(this.GetValue());
public override void WriteTo(IJsonWriter jsonWriter)
{
jsonWriter.WriteInt64Value(this.GetValue());
}
public static CosmosInt64 Create(
IJsonNavigator jsonNavigator,
IJsonNavigatorNode jsonNavigatorNode) => new LazyCosmosInt64(jsonNavigator, jsonNavigatorNode);
IJsonNavigatorNode jsonNavigatorNode)
{
return new LazyCosmosInt64(jsonNavigator, jsonNavigatorNode);
}
public static CosmosInt64 Create(long number) => new EagerCosmosInt64(number);
public static CosmosInt64 Create(long number)
{
return new EagerCosmosInt64(number);
}
}
}

Просмотреть файл

@ -30,26 +30,56 @@ namespace Microsoft.Azure.Cosmos.CosmosElements.Numbers
public abstract sbyte GetValue();
public override void Accept(ICosmosNumberVisitor cosmosNumberVisitor) => cosmosNumberVisitor.Visit(this);
public override void Accept(ICosmosNumberVisitor cosmosNumberVisitor)
{
cosmosNumberVisitor.Visit(this);
}
public override TResult Accept<TResult>(ICosmosNumberVisitor<TResult> cosmosNumberVisitor) => cosmosNumberVisitor.Visit(this);
public override TResult Accept<TResult>(ICosmosNumberVisitor<TResult> cosmosNumberVisitor)
{
return cosmosNumberVisitor.Visit(this);
}
public override TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input) => cosmosNumberVisitor.Visit(this, input);
public override TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input)
{
return cosmosNumberVisitor.Visit(this, input);
}
public override bool Equals(CosmosNumber cosmosNumber) => cosmosNumber is CosmosInt8 cosmosInt8 && this.Equals(cosmosInt8);
public override bool Equals(CosmosNumber cosmosNumber)
{
return cosmosNumber is CosmosInt8 cosmosInt8 && this.Equals(cosmosInt8);
}
public bool Equals(CosmosInt8 cosmosInt8) => this.GetValue() == cosmosInt8.GetValue();
public bool Equals(CosmosInt8 cosmosInt8)
{
return this.GetValue() == cosmosInt8.GetValue();
}
public override int GetHashCode() => (int)MurmurHash3.Hash32(this.GetValue(), 1301790982);
public override int GetHashCode()
{
return (int)MurmurHash3.Hash32(this.GetValue(), 1301790982);
}
public int CompareTo(CosmosInt8 cosmosInt8) => this.GetValue().CompareTo(cosmosInt8.GetValue());
public int CompareTo(CosmosInt8 cosmosInt8)
{
return this.GetValue().CompareTo(cosmosInt8.GetValue());
}
public override void WriteTo(IJsonWriter jsonWriter) => jsonWriter.WriteInt8Value(this.GetValue());
public override void WriteTo(IJsonWriter jsonWriter)
{
jsonWriter.WriteInt8Value(this.GetValue());
}
public static CosmosInt8 Create(
IJsonNavigator jsonNavigator,
IJsonNavigatorNode jsonNavigatorNode) => new LazyCosmosInt8(jsonNavigator, jsonNavigatorNode);
IJsonNavigatorNode jsonNavigatorNode)
{
return new LazyCosmosInt8(jsonNavigator, jsonNavigatorNode);
}
public static CosmosInt8 Create(sbyte number) => new EagerCosmosInt8(number);
public static CosmosInt8 Create(sbyte number)
{
return new EagerCosmosInt8(number);
}
}
}

Просмотреть файл

@ -30,26 +30,56 @@ namespace Microsoft.Azure.Cosmos.CosmosElements.Numbers
public abstract Number64 GetValue();
public override void Accept(ICosmosNumberVisitor cosmosNumberVisitor) => cosmosNumberVisitor.Visit(this);
public override void Accept(ICosmosNumberVisitor cosmosNumberVisitor)
{
cosmosNumberVisitor.Visit(this);
}
public override TResult Accept<TResult>(ICosmosNumberVisitor<TResult> cosmosNumberVisitor) => cosmosNumberVisitor.Visit(this);
public override TResult Accept<TResult>(ICosmosNumberVisitor<TResult> cosmosNumberVisitor)
{
return cosmosNumberVisitor.Visit(this);
}
public override TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input) => cosmosNumberVisitor.Visit(this, input);
public override TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input)
{
return cosmosNumberVisitor.Visit(this, input);
}
public override bool Equals(CosmosNumber cosmosNumber) => cosmosNumber is CosmosNumber64 cosmosNumber64 && this.Equals(cosmosNumber64);
public override bool Equals(CosmosNumber cosmosNumber)
{
return cosmosNumber is CosmosNumber64 cosmosNumber64 && this.Equals(cosmosNumber64);
}
public bool Equals(CosmosNumber64 cosmosNumber64) => this.GetValue() == cosmosNumber64.GetValue();
public bool Equals(CosmosNumber64 cosmosNumber64)
{
return this.GetValue() == cosmosNumber64.GetValue();
}
public override int GetHashCode() => (int)MurmurHash3.Hash32(Number64.ToDoubleEx(this.GetValue()), 1943952435);
public override int GetHashCode()
{
return (int)MurmurHash3.Hash32(Number64.ToDoubleEx(this.GetValue()), 1943952435);
}
public int CompareTo(CosmosNumber64 cosmosNumber64) => this.GetValue().CompareTo(cosmosNumber64.GetValue());
public int CompareTo(CosmosNumber64 cosmosNumber64)
{
return this.GetValue().CompareTo(cosmosNumber64.GetValue());
}
public override void WriteTo(IJsonWriter jsonWriter) => jsonWriter.WriteNumber64Value(this.GetValue());
public override void WriteTo(IJsonWriter jsonWriter)
{
jsonWriter.WriteNumber64Value(this.GetValue());
}
public static CosmosNumber64 Create(
IJsonNavigator jsonNavigator,
IJsonNavigatorNode jsonNavigatorNode) => new LazyCosmosNumber64(jsonNavigator, jsonNavigatorNode);
IJsonNavigatorNode jsonNavigatorNode)
{
return new LazyCosmosNumber64(jsonNavigator, jsonNavigatorNode);
}
public static CosmosNumber64 Create(Number64 number) => new EagerCosmosNumber64(number);
public static CosmosNumber64 Create(Number64 number)
{
return new EagerCosmosNumber64(number);
}
}
}

Просмотреть файл

@ -30,26 +30,56 @@ namespace Microsoft.Azure.Cosmos.CosmosElements.Numbers
public abstract uint GetValue();
public override void Accept(ICosmosNumberVisitor cosmosNumberVisitor) => cosmosNumberVisitor.Visit(this);
public override void Accept(ICosmosNumberVisitor cosmosNumberVisitor)
{
cosmosNumberVisitor.Visit(this);
}
public override TResult Accept<TResult>(ICosmosNumberVisitor<TResult> cosmosNumberVisitor) => cosmosNumberVisitor.Visit(this);
public override TResult Accept<TResult>(ICosmosNumberVisitor<TResult> cosmosNumberVisitor)
{
return cosmosNumberVisitor.Visit(this);
}
public override TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input) => cosmosNumberVisitor.Visit(this, input);
public override TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input)
{
return cosmosNumberVisitor.Visit(this, input);
}
public override bool Equals(CosmosNumber cosmosNumber) => cosmosNumber is CosmosUInt32 cosmosUInt32 && this.Equals(cosmosUInt32);
public override bool Equals(CosmosNumber cosmosNumber)
{
return cosmosNumber is CosmosUInt32 cosmosUInt32 && this.Equals(cosmosUInt32);
}
public bool Equals(CosmosUInt32 cosmosUInt32) => this.GetValue() == cosmosUInt32.GetValue();
public bool Equals(CosmosUInt32 cosmosUInt32)
{
return this.GetValue() == cosmosUInt32.GetValue();
}
public override int GetHashCode() => (int)MurmurHash3.Hash32(this.GetValue(), 3771427877);
public override int GetHashCode()
{
return (int)MurmurHash3.Hash32(this.GetValue(), 3771427877);
}
public int CompareTo(CosmosUInt32 cosmosUInt32) => this.GetValue().CompareTo(cosmosUInt32.GetValue());
public int CompareTo(CosmosUInt32 cosmosUInt32)
{
return this.GetValue().CompareTo(cosmosUInt32.GetValue());
}
public override void WriteTo(IJsonWriter jsonWriter) => jsonWriter.WriteUInt32Value(this.GetValue());
public override void WriteTo(IJsonWriter jsonWriter)
{
jsonWriter.WriteUInt32Value(this.GetValue());
}
public static CosmosUInt32 Create(
IJsonNavigator jsonNavigator,
IJsonNavigatorNode jsonNavigatorNode) => new LazyCosmosUInt32(jsonNavigator, jsonNavigatorNode);
IJsonNavigatorNode jsonNavigatorNode)
{
return new LazyCosmosUInt32(jsonNavigator, jsonNavigatorNode);
}
public static CosmosUInt32 Create(uint number) => new EagerCosmosUInt32(number);
public static CosmosUInt32 Create(uint number)
{
return new EagerCosmosUInt32(number);
}
}
}

Просмотреть файл

@ -73,13 +73,7 @@ namespace Microsoft.Azure.Cosmos
}
}
public override bool CanWrite
{
get
{
return false;
}
}
public override bool CanWrite => false;
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{

Просмотреть файл

@ -7,12 +7,9 @@ namespace Microsoft.Azure.Cosmos
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using Microsoft.Azure.Cosmos.Diagnostics;
using Microsoft.Azure.Documents;
using Newtonsoft.Json;
internal sealed class CosmosClientSideRequestStatistics : CosmosDiagnosticsInternal, IClientSideRequestStatistics
{
@ -44,7 +41,7 @@ namespace Microsoft.Azure.Cosmos
private Dictionary<string, AddressResolutionStatistics> EndpointToAddressResolutionStatistics { get; }
private Dictionary<int, DateTime> RecordRequestHashCodeToStartTime = new Dictionary<int, DateTime>();
private readonly Dictionary<int, DateTime> RecordRequestHashCodeToStartTime = new Dictionary<int, DateTime>();
public List<Uri> ContactedReplicas { get; set; }

Просмотреть файл

@ -738,7 +738,7 @@ namespace Microsoft.Azure.Cosmos
/// ]]>
/// </code>
/// </example>
public Task OpenAsync(CancellationToken cancellationToken = default(CancellationToken))
public Task OpenAsync(CancellationToken cancellationToken = default)
{
return TaskHelper.InlineIfPossibleAsync(() => this.OpenPrivateInlineAsync(cancellationToken), null, cancellationToken);
}
@ -1901,7 +1901,7 @@ namespace Microsoft.Azure.Cosmos
/// <seealso cref="System.Threading.Tasks.Task"/>
public Task<ResourceResponse<Document>> CreateDocumentAsync(string documentsFeedOrDatabaseLink,
object document, Documents.Client.RequestOptions options = null, bool disableAutomaticIdGeneration = false,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
// This call is to just run CreateDocumentInlineAsync in a SynchronizationContext aware environment
return TaskHelper.InlineIfPossible(() => this.CreateDocumentInlineAsync(documentsFeedOrDatabaseLink, document, options, disableAutomaticIdGeneration, cancellationToken), null, cancellationToken);
@ -2798,7 +2798,7 @@ namespace Microsoft.Azure.Cosmos
/// <seealso cref="Microsoft.Azure.Documents.Client.RequestOptions"/>
/// <seealso cref="Microsoft.Azure.Documents.Client.ResourceResponse{T}"/>
/// <seealso cref="System.Threading.Tasks.Task"/>
public Task<ResourceResponse<Document>> DeleteDocumentAsync(string documentLink, Documents.Client.RequestOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
public Task<ResourceResponse<Document>> DeleteDocumentAsync(string documentLink, Documents.Client.RequestOptions options = null, CancellationToken cancellationToken = default)
{
IDocumentClientRetryPolicy retryPolicyInstance = this.ResetSessionTokenRetryPolicy.GetRequestPolicy();
return TaskHelper.InlineIfPossible(() => this.DeleteDocumentPrivateAsync(documentLink, options, retryPolicyInstance, cancellationToken), retryPolicyInstance, cancellationToken);
@ -3273,7 +3273,7 @@ namespace Microsoft.Azure.Cosmos
/// <seealso cref="Microsoft.Azure.Documents.Client.RequestOptions"/>
/// <seealso cref="Microsoft.Azure.Documents.Client.ResourceResponse{T}"/>
/// <seealso cref="System.Threading.Tasks.Task"/>
public Task<ResourceResponse<Document>> ReplaceDocumentAsync(string documentLink, object document, Documents.Client.RequestOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
public Task<ResourceResponse<Document>> ReplaceDocumentAsync(string documentLink, object document, Documents.Client.RequestOptions options = null, CancellationToken cancellationToken = default)
{
// This call is to just run ReplaceDocumentInlineAsync in a SynchronizationContext aware environment
return TaskHelper.InlineIfPossible(() => this.ReplaceDocumentInlineAsync(documentLink, document, options, cancellationToken), null, cancellationToken);
@ -3348,7 +3348,7 @@ namespace Microsoft.Azure.Cosmos
/// <seealso cref="Microsoft.Azure.Documents.Client.RequestOptions"/>
/// <seealso cref="Microsoft.Azure.Documents.Client.ResourceResponse{T}"/>
/// <seealso cref="System.Threading.Tasks.Task"/>
public Task<ResourceResponse<Document>> ReplaceDocumentAsync(Document document, Documents.Client.RequestOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
public Task<ResourceResponse<Document>> ReplaceDocumentAsync(Document document, Documents.Client.RequestOptions options = null, CancellationToken cancellationToken = default)
{
IDocumentClientRetryPolicy retryPolicyInstance = this.ResetSessionTokenRetryPolicy.GetRequestPolicy();
return TaskHelper.InlineIfPossible(() => this.ReplaceDocumentPrivateAsync(
@ -3871,7 +3871,7 @@ namespace Microsoft.Azure.Cosmos
/// <seealso cref="Microsoft.Azure.Documents.Client.ResourceResponse{T}"/>
/// <seealso cref="System.Threading.Tasks.Task"/>
/// <seealso cref="System.Uri"/>
public Task<ResourceResponse<Document>> ReadDocumentAsync(string documentLink, Documents.Client.RequestOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
public Task<ResourceResponse<Document>> ReadDocumentAsync(string documentLink, Documents.Client.RequestOptions options = null, CancellationToken cancellationToken = default)
{
IDocumentClientRetryPolicy retryPolicyInstance = this.ResetSessionTokenRetryPolicy.GetRequestPolicy();
return TaskHelper.InlineIfPossible(
@ -3953,7 +3953,7 @@ namespace Microsoft.Azure.Cosmos
/// <seealso cref="Microsoft.Azure.Documents.Client.DocumentResponse{T}"/>
/// <seealso cref="System.Threading.Tasks.Task"/>
/// <seealso cref="System.Uri"/>
public Task<DocumentResponse<T>> ReadDocumentAsync<T>(string documentLink, Documents.Client.RequestOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
public Task<DocumentResponse<T>> ReadDocumentAsync<T>(string documentLink, Documents.Client.RequestOptions options = null, CancellationToken cancellationToken = default)
{
IDocumentClientRetryPolicy retryPolicyInstance = this.ResetSessionTokenRetryPolicy.GetRequestPolicy();
return TaskHelper.InlineIfPossible(
@ -5151,7 +5151,7 @@ namespace Microsoft.Azure.Cosmos
/// <seealso cref="Microsoft.Azure.Documents.Client.RequestOptions"/>
/// <seealso cref="Microsoft.Azure.Documents.Client.ResourceResponse{T}"/>
/// <seealso cref="System.Threading.Tasks.Task"/>
public Task<DocumentFeedResponse<dynamic>> ReadDocumentFeedAsync(string documentsLink, FeedOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
public Task<DocumentFeedResponse<dynamic>> ReadDocumentFeedAsync(string documentsLink, FeedOptions options = null, CancellationToken cancellationToken = default)
{
return TaskHelper.InlineIfPossible(() => this.ReadDocumentFeedInlineAsync(documentsLink, options, cancellationToken), null, cancellationToken);
}
@ -5526,7 +5526,7 @@ namespace Microsoft.Azure.Cosmos
/// <seealso cref="System.Threading.Tasks.Task"/>
public Task<StoredProcedureResponse<TValue>> ExecuteStoredProcedureAsync<TValue>(string storedProcedureLink, params dynamic[] procedureParams)
{
return this.ExecuteStoredProcedureAsync<TValue>(storedProcedureLink, null, default(CancellationToken), procedureParams);
return this.ExecuteStoredProcedureAsync<TValue>(storedProcedureLink, null, default, procedureParams);
}
/// <summary>
@ -5565,7 +5565,7 @@ namespace Microsoft.Azure.Cosmos
storedProcedureLink,
options,
retryPolicyInstance,
default(CancellationToken),
default,
procedureParams),
retryPolicyInstance);
}
@ -5843,7 +5843,7 @@ namespace Microsoft.Azure.Cosmos
/// <seealso cref="Microsoft.Azure.Documents.Client.RequestOptions"/>
/// <seealso cref="Microsoft.Azure.Documents.Client.ResourceResponse{T}"/>
/// <seealso cref="System.Threading.Tasks.Task"/>
public Task<ResourceResponse<Document>> UpsertDocumentAsync(string documentsFeedOrDatabaseLink, object document, Documents.Client.RequestOptions options = null, bool disableAutomaticIdGeneration = false, CancellationToken cancellationToken = default(CancellationToken))
public Task<ResourceResponse<Document>> UpsertDocumentAsync(string documentsFeedOrDatabaseLink, object document, Documents.Client.RequestOptions options = null, bool disableAutomaticIdGeneration = false, CancellationToken cancellationToken = default)
{
// This call is to just run UpsertDocumentInlineAsync in a SynchronizationContext aware environment
return TaskHelper.InlineIfPossible(() => this.UpsertDocumentInlineAsync(documentsFeedOrDatabaseLink, document, options, disableAutomaticIdGeneration, cancellationToken), null, cancellationToken);
@ -6543,7 +6543,7 @@ namespace Microsoft.Azure.Cosmos
internal Task<DocumentServiceResponse> CreateAsync(
DocumentServiceRequest request,
IDocumentClientRetryPolicy retryPolicy,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (request == null)
{
@ -6556,7 +6556,7 @@ namespace Microsoft.Azure.Cosmos
internal Task<DocumentServiceResponse> UpdateAsync(
DocumentServiceRequest request,
IDocumentClientRetryPolicy retryPolicy,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (request == null)
{
@ -6569,7 +6569,7 @@ namespace Microsoft.Azure.Cosmos
internal Task<DocumentServiceResponse> ReadAsync(
DocumentServiceRequest request,
IDocumentClientRetryPolicy retryPolicy,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (request == null)
{
@ -6582,7 +6582,7 @@ namespace Microsoft.Azure.Cosmos
internal Task<DocumentServiceResponse> ReadFeedAsync(
DocumentServiceRequest request,
IDocumentClientRetryPolicy retryPolicy,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (request == null)
{
@ -6595,7 +6595,7 @@ namespace Microsoft.Azure.Cosmos
internal Task<DocumentServiceResponse> DeleteAsync(
DocumentServiceRequest request,
IDocumentClientRetryPolicy retryPolicy,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (request == null)
{
@ -6608,7 +6608,7 @@ namespace Microsoft.Azure.Cosmos
internal Task<DocumentServiceResponse> ExecuteProcedureAsync(
DocumentServiceRequest request,
IDocumentClientRetryPolicy retryPolicy,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (request == null)
{
@ -6621,7 +6621,7 @@ namespace Microsoft.Azure.Cosmos
internal Task<DocumentServiceResponse> ExecuteQueryAsync(
DocumentServiceRequest request,
IDocumentClientRetryPolicy retryPolicy,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (request == null)
{
@ -6634,7 +6634,7 @@ namespace Microsoft.Azure.Cosmos
internal Task<DocumentServiceResponse> UpsertAsync(
DocumentServiceRequest request,
IDocumentClientRetryPolicy retryPolicy,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
if (request == null)
{
@ -6671,7 +6671,7 @@ namespace Microsoft.Azure.Cosmos
return this.GetDatabaseAccountPrivateAsync(serviceEndpoint, cancellationToken);
}
private async Task<AccountProperties> GetDatabaseAccountPrivateAsync(Uri serviceEndpoint, CancellationToken cancellationToken = default(CancellationToken))
private async Task<AccountProperties> GetDatabaseAccountPrivateAsync(Uri serviceEndpoint, CancellationToken cancellationToken = default)
{
await this.EnsureValidClientAsync();
GatewayStoreModel gatewayModel = this.GatewayStoreModel as GatewayStoreModel;

Просмотреть файл

@ -44,6 +44,9 @@ namespace Microsoft.Azure.Cosmos
/// </summary>
/// <param name="partitionKey">The partition key value to create a feed range from.</param>
/// <returns>The feed range that spans the partition.</returns>
public static FeedRange FromPartitionKey(PartitionKey partitionKey) => new FeedRangePartitionKey(partitionKey);
public static FeedRange FromPartitionKey(PartitionKey partitionKey)
{
return new FeedRangePartitionKey(partitionKey);
}
}
}

Просмотреть файл

@ -32,7 +32,10 @@ namespace Microsoft.Azure.Cosmos
public override Task<List<Documents.Routing.Range<string>>> GetEffectiveRangesAsync(
IRoutingMapProvider routingMapProvider,
string containerRid,
Documents.PartitionKeyDefinition partitionKeyDefinition) => Task.FromResult(new List<Documents.Routing.Range<string>>() { this.Range });
Documents.PartitionKeyDefinition partitionKeyDefinition)
{
return Task.FromResult(new List<Documents.Routing.Range<string>>() { this.Range });
}
public override async Task<IEnumerable<string>> GetPartitionKeyRangesAsync(
IRoutingMapProvider routingMapProvider,
@ -44,12 +47,21 @@ namespace Microsoft.Azure.Cosmos
return partitionKeyRanges.Select(partitionKeyRange => partitionKeyRange.Id);
}
public override void Accept(IFeedRangeVisitor visitor) => visitor.Visit(this);
public override void Accept(IFeedRangeVisitor visitor)
{
visitor.Visit(this);
}
public override Task<TResult> AcceptAsync<TResult>(
IFeedRangeAsyncVisitor<TResult> visitor,
CancellationToken cancellationToken = default) => visitor.VisitAsync(this, cancellationToken);
CancellationToken cancellationToken = default)
{
return visitor.VisitAsync(this, cancellationToken);
}
public override string ToString() => this.Range.ToString();
public override string ToString()
{
return this.Range.ToString();
}
}
}

Просмотреть файл

@ -31,7 +31,10 @@ namespace Microsoft.Azure.Cosmos
public abstract override string ToString();
public override string ToJsonString() => JsonConvert.SerializeObject(this);
public override string ToJsonString()
{
return JsonConvert.SerializeObject(this);
}
public static bool TryParse(
string jsonString,

Просмотреть файл

@ -24,12 +24,15 @@ namespace Microsoft.Azure.Cosmos
public override Task<List<Documents.Routing.Range<string>>> GetEffectiveRangesAsync(
IRoutingMapProvider routingMapProvider,
string containerRid,
Documents.PartitionKeyDefinition partitionKeyDefinition) => Task.FromResult(
new List<Documents.Routing.Range<string>>
{
Documents.PartitionKeyDefinition partitionKeyDefinition)
{
return Task.FromResult(
new List<Documents.Routing.Range<string>>
{
Documents.Routing.Range<string>.GetPointRange(
this.PartitionKey.InternalKey.GetEffectivePartitionKeyString(partitionKeyDefinition))
});
});
}
public override async Task<IEnumerable<string>> GetPartitionKeyRangesAsync(
IRoutingMapProvider routingMapProvider,
@ -42,12 +45,21 @@ namespace Microsoft.Azure.Cosmos
return new List<string>() { range.Id };
}
public override void Accept(IFeedRangeVisitor visitor) => visitor.Visit(this);
public override void Accept(IFeedRangeVisitor visitor)
{
visitor.Visit(this);
}
public override Task<TResult> AcceptAsync<TResult>(
IFeedRangeAsyncVisitor<TResult> visitor,
CancellationToken cancellationToken = default) => visitor.VisitAsync(this, cancellationToken);
CancellationToken cancellationToken = default)
{
return visitor.VisitAsync(this, cancellationToken);
}
public override string ToString() => this.PartitionKey.InternalKey.ToJsonString();
public override string ToString()
{
return this.PartitionKey.InternalKey.ToJsonString();
}
}
}

Просмотреть файл

@ -4,7 +4,6 @@
namespace Microsoft.Azure.Cosmos
{
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
@ -74,12 +73,21 @@ namespace Microsoft.Azure.Cosmos
return Task.FromResult(partitionKeyRanges);
}
public override void Accept(IFeedRangeVisitor visitor) => visitor.Visit(this);
public override void Accept(IFeedRangeVisitor visitor)
{
visitor.Visit(this);
}
public override Task<TResult> AcceptAsync<TResult>(
IFeedRangeAsyncVisitor<TResult> visitor,
CancellationToken cancellationToken = default) => visitor.VisitAsync(this, cancellationToken);
CancellationToken cancellationToken = default)
{
return visitor.VisitAsync(this, cancellationToken);
}
public override string ToString() => this.PartitionKeyRangeId;
public override string ToString()
{
return this.PartitionKeyRangeId;
}
}
}

Просмотреть файл

@ -4,10 +4,6 @@
namespace Microsoft.Azure.Cosmos
{
using System;
using System.Collections.Generic;
using System.Text;
internal interface IFeedRangeContinuationVisitor
{
public void Visit(FeedRangeCompositeContinuation feedRangeCompositeContinuation);

Просмотреть файл

@ -146,7 +146,7 @@ namespace Microsoft.Azure.Cosmos.Fluent
this.clientOptions.ApplicationRegion = applicationRegion;
return this;
}
/// <summary>
/// Set the preferred regions for geo-replicated database accounts in the Azure Cosmos DB service.
/// </summary>

Просмотреть файл

@ -13,7 +13,7 @@ namespace Microsoft.Azure.Cosmos.Fluent
where T : ContainerDefinition<T>
{
private readonly string containerName;
private string partitionKeyPath;
private readonly string partitionKeyPath;
private int? defaultTimeToLive;
private IndexingPolicy indexingPolicy;
private string timeToLivePropertyPath;

Просмотреть файл

@ -65,7 +65,7 @@ namespace Microsoft.Azure.Cosmos
HttpTransportClient.GetResourceFeedUri(resourceOperation.resourceType, baseAddress, request) :
HttpTransportClient.GetResourceEntryUri(resourceOperation.resourceType, baseAddress, request);
using (HttpResponseMessage responseMessage = await this.InvokeClientAsync(request, resourceOperation.resourceType, physicalAddress, default(CancellationToken)))
using (HttpResponseMessage responseMessage = await this.InvokeClientAsync(request, resourceOperation.resourceType, physicalAddress, default))
{
return await HttpTransportClient.ProcessHttpResponse(request.ResourceAddress, string.Empty, responseMessage, physicalAddress, request);
}
@ -75,7 +75,7 @@ namespace Microsoft.Azure.Cosmos
internal Task<HttpResponseMessage> SendHttpAsync(
Func<ValueTask<HttpRequestMessage>> requestMessage,
ResourceType resourceType,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
return this.httpClient.SendHttpAsync(
createRequestMessageAsync: requestMessage,

Просмотреть файл

@ -47,7 +47,7 @@ namespace Microsoft.Azure.Cosmos
serializerSettings);
}
public virtual async Task<DocumentServiceResponse> ProcessMessageAsync(DocumentServiceRequest request, CancellationToken cancellationToken = default(CancellationToken))
public virtual async Task<DocumentServiceResponse> ProcessMessageAsync(DocumentServiceRequest request, CancellationToken cancellationToken = default)
{
GatewayStoreModel.ApplySessionToken(
request,
@ -76,7 +76,7 @@ namespace Microsoft.Azure.Cosmos
return response;
}
public virtual async Task<AccountProperties> GetDatabaseAccountAsync(Func<ValueTask<HttpRequestMessage>> requestMessage, CancellationToken cancellationToken = default(CancellationToken))
public virtual async Task<AccountProperties> GetDatabaseAccountAsync(Func<ValueTask<HttpRequestMessage>> requestMessage, CancellationToken cancellationToken = default)
{
AccountProperties databaseAccount = null;

Просмотреть файл

@ -11,7 +11,6 @@ namespace Microsoft.Azure.Cosmos.Handlers
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Common;
using Microsoft.Azure.Cosmos.Query;
using Microsoft.Azure.Cosmos.Query.Core.ContinuationTokens;
using Microsoft.Azure.Cosmos.Routing;
using Microsoft.Azure.Documents;
@ -29,7 +28,7 @@ namespace Microsoft.Azure.Cosmos.Handlers
internal class PartitionKeyRangeHandler : RequestHandler
{
private readonly CosmosClient client;
private PartitionRoutingHelper partitionRoutingHelper;
private readonly PartitionRoutingHelper partitionRoutingHelper;
public PartitionKeyRangeHandler(CosmosClient client, PartitionRoutingHelper partitionRoutingHelper = null)
{
if (client == null)

Просмотреть файл

@ -5,10 +5,8 @@
namespace Microsoft.Azure.Cosmos
{
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Diagnostics;
/// <summary>
/// Abstraction which allows defining of custom message handlers.

Просмотреть файл

@ -11,7 +11,6 @@ namespace Microsoft.Azure.Cosmos.Handlers
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Diagnostics;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Routing;
@ -20,11 +19,11 @@ namespace Microsoft.Azure.Cosmos.Handlers
/// </summary>
internal class RequestInvokerHandler : RequestHandler
{
private static (bool, ResponseMessage) clientIsValid = (false, null);
private readonly CosmosClient client;
private Cosmos.ConsistencyLevel? AccountConsistencyLevel = null;
private Cosmos.ConsistencyLevel? RequestedClientConsistencyLevel;
private readonly Cosmos.ConsistencyLevel? RequestedClientConsistencyLevel;
private static readonly HttpMethod httpPatchMethod = new HttpMethod(HttpConstants.HttpMethods.Patch);
private Cosmos.ConsistencyLevel? AccountConsistencyLevel = null;
private static (bool, ResponseMessage) clientIsValid = (false, null);
public RequestInvokerHandler(
CosmosClient client,

Просмотреть файл

@ -8,7 +8,6 @@ namespace Microsoft.Azure.Cosmos
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;
using Microsoft.Azure.Cosmos.Resource.CosmosExceptions;
using Microsoft.Azure.Documents;

Просмотреть файл

@ -9,7 +9,6 @@ namespace Microsoft.Azure.Cosmos.Handlers
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Diagnostics;
using Microsoft.Azure.Documents;
//TODO: write unit test for this handler

Просмотреть файл

@ -10,7 +10,6 @@ namespace Microsoft.Azure.Cosmos
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Reflection;
using Microsoft.Azure.Documents.Collections;
/// <summary>
@ -62,18 +61,14 @@ namespace Microsoft.Azure.Cosmos
{
get
{
string value;
if (!this.TryGetValue(headerName, out value))
if (!this.TryGetValue(headerName, out string value))
{
return null;
}
return value;
}
set
{
this.Set(headerName, value);
}
set => this.Set(headerName, value);
}
public void Set(string key, string value)
@ -180,7 +175,7 @@ namespace Microsoft.Azure.Cosmos
if (string.IsNullOrEmpty(value))
{
return default(T);
return default;
}
if (typeof(T) == typeof(double))

Просмотреть файл

@ -38,10 +38,7 @@ namespace Microsoft.Azure.Cosmos
return base.ContinuationToken;
}
internal set
{
throw new InvalidOperationException("To prevent the different aggregate context from impacting each other only allow updating the continuation token via clone method.");
}
internal set => throw new InvalidOperationException("To prevent the different aggregate context from impacting each other only allow updating the continuation token via clone method.");
}
internal virtual string ContainerRid { get; }

Просмотреть файл

@ -10,10 +10,8 @@ namespace Microsoft.Azure.Cosmos
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Resource.CosmosExceptions;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Collections;
@ -245,7 +243,11 @@ namespace Microsoft.Azure.Cosmos
}
};
HttpRequestMessage GetHttpRequestMessage() => requestMessage;
HttpRequestMessage GetHttpRequestMessage()
{
return requestMessage;
}
return BackoffRetryUtility<HttpResponseMessage>.ExecuteAsync(
callbackMethod: funcDelegate,
retryPolicy: new TransientHttpClientRetryPolicy(

Просмотреть файл

@ -4,8 +4,6 @@
namespace Microsoft.Azure.Cosmos
{
using System;
using System.IO;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Collections;

Просмотреть файл

@ -10,6 +10,6 @@ namespace Microsoft.Azure.Cosmos
internal interface IDocumentClientInternal : IDocumentClient
{
Task<AccountProperties> GetDatabaseAccountInternalAsync(Uri serviceEndpoint, CancellationToken cancellationToken = default(CancellationToken));
Task<AccountProperties> GetDatabaseAccountInternalAsync(Uri serviceEndpoint, CancellationToken cancellationToken = default);
}
}

Просмотреть файл

@ -39,8 +39,8 @@ namespace Microsoft.Azure.Cosmos.Json
/// <returns>The reversed char.</returns>
public static char Reverse(char value)
{
ushort b1 = (ushort)(((ushort)value >> 0) & 0xff);
ushort b2 = (ushort)(((ushort)value >> 8) & 0xff);
ushort b1 = (ushort)((value >> 0) & 0xff);
ushort b2 = (ushort)((value >> 8) & 0xff);
return (char)((b1 << 8) | (b2 << 0));
}

Просмотреть файл

@ -5,8 +5,6 @@ namespace Microsoft.Azure.Cosmos.Json
{
using System;
using System.Collections.Generic;
using Microsoft.Azure.Cosmos.Core.Utf8;
using Microsoft.Azure.Cosmos.Query.Core;
/// <summary>
/// JsonNavigator interface for classes that can navigate jsons.

Просмотреть файл

@ -4,7 +4,6 @@
namespace Microsoft.Azure.Cosmos.Json
{
using System;
using System.Collections.Generic;
/// <summary>
/// Interface for all JsonReaders that know how to read jsons.

Просмотреть файл

@ -5,8 +5,6 @@
namespace Microsoft.Azure.Cosmos.Json
{
using System;
using System.Collections.Generic;
using System.Text;
internal interface IJsonTextWriterExtensions : IJsonWriter
{

Просмотреть файл

@ -4,7 +4,6 @@
namespace Microsoft.Azure.Cosmos.Json
{
using System;
using Antlr4.Runtime.Tree;
#if INTERNAL
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member

Просмотреть файл

@ -4,8 +4,6 @@
namespace Microsoft.Azure.Cosmos.Json.Interop
{
using System;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
/// <summary>
@ -179,9 +177,9 @@ namespace Microsoft.Azure.Cosmos.Json.Interop
}
/// <summary>
/// Reads the next JSON token from the source as a <see cref="Byte"/>[].
/// Reads the next JSON token from the source as a <see cref="byte"/>[].
/// </summary>
/// <returns>A <see cref="Byte"/>[] or <c>null</c> if the next JSON token is null. This method will return <c>null</c> at the end of an array.</returns>
/// <returns>A <see cref="byte"/>[] or <c>null</c> if the next JSON token is null. This method will return <c>null</c> at the end of an array.</returns>
public override byte[] ReadAsBytes()
{
throw new NotImplementedException();
@ -226,9 +224,9 @@ namespace Microsoft.Azure.Cosmos.Json.Interop
}
/// <summary>
/// Reads the next JSON token from the source as a <see cref="Nullable{T}"/> of <see cref="Decimal"/>.
/// Reads the next JSON token from the source as a <see cref="Nullable{T}"/> of <see cref="decimal"/>.
/// </summary>
/// <returns>A <see cref="Nullable{T}"/> of <see cref="Decimal"/>. This method will return <c>null</c> at the end of an array.</returns>
/// <returns>A <see cref="Nullable{T}"/> of <see cref="decimal"/>. This method will return <c>null</c> at the end of an array.</returns>
public override decimal? ReadAsDecimal()
{
decimal? value = (decimal?)this.ReadNumberValue();
@ -241,9 +239,9 @@ namespace Microsoft.Azure.Cosmos.Json.Interop
}
/// <summary>
/// Reads the next JSON token from the source as a <see cref="Nullable{T}"/> of <see cref="Int32"/>.
/// Reads the next JSON token from the source as a <see cref="Nullable{T}"/> of <see cref="int"/>.
/// </summary>
/// <returns>A <see cref="Nullable{T}"/> of <see cref="Int32"/>. This method will return <c>null</c> at the end of an array.</returns>
/// <returns>A <see cref="Nullable{T}"/> of <see cref="int"/>. This method will return <c>null</c> at the end of an array.</returns>
public override int? ReadAsInt32()
{
int? value = (int?)this.ReadNumberValue();
@ -256,9 +254,9 @@ namespace Microsoft.Azure.Cosmos.Json.Interop
}
/// <summary>
/// Reads the next JSON token from the source as a <see cref="String"/>.
/// Reads the next JSON token from the source as a <see cref="string"/>.
/// </summary>
/// <returns>A <see cref="String"/>. This method will return <c>null</c> at the end of an array.</returns>
/// <returns>A <see cref="string"/>. This method will return <c>null</c> at the end of an array.</returns>
public override string ReadAsString()
{
this.Read();

Просмотреть файл

@ -161,10 +161,10 @@ namespace Microsoft.Azure.Cosmos.Json.Interop
#region WriteValue methods
/// <summary>
/// Writes a <see cref="Object"/> value.
/// Writes a <see cref="object"/> value.
/// An error will raised if the value cannot be written as a single JSON token.
/// </summary>
/// <param name="value">The <see cref="Object"/> value to write.</param>
/// <param name="value">The <see cref="object"/> value to write.</param>
public override void WriteValue(object value)
{
if (value is string stringValue)
@ -178,9 +178,9 @@ namespace Microsoft.Azure.Cosmos.Json.Interop
}
/// <summary>
/// Writes a <see cref="String"/> value.
/// Writes a <see cref="string"/> value.
/// </summary>
/// <param name="value">The <see cref="String"/> value to write.</param>
/// <param name="value">The <see cref="string"/> value to write.</param>
public override void WriteValue(string value)
{
base.WriteValue(value);
@ -188,27 +188,27 @@ namespace Microsoft.Azure.Cosmos.Json.Interop
}
/// <summary>
/// Writes a <see cref="Int32"/> value.
/// Writes a <see cref="int"/> value.
/// </summary>
/// <param name="value">The <see cref="Int32"/> value to write.</param>
/// <param name="value">The <see cref="int"/> value to write.</param>
public override void WriteValue(int value)
{
this.WriteValue((long)value);
}
/// <summary>
/// Writes a <see cref="UInt32"/> value.
/// Writes a <see cref="uint"/> value.
/// </summary>
/// <param name="value">The <see cref="UInt32"/> value to write.</param>
/// <param name="value">The <see cref="uint"/> value to write.</param>
public override void WriteValue(uint value)
{
this.WriteValue((long)value);
}
/// <summary>
/// Writes a <see cref="Int64"/> value.
/// Writes a <see cref="long"/> value.
/// </summary>
/// <param name="value">The <see cref="Int64"/> value to write.</param>
/// <param name="value">The <see cref="long"/> value to write.</param>
public override void WriteValue(long value)
{
base.WriteValue(value);
@ -216,9 +216,9 @@ namespace Microsoft.Azure.Cosmos.Json.Interop
}
/// <summary>
/// Writes a <see cref="UInt64"/> value.
/// Writes a <see cref="ulong"/> value.
/// </summary>
/// <param name="value">The <see cref="UInt64"/> value to write.</param>
/// <param name="value">The <see cref="ulong"/> value to write.</param>
public override void WriteValue(ulong value)
{
if (value <= long.MaxValue)
@ -232,18 +232,18 @@ namespace Microsoft.Azure.Cosmos.Json.Interop
}
/// <summary>
/// Writes a <see cref="Single"/> value.
/// Writes a <see cref="float"/> value.
/// </summary>
/// <param name="value">The <see cref="Single"/> value to write.</param>
/// <param name="value">The <see cref="float"/> value to write.</param>
public override void WriteValue(float value)
{
this.WriteValue((double)value);
}
/// <summary>
/// Writes a <see cref="Double"/> value.
/// Writes a <see cref="double"/> value.
/// </summary>
/// <param name="value">The <see cref="Double"/> value to write.</param>
/// <param name="value">The <see cref="double"/> value to write.</param>
public override void WriteValue(double value)
{
base.WriteValue(value);
@ -251,9 +251,9 @@ namespace Microsoft.Azure.Cosmos.Json.Interop
}
/// <summary>
/// Writes a <see cref="Boolean"/> value.
/// Writes a <see cref="bool"/> value.
/// </summary>
/// <param name="value">The <see cref="Boolean"/> value to write.</param>
/// <param name="value">The <see cref="bool"/> value to write.</param>
public override void WriteValue(bool value)
{
base.WriteValue(value);
@ -261,27 +261,27 @@ namespace Microsoft.Azure.Cosmos.Json.Interop
}
/// <summary>
/// Writes a <see cref="Int16"/> value.
/// Writes a <see cref="short"/> value.
/// </summary>
/// <param name="value">The <see cref="Int16"/> value to write.</param>
/// <param name="value">The <see cref="short"/> value to write.</param>
public override void WriteValue(short value)
{
base.WriteValue((long)value);
}
/// <summary>
/// Writes a <see cref="UInt16"/> value.
/// Writes a <see cref="ushort"/> value.
/// </summary>
/// <param name="value">The <see cref="UInt16"/> value to write.</param>
/// <param name="value">The <see cref="ushort"/> value to write.</param>
public override void WriteValue(ushort value)
{
this.WriteValue((long)value);
}
/// <summary>
/// Writes a <see cref="Char"/> value.
/// Writes a <see cref="char"/> value.
/// </summary>
/// <param name="value">The <see cref="Char"/> value to write.</param>
/// <param name="value">The <see cref="char"/> value to write.</param>
public override void WriteValue(char value)
{
base.WriteValue(value);
@ -289,27 +289,27 @@ namespace Microsoft.Azure.Cosmos.Json.Interop
}
/// <summary>
/// Writes a <see cref="Byte"/> value.
/// Writes a <see cref="byte"/> value.
/// </summary>
/// <param name="value">The <see cref="Byte"/> value to write.</param>
/// <param name="value">The <see cref="byte"/> value to write.</param>
public override void WriteValue(byte value)
{
this.WriteValue((long)value);
}
/// <summary>
/// Writes a <see cref="SByte"/> value.
/// Writes a <see cref="sbyte"/> value.
/// </summary>
/// <param name="value">The <see cref="SByte"/> value to write.</param>
/// <param name="value">The <see cref="sbyte"/> value to write.</param>
public override void WriteValue(sbyte value)
{
this.WriteValue((long)value);
}
/// <summary>
/// Writes a <see cref="Decimal"/> value.
/// Writes a <see cref="decimal"/> value.
/// </summary>
/// <param name="value">The <see cref="Decimal"/> value to write.</param>
/// <param name="value">The <see cref="decimal"/> value to write.</param>
public override void WriteValue(decimal value)
{
this.WriteValue((double)value);
@ -325,9 +325,9 @@ namespace Microsoft.Azure.Cosmos.Json.Interop
}
/// <summary>
/// Writes a <see cref="Byte"/>[] value.
/// Writes a <see cref="byte"/>[] value.
/// </summary>
/// <param name="value">The <see cref="Byte"/>[] value to write.</param>
/// <param name="value">The <see cref="byte"/>[] value to write.</param>
public override void WriteValue(byte[] value)
{
throw new NotSupportedException("Can not write byte arrays");

Просмотреть файл

@ -7,7 +7,6 @@ namespace Microsoft.Azure.Cosmos.Json.Interop
using System.IO;
using System.Text;
using Microsoft.Azure.Cosmos.Core.Utf8;
using Newtonsoft.Json;
#if INTERNAL
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
@ -29,13 +28,7 @@ namespace Microsoft.Azure.Cosmos.Json.Interop
this.getResultCallback = getResultCallback ?? throw new ArgumentNullException(nameof(getResultCallback));
}
public override long CurrentLength
{
get
{
throw new NotImplementedException();
}
}
public override long CurrentLength => throw new NotImplementedException();
public override JsonSerializationFormat SerializationFormat => JsonSerializationFormat.Text;

Просмотреть файл

@ -23,7 +23,7 @@ namespace Microsoft.Azure.Cosmos.Json
int arrayLength = JsonBinaryEncoding.GetValueLength(buffer.Span);
// Scope to just the array
buffer = buffer.Slice(0, (int)arrayLength);
buffer = buffer.Slice(0, arrayLength);
// Seek to the first array item
buffer = buffer.Slice(firstArrayItemOffset);

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше