Skip to content

Commit

Permalink
Search: Remove ForwardsClientCalls (#13004)
Browse files Browse the repository at this point in the history
Fixes #10611 using the automatic refactoring
  • Loading branch information
tg-msft authored and prmathur-microsoft committed Jul 8, 2020
1 parent d527d8f commit 95180c3
Showing 1 changed file with 175 additions and 65 deletions.
240 changes: 175 additions & 65 deletions sdk/search/Azure.Search.Documents/src/SearchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1356,15 +1356,26 @@ await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).Conf
/// exceptions thrown on partial failure.
/// </para>
/// </remarks>
[ForwardsClientCalls]
public virtual Response<IndexDocumentsResult> UploadDocuments<T>(
IEnumerable<T> documents,
IndexDocumentsOptions options = null,
CancellationToken cancellationToken = default) =>
IndexDocuments<T>(
IndexDocumentsBatch.Upload<T>(documents),
options,
cancellationToken);
CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(UploadDocuments)}");
scope.Start();
try
{
return IndexDocuments<T>(
IndexDocumentsBatch.Upload<T>(documents),
options,
cancellationToken);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// Upload documents to the index as a batch.
Expand Down Expand Up @@ -1404,16 +1415,27 @@ public virtual Response<IndexDocumentsResult> UploadDocuments<T>(
/// exceptions thrown on partial failure.
/// </para>
/// </remarks>
[ForwardsClientCalls]
public virtual async Task<Response<IndexDocumentsResult>> UploadDocumentsAsync<T>(
IEnumerable<T> documents,
IndexDocumentsOptions options = null,
CancellationToken cancellationToken = default) =>
await IndexDocumentsAsync<T>(
IndexDocumentsBatch.Upload<T>(documents),
options,
cancellationToken)
.ConfigureAwait(false);
CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(UploadDocuments)}");
scope.Start();
try
{
return await IndexDocumentsAsync<T>(
IndexDocumentsBatch.Upload<T>(documents),
options,
cancellationToken)
.ConfigureAwait(false);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// Merge documents to the index as a batch.
Expand Down Expand Up @@ -1453,15 +1475,26 @@ await IndexDocumentsAsync<T>(
/// exceptions thrown on partial failure.
/// </para>
/// </remarks>
[ForwardsClientCalls]
public virtual Response<IndexDocumentsResult> MergeDocuments<T>(
IEnumerable<T> documents,
IndexDocumentsOptions options = null,
CancellationToken cancellationToken = default) =>
IndexDocuments<T>(
IndexDocumentsBatch.Merge<T>(documents),
options,
cancellationToken);
CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(MergeDocuments)}");
scope.Start();
try
{
return IndexDocuments<T>(
IndexDocumentsBatch.Merge<T>(documents),
options,
cancellationToken);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// Merge documents to the index as a batch.
Expand Down Expand Up @@ -1501,16 +1534,27 @@ public virtual Response<IndexDocumentsResult> MergeDocuments<T>(
/// exceptions thrown on partial failure.
/// </para>
/// </remarks>
[ForwardsClientCalls]
public virtual async Task<Response<IndexDocumentsResult>> MergeDocumentsAsync<T>(
IEnumerable<T> documents,
IndexDocumentsOptions options = null,
CancellationToken cancellationToken = default) =>
await IndexDocumentsAsync<T>(
IndexDocumentsBatch.Merge<T>(documents),
options,
cancellationToken)
.ConfigureAwait(false);
CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(MergeDocuments)}");
scope.Start();
try
{
return await IndexDocumentsAsync<T>(
IndexDocumentsBatch.Merge<T>(documents),
options,
cancellationToken)
.ConfigureAwait(false);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// Merge or upload documents to the index as a batch.
Expand Down Expand Up @@ -1550,15 +1594,26 @@ await IndexDocumentsAsync<T>(
/// exceptions thrown on partial failure.
/// </para>
/// </remarks>
[ForwardsClientCalls]
public virtual Response<IndexDocumentsResult> MergeOrUploadDocuments<T>(
IEnumerable<T> documents,
IndexDocumentsOptions options = null,
CancellationToken cancellationToken = default) =>
IndexDocuments<T>(
IndexDocumentsBatch.MergeOrUpload<T>(documents),
options,
cancellationToken);
CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(MergeOrUploadDocuments)}");
scope.Start();
try
{
return IndexDocuments<T>(
IndexDocumentsBatch.MergeOrUpload<T>(documents),
options,
cancellationToken);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// Merge or upload documents to the index as a batch.
Expand Down Expand Up @@ -1598,16 +1653,27 @@ public virtual Response<IndexDocumentsResult> MergeOrUploadDocuments<T>(
/// exceptions thrown on partial failure.
/// </para>
/// </remarks>
[ForwardsClientCalls]
public virtual async Task<Response<IndexDocumentsResult>> MergeOrUploadDocumentsAsync<T>(
IEnumerable<T> documents,
IndexDocumentsOptions options = null,
CancellationToken cancellationToken = default) =>
await IndexDocumentsAsync<T>(
IndexDocumentsBatch.MergeOrUpload<T>(documents),
options,
cancellationToken)
.ConfigureAwait(false);
CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(MergeOrUploadDocuments)}");
scope.Start();
try
{
return await IndexDocumentsAsync<T>(
IndexDocumentsBatch.MergeOrUpload<T>(documents),
options,
cancellationToken)
.ConfigureAwait(false);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// Delete documents from the index as a batch.
Expand Down Expand Up @@ -1647,15 +1713,26 @@ await IndexDocumentsAsync<T>(
/// exceptions thrown on partial failure.
/// </para>
/// </remarks>
[ForwardsClientCalls]
public virtual Response<IndexDocumentsResult> DeleteDocuments<T>(
IEnumerable<T> documents,
IndexDocumentsOptions options = null,
CancellationToken cancellationToken = default) =>
IndexDocuments<T>(
IndexDocumentsBatch.Delete<T>(documents),
options,
cancellationToken);
CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(DeleteDocuments)}");
scope.Start();
try
{
return IndexDocuments<T>(
IndexDocumentsBatch.Delete<T>(documents),
options,
cancellationToken);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// Delete documents from the index as a batch.
Expand Down Expand Up @@ -1695,16 +1772,27 @@ public virtual Response<IndexDocumentsResult> DeleteDocuments<T>(
/// exceptions thrown on partial failure.
/// </para>
/// </remarks>
[ForwardsClientCalls]
public virtual async Task<Response<IndexDocumentsResult>> DeleteDocumentsAsync<T>(
IEnumerable<T> documents,
IndexDocumentsOptions options = null,
CancellationToken cancellationToken = default) =>
await IndexDocumentsAsync<T>(
IndexDocumentsBatch.Delete<T>(documents),
options,
cancellationToken)
.ConfigureAwait(false);
CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(DeleteDocuments)}");
scope.Start();
try
{
return await IndexDocumentsAsync<T>(
IndexDocumentsBatch.Delete<T>(documents),
options,
cancellationToken)
.ConfigureAwait(false);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// Delete documents from the index as a batch given only their keys.
Expand Down Expand Up @@ -1739,16 +1827,27 @@ await IndexDocumentsAsync<T>(
/// exceptions thrown on partial failure.
/// </para>
/// </remarks>
[ForwardsClientCalls]
public virtual Response<IndexDocumentsResult> DeleteDocuments(
string keyName,
IEnumerable<string> keyValues,
IndexDocumentsOptions options = null,
CancellationToken cancellationToken = default) =>
IndexDocuments(
IndexDocumentsBatch.Delete(keyName, keyValues),
options,
cancellationToken);
CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(DeleteDocuments)}");
scope.Start();
try
{
return IndexDocuments(
IndexDocumentsBatch.Delete(keyName, keyValues),
options,
cancellationToken);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// Delete documents from the index as a batch given only their keys.
Expand Down Expand Up @@ -1783,17 +1882,28 @@ public virtual Response<IndexDocumentsResult> DeleteDocuments(
/// exceptions thrown on partial failure.
/// </para>
/// </remarks>
[ForwardsClientCalls]
public virtual async Task<Response<IndexDocumentsResult>> DeleteDocumentsAsync(
string keyName,
IEnumerable<string> keyValues,
IndexDocumentsOptions options = null,
CancellationToken cancellationToken = default) =>
await IndexDocumentsAsync(
IndexDocumentsBatch.Delete(keyName, keyValues),
options,
cancellationToken)
.ConfigureAwait(false);
CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(DeleteDocuments)}");
scope.Start();
try
{
return await IndexDocumentsAsync(
IndexDocumentsBatch.Delete(keyName, keyValues),
options,
cancellationToken)
.ConfigureAwait(false);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}
#endregion Index Documents Conveniences
}
}

0 comments on commit 95180c3

Please sign in to comment.