-
Notifications
You must be signed in to change notification settings - Fork 0
Update to SDK v0.10.0-preview.1, add 5 new connector samples #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7abc27c
Update to SDK v0.10.0-preview.1, add 5 new connector samples
daviburg b794b4b
Add new connector endpoints to README table
daviburg 058be89
Address review: remove unused Models usings, parameterize Excel function
daviburg dacb23a
Fix trailing period in error message
daviburg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| //------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| //------------------------------------------------------------ | ||
|
|
||
| using System.Net; | ||
| using Azure.Connectors.Sdk; | ||
| using Azure.Connectors.Sdk.AzureEventGrid; | ||
| using Microsoft.Azure.Functions.Worker; | ||
| using Microsoft.Azure.Functions.Worker.Http; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace DirectConnector; | ||
|
|
||
| /// <summary> | ||
| /// Azure Functions demonstrating Azure Event Grid operations using the generated | ||
| /// <see cref="AzureEventGridClient"/> from the Azure Connectors SDK. | ||
| /// </summary> | ||
| public class AzureEventGridFunctions | ||
| { | ||
| private readonly ILogger<AzureEventGridFunctions> _logger; | ||
| private readonly AzureEventGridClient _eventGridClient; | ||
|
|
||
| public AzureEventGridFunctions( | ||
| ILogger<AzureEventGridFunctions> logger, | ||
| AzureEventGridClient eventGridClient) | ||
| { | ||
| this._logger = logger; | ||
| this._eventGridClient = eventGridClient; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Lists available Event Grid topic types. | ||
| /// </summary> | ||
| [Function("EventGridListTopicTypes")] | ||
| public async Task<HttpResponseData> EventGridListTopicTypesAsync( | ||
| [HttpTrigger(AuthorizationLevel.Function, "get", Route = "eventgrid/topictypes")] HttpRequestData request, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| this._logger.LogInformation("EventGridListTopicTypes: Using generated AzureEventGridClient from SDK."); | ||
|
|
||
| try | ||
| { | ||
| var topicTypes = await this._eventGridClient | ||
| .TopicTypesListAsync(cancellationToken: cancellationToken) | ||
| .ConfigureAwait(continueOnCapturedContext: false); | ||
|
|
||
| var response = request.CreateResponse(HttpStatusCode.OK); | ||
| await response | ||
| .WriteAsJsonAsync(new { success = true, topicTypes }, cancellationToken) | ||
| .ConfigureAwait(continueOnCapturedContext: false); | ||
|
|
||
| return response; | ||
| } | ||
| catch (ConnectorException ex) | ||
| { | ||
| this._logger.LogError(ex, "EventGridListTopicTypes failed with status '{StatusCode}'.", ex.Status); | ||
|
|
||
| var errorResponse = request.CreateResponse(HttpStatusCode.BadGateway); | ||
| await errorResponse | ||
| .WriteAsJsonAsync(new { success = false, error = ex.Message, statusCode = ex.Status, details = ex.ResponseBody }, cancellationToken) | ||
| .ConfigureAwait(continueOnCapturedContext: false); | ||
|
|
||
| return errorResponse; | ||
| } | ||
| catch (Exception ex) when (!ex.IsFatal()) | ||
| { | ||
| this._logger.LogError(ex, "Error in EventGridListTopicTypes."); | ||
|
|
||
| var errorResponse = request.CreateResponse(HttpStatusCode.InternalServerError); | ||
| await errorResponse | ||
| .WriteAsJsonAsync(new { success = false, error = ex.Message }) | ||
| .ConfigureAwait(continueOnCapturedContext: false); | ||
|
|
||
| return errorResponse; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Lists Event Grid subscriptions. | ||
| /// </summary> | ||
| [Function("EventGridListSubscriptions")] | ||
| public async Task<HttpResponseData> EventGridListSubscriptionsAsync( | ||
| [HttpTrigger(AuthorizationLevel.Function, "get", Route = "eventgrid/subscriptions")] HttpRequestData request, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| this._logger.LogInformation("EventGridListSubscriptions: Using generated AzureEventGridClient from SDK."); | ||
|
|
||
| try | ||
| { | ||
| var subscriptions = await this._eventGridClient | ||
| .SubscriptionsListAsync(cancellationToken: cancellationToken) | ||
| .ConfigureAwait(continueOnCapturedContext: false); | ||
|
|
||
| var response = request.CreateResponse(HttpStatusCode.OK); | ||
| await response | ||
| .WriteAsJsonAsync(new { success = true, subscriptions }, cancellationToken) | ||
| .ConfigureAwait(continueOnCapturedContext: false); | ||
|
|
||
| return response; | ||
| } | ||
| catch (ConnectorException ex) | ||
| { | ||
| this._logger.LogError(ex, "EventGridListSubscriptions failed with status '{StatusCode}'.", ex.Status); | ||
|
|
||
| var errorResponse = request.CreateResponse(HttpStatusCode.BadGateway); | ||
| await errorResponse | ||
| .WriteAsJsonAsync(new { success = false, error = ex.Message, statusCode = ex.Status, details = ex.ResponseBody }, cancellationToken) | ||
| .ConfigureAwait(continueOnCapturedContext: false); | ||
|
|
||
| return errorResponse; | ||
| } | ||
| catch (Exception ex) when (!ex.IsFatal()) | ||
| { | ||
| this._logger.LogError(ex, "Error in EventGridListSubscriptions."); | ||
|
|
||
| var errorResponse = request.CreateResponse(HttpStatusCode.InternalServerError); | ||
| await errorResponse | ||
| .WriteAsJsonAsync(new { success = false, error = ex.Message }) | ||
| .ConfigureAwait(continueOnCapturedContext: false); | ||
|
|
||
| return errorResponse; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| //------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| //------------------------------------------------------------ | ||
|
|
||
| using System.Net; | ||
| using Azure.Connectors.Sdk; | ||
| using Azure.Connectors.Sdk.ExcelOnline; | ||
| using Microsoft.Azure.Functions.Worker; | ||
| using Microsoft.Azure.Functions.Worker.Http; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace DirectConnector; | ||
|
|
||
| /// <summary> | ||
| /// Azure Functions demonstrating Excel Online operations using the generated | ||
| /// <see cref="ExcelOnlineClient"/> from the Azure Connectors SDK. | ||
| /// </summary> | ||
| public class ExcelOnlineFunctions | ||
| { | ||
| private readonly ILogger<ExcelOnlineFunctions> _logger; | ||
| private readonly ExcelOnlineClient _excelOnlineClient; | ||
|
|
||
| public ExcelOnlineFunctions( | ||
| ILogger<ExcelOnlineFunctions> logger, | ||
| ExcelOnlineClient excelOnlineClient) | ||
| { | ||
| this._logger = logger; | ||
| this._excelOnlineClient = excelOnlineClient; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets tables from an Excel workbook in OneDrive for Business. | ||
| /// </summary> | ||
| [Function("ExcelGetTables")] | ||
| public async Task<HttpResponseData> ExcelGetTablesAsync( | ||
| [HttpTrigger(AuthorizationLevel.Function, "get", Route = "excel/tables")] HttpRequestData request, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| var documentLibrary = request.Query["documentLibrary"] ?? "Documents"; | ||
| var file = request.Query["file"]; | ||
|
|
||
| if (string.IsNullOrEmpty(file)) | ||
| { | ||
| var badRequest = request.CreateResponse(HttpStatusCode.BadRequest); | ||
| await badRequest | ||
| .WriteAsJsonAsync(new { success = false, error = "Missing required query parameter 'file'. Example: ?file=TestWorkbook.xlsx&documentLibrary=Documents." }, cancellationToken) | ||
| .ConfigureAwait(continueOnCapturedContext: false); | ||
| return badRequest; | ||
| } | ||
|
|
||
| this._logger.LogInformation("ExcelGetTables: Using generated ExcelOnlineClient from SDK."); | ||
|
|
||
| try | ||
| { | ||
| var tables = await this._excelOnlineClient | ||
| .GetTablesAsync(documentLibrary: documentLibrary, file: file, cancellationToken: cancellationToken) | ||
| .ConfigureAwait(continueOnCapturedContext: false); | ||
|
|
||
| var response = request.CreateResponse(HttpStatusCode.OK); | ||
| await response | ||
| .WriteAsJsonAsync(new { success = true, tables }, cancellationToken) | ||
| .ConfigureAwait(continueOnCapturedContext: false); | ||
|
|
||
| return response; | ||
| } | ||
| catch (ConnectorException ex) | ||
| { | ||
| this._logger.LogError(ex, "ExcelGetTables failed with status '{StatusCode}'.", ex.Status); | ||
|
|
||
| var errorResponse = request.CreateResponse(HttpStatusCode.BadGateway); | ||
| await errorResponse | ||
| .WriteAsJsonAsync(new { success = false, error = ex.Message, statusCode = ex.Status, details = ex.ResponseBody }, cancellationToken) | ||
| .ConfigureAwait(continueOnCapturedContext: false); | ||
|
|
||
| return errorResponse; | ||
| } | ||
| catch (Exception ex) when (!ex.IsFatal()) | ||
| { | ||
| this._logger.LogError(ex, "Error in ExcelGetTables."); | ||
|
|
||
| var errorResponse = request.CreateResponse(HttpStatusCode.InternalServerError); | ||
| await errorResponse | ||
| .WriteAsJsonAsync(new { success = false, error = ex.Message }) | ||
| .ConfigureAwait(continueOnCapturedContext: false); | ||
|
|
||
| return errorResponse; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.