From 95180c37d612bfdf3a4389cc7b814aff0dfc5604 Mon Sep 17 00:00:00 2001 From: tg-msft Date: Thu, 25 Jun 2020 08:59:10 -0700 Subject: [PATCH] Search: Remove ForwardsClientCalls (#13004) Fixes #10611 using the automatic refactoring --- .../src/SearchClient.cs | 240 +++++++++++++----- 1 file changed, 175 insertions(+), 65 deletions(-) diff --git a/sdk/search/Azure.Search.Documents/src/SearchClient.cs b/sdk/search/Azure.Search.Documents/src/SearchClient.cs index e8521a343c04f..944437a8f19b6 100644 --- a/sdk/search/Azure.Search.Documents/src/SearchClient.cs +++ b/sdk/search/Azure.Search.Documents/src/SearchClient.cs @@ -1356,15 +1356,26 @@ await ClientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).Conf /// exceptions thrown on partial failure. /// /// - [ForwardsClientCalls] public virtual Response UploadDocuments( IEnumerable documents, IndexDocumentsOptions options = null, - CancellationToken cancellationToken = default) => - IndexDocuments( - IndexDocumentsBatch.Upload(documents), - options, - cancellationToken); + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(UploadDocuments)}"); + scope.Start(); + try + { + return IndexDocuments( + IndexDocumentsBatch.Upload(documents), + options, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } /// /// Upload documents to the index as a batch. @@ -1404,16 +1415,27 @@ public virtual Response UploadDocuments( /// exceptions thrown on partial failure. /// /// - [ForwardsClientCalls] public virtual async Task> UploadDocumentsAsync( IEnumerable documents, IndexDocumentsOptions options = null, - CancellationToken cancellationToken = default) => - await IndexDocumentsAsync( - IndexDocumentsBatch.Upload(documents), - options, - cancellationToken) - .ConfigureAwait(false); + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(UploadDocuments)}"); + scope.Start(); + try + { + return await IndexDocumentsAsync( + IndexDocumentsBatch.Upload(documents), + options, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } /// /// Merge documents to the index as a batch. @@ -1453,15 +1475,26 @@ await IndexDocumentsAsync( /// exceptions thrown on partial failure. /// /// - [ForwardsClientCalls] public virtual Response MergeDocuments( IEnumerable documents, IndexDocumentsOptions options = null, - CancellationToken cancellationToken = default) => - IndexDocuments( - IndexDocumentsBatch.Merge(documents), - options, - cancellationToken); + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(MergeDocuments)}"); + scope.Start(); + try + { + return IndexDocuments( + IndexDocumentsBatch.Merge(documents), + options, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } /// /// Merge documents to the index as a batch. @@ -1501,16 +1534,27 @@ public virtual Response MergeDocuments( /// exceptions thrown on partial failure. /// /// - [ForwardsClientCalls] public virtual async Task> MergeDocumentsAsync( IEnumerable documents, IndexDocumentsOptions options = null, - CancellationToken cancellationToken = default) => - await IndexDocumentsAsync( - IndexDocumentsBatch.Merge(documents), - options, - cancellationToken) - .ConfigureAwait(false); + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(MergeDocuments)}"); + scope.Start(); + try + { + return await IndexDocumentsAsync( + IndexDocumentsBatch.Merge(documents), + options, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } /// /// Merge or upload documents to the index as a batch. @@ -1550,15 +1594,26 @@ await IndexDocumentsAsync( /// exceptions thrown on partial failure. /// /// - [ForwardsClientCalls] public virtual Response MergeOrUploadDocuments( IEnumerable documents, IndexDocumentsOptions options = null, - CancellationToken cancellationToken = default) => - IndexDocuments( - IndexDocumentsBatch.MergeOrUpload(documents), - options, - cancellationToken); + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(MergeOrUploadDocuments)}"); + scope.Start(); + try + { + return IndexDocuments( + IndexDocumentsBatch.MergeOrUpload(documents), + options, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } /// /// Merge or upload documents to the index as a batch. @@ -1598,16 +1653,27 @@ public virtual Response MergeOrUploadDocuments( /// exceptions thrown on partial failure. /// /// - [ForwardsClientCalls] public virtual async Task> MergeOrUploadDocumentsAsync( IEnumerable documents, IndexDocumentsOptions options = null, - CancellationToken cancellationToken = default) => - await IndexDocumentsAsync( - IndexDocumentsBatch.MergeOrUpload(documents), - options, - cancellationToken) - .ConfigureAwait(false); + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(MergeOrUploadDocuments)}"); + scope.Start(); + try + { + return await IndexDocumentsAsync( + IndexDocumentsBatch.MergeOrUpload(documents), + options, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } /// /// Delete documents from the index as a batch. @@ -1647,15 +1713,26 @@ await IndexDocumentsAsync( /// exceptions thrown on partial failure. /// /// - [ForwardsClientCalls] public virtual Response DeleteDocuments( IEnumerable documents, IndexDocumentsOptions options = null, - CancellationToken cancellationToken = default) => - IndexDocuments( - IndexDocumentsBatch.Delete(documents), - options, - cancellationToken); + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(DeleteDocuments)}"); + scope.Start(); + try + { + return IndexDocuments( + IndexDocumentsBatch.Delete(documents), + options, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } /// /// Delete documents from the index as a batch. @@ -1695,16 +1772,27 @@ public virtual Response DeleteDocuments( /// exceptions thrown on partial failure. /// /// - [ForwardsClientCalls] public virtual async Task> DeleteDocumentsAsync( IEnumerable documents, IndexDocumentsOptions options = null, - CancellationToken cancellationToken = default) => - await IndexDocumentsAsync( - IndexDocumentsBatch.Delete(documents), - options, - cancellationToken) - .ConfigureAwait(false); + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchClient)}.{nameof(DeleteDocuments)}"); + scope.Start(); + try + { + return await IndexDocumentsAsync( + IndexDocumentsBatch.Delete(documents), + options, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } /// /// Delete documents from the index as a batch given only their keys. @@ -1739,16 +1827,27 @@ await IndexDocumentsAsync( /// exceptions thrown on partial failure. /// /// - [ForwardsClientCalls] public virtual Response DeleteDocuments( string keyName, IEnumerable 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; + } + } /// /// Delete documents from the index as a batch given only their keys. @@ -1783,17 +1882,28 @@ public virtual Response DeleteDocuments( /// exceptions thrown on partial failure. /// /// - [ForwardsClientCalls] public virtual async Task> DeleteDocumentsAsync( string keyName, IEnumerable 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 } }