зеркало из
1
0
Форкнуть 0

Merge pull request #1 from Azure/main

resync fork
This commit is contained in:
mohammed barqawi 2021-04-09 22:36:47 +03:00 коммит произвёл GitHub
Родитель 266bf54c71 b58fdb2e6f
Коммит dad5672ac3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
19 изменённых файлов: 1121 добавлений и 2 удалений

33
.github/workflows/dotnet.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,33 @@
name: .NET build and test
env:
NUGET_VERSION: '5.3.1' # set this to the dot net version to use
AZURE_ARTIFACTS_FEED_URL: https://pkgs.dev.azure.com/.../nuget/v3/index.json # set this to the registry url for your Azure Artifacts Feed, you will find this in Azure DevOps
BUILD_CONFIGURATION: 'Release' # set this to the appropriate build configuration
DOTNET_VERSION: '3.1.x'
SOLUTION_FILE_PATH: .
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1
- name: Restore NuGet packages
working-directory: ${{env.GITHUB_WORKSPACE}}
run: nuget restore ${{env.SOLUTION_FILE_PATH}}
- name: Build
working-directory: ${{env.GITHUB_WORKSPACE}}
# Add additional options to the MSBuild command line here (like platform or verbosity level).
# See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}}
- name: Test
run: dotnet test dirs.sln --logger trx --verbosity normal

21
LICENSE.txt Normal file
Просмотреть файл

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 Microsoft Azure
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

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

@ -1,2 +1,20 @@
# logicapps-connector-extensions
LogicApps Connector Extensions
This repository is for active development of built-in connector extensibility for Logic Apps preview. Visit [Logic Apps preview doc](https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-overview-preview) for more details.
## Getting started
To get started for authoring the new built-in connector, refer [Logic app doc](https://docs.microsoft.com/en-us/azure/logic-apps/create-stateful-stateless-workflows-visual-studio-code#enable-built-in-connector-authoring)
For tutorials, quick starts, visit the [techcommunity blog](https://techcommunity.microsoft.com/t5/integrations-on-azure/azure-logic-apps-running-anywhere-built-in-connector/ba-p/1921272)
### Extension deployment
To deploy the connector extension , you need to execute the poswershell script [add-extension.ps1](https://github.com/Azure/logicapps-connector-extensions/blob/main/src/Common/tools/add-extension.ps1) in the VS code logic app project as shown below:
![deployment](https://techcommunity.microsoft.com/t5/image/serverpage/image-id/271421iC23BEF2FCEC4FE53/image-dimensions/542x240?v=v2)
### Contributing
For details on contributing to this repository, see the contributing guide.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repositories using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

37
azure-pipelines.yml Normal file
Просмотреть файл

@ -0,0 +1,37 @@
trigger:
- CosmosDB
pool:
vmImage: 'windows-latest'
variables:
solution: '**/dirs.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=false /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest@2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- script: dotnet test dirs.sln --logger trx
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'

62
dirs.sln Normal file
Просмотреть файл

@ -0,0 +1,62 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30503.244
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB", "src\CosmosDB\Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.csproj", "{B58DD1C3-0141-41B6-B086-4F4745B04DFB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0BCE55FC-1587-4942-9024-D3C685450FEC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CosmosDB", "CosmosDB", "{14B26AB8-DBDA-48FF-8DDE-76EAAAACFDBE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{E5AB7828-C313-4E8F-BBBA-DD051553B80E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CosmosDB", "CosmosDB", "{E03FD904-FE07-42B5-890A-695F19C1AF5C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.Tests", "test\CosmosDB\Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.Tests\Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.Tests.csproj", "{BA921F94-7106-48E3-A4ED-C752F5F4E6B1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{45DEA270-AE97-412B-8DF6-6DEEA570C01F}"
ProjectSection(SolutionItems) = preProject
azure-pipelines.yml = azure-pipelines.yml
src.ruleset = src.ruleset
stylecop.json = stylecop.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{2108829F-8E0A-4F6D-BF07-E4BB34193D1E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.Workflows.ServiceProvider.Extensions.Common", "src\Common\Microsoft.Azure.Workflows.ServiceProvider.Extensions.Common.csproj", "{216FA3A1-FEC2-49C9-9123-68771B546F9F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B58DD1C3-0141-41B6-B086-4F4745B04DFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B58DD1C3-0141-41B6-B086-4F4745B04DFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B58DD1C3-0141-41B6-B086-4F4745B04DFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B58DD1C3-0141-41B6-B086-4F4745B04DFB}.Release|Any CPU.Build.0 = Release|Any CPU
{BA921F94-7106-48E3-A4ED-C752F5F4E6B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA921F94-7106-48E3-A4ED-C752F5F4E6B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA921F94-7106-48E3-A4ED-C752F5F4E6B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA921F94-7106-48E3-A4ED-C752F5F4E6B1}.Release|Any CPU.Build.0 = Release|Any CPU
{216FA3A1-FEC2-49C9-9123-68771B546F9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{216FA3A1-FEC2-49C9-9123-68771B546F9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{216FA3A1-FEC2-49C9-9123-68771B546F9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{216FA3A1-FEC2-49C9-9123-68771B546F9F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{B58DD1C3-0141-41B6-B086-4F4745B04DFB} = {14B26AB8-DBDA-48FF-8DDE-76EAAAACFDBE}
{14B26AB8-DBDA-48FF-8DDE-76EAAAACFDBE} = {0BCE55FC-1587-4942-9024-D3C685450FEC}
{E03FD904-FE07-42B5-890A-695F19C1AF5C} = {E5AB7828-C313-4E8F-BBBA-DD051553B80E}
{BA921F94-7106-48E3-A4ED-C752F5F4E6B1} = {E03FD904-FE07-42B5-890A-695F19C1AF5C}
{2108829F-8E0A-4F6D-BF07-E4BB34193D1E} = {0BCE55FC-1587-4942-9024-D3C685450FEC}
{216FA3A1-FEC2-49C9-9123-68771B546F9F} = {2108829F-8E0A-4F6D-BF07-E4BB34193D1E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BFBA28BE-9B3B-4E33-A597-C95445B11C87}
EndGlobalSection
EndGlobal

Двоичные данные
sign.snk Normal file

Двоичный файл не отображается.

127
src.ruleset Normal file
Просмотреть файл

@ -0,0 +1,127 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="WebJobs SDK" Description="This rule set contains the rules that applies to sources" ToolsVersion="15.0">
<IncludeAll Action="Error" />
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1006" Action="None" />
<Rule Id="CA1020" Action="None" />
<Rule Id="CA1024" Action="None" />
<Rule Id="CA1026" Action="None" />
<Rule Id="CA1031" Action="None" />
<Rule Id="CA1033" Action="None" />
<Rule Id="CA1062" Action="None" />
<Rule Id="CA1303" Action="None" />
<Rule Id="CA1305" Action="None" />
<Rule Id="CA1307" Action="None" />
<Rule Id="CA1308" Action="None" />
<Rule Id="CA1506" Action="None" />
<Rule Id="CA1726" Action="None" />
<Rule Id="CA1800" Action="None" />
<Rule Id="CA2204" Action="None" />
<Rule Id="CA2210" Action="None" />
<Rule Id="CA2243" Action="None" />
<Rule Id="CA904" Action="None" />
<Rule Id="CA905" Action="None" />
<Rule Id="CA908" Action="None" />
<Rule Id="CS0618" Action="None" />
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA0001" Action="None" />
<Rule Id="SA1005" Action="None" />
<Rule Id="SA1101" Action="None" />
<Rule Id="SA1116" Action="None" />
<Rule Id="SA1117" Action="None" />
<Rule Id="SA1127" Action="None" />
<Rule Id="SA1128" Action="None" />
<Rule Id="SA1139" Action="None" />
<Rule Id="SA1202" Action="None" />
<Rule Id="SA1204" Action="None" />
<Rule Id="SA1308" Action="None" />
<Rule Id="SA1309" Action="None" />
<Rule Id="SA1314" Action="None" />
<Rule Id="SA1402" Action="None" />
<Rule Id="SA1404" Action="None" />
<Rule Id="SA1405" Action="None" />
<Rule Id="SA1413" Action="None" />
<Rule Id="SA1502" Action="None" />
<Rule Id="SA1512" Action="None" />
<Rule Id="SA1513" Action="None" />
<Rule Id="SA1611" Action="None" />
<Rule Id="SA1615" Action="None" />
<Rule Id="SA1618" Action="None" />
<Rule Id="SA1028" Action="None" />
<!-- Re-enable this -->
<Rule Id="SA1009" Action="None" />
<!-- Re-enable this -->
<Rule Id="SA1649" Action="None" />
<!-- Re-enable this -->
<Rule Id="SA1623" Action="None" />
<!-- Re-enable this -->
<Rule Id="SA1515" Action="None" />
<!-- Re-enable this -->
<Rule Id="SA1401" Action="None" />
<!-- Re-enable this -->
<Rule Id="SA1516" Action="None" />
<!-- Re-enable this -->
<Rule Id="SA1400" Action="None" />
<!-- Re-enable this -->
<Rule Id="SA1507" Action="None" />
<!-- Re-enable this -->
<Rule Id="SA1124" Action="None" />
<!-- Re-enable this -->
<Rule Id="SA1614" Action="None" />
<!-- Re-enable this -->
<Rule Id="SA1616" Action="None" />
<!-- Re-enable this -->
<Rule Id="SA1617" Action="None" />
<!-- Re-enable this -->
<Rule Id="SA1622" Action="None" />
<!-- Re-enable this -->
<Rule Id="SA1311" Action="None" />
<!-- Re-enable this -->
<Rule Id="SA1134" Action="None" />
<Rule Id="SA1201" Action="None" />
<Rule Id="SA1121" Action="None" />
<Rule Id="SA1111" Action="None" />
<Rule Id="SA1118" Action="None" />
<Rule Id="SA1003" Action="None" />
<Rule Id="SA1013" Action="None" />
<Rule Id="SA1208" Action="None" />
<Rule Id="SA1210" Action="None" />
<Rule Id="SA1500" Action="None" />
<Rule Id="SA1012" Action="None" />
<Rule Id="SA1122" Action="None" />
<Rule Id="SA1129" Action="None" />
<Rule Id="SA1312" Action="None" />
<Rule Id="SA1137" Action="None" />
<Rule Id="SA1130" Action="None" />
<Rule Id="SA1514" Action="None" />
<Rule Id="SA1505" Action="None" />
<Rule Id="SA1119" Action="None" />
<Rule Id="SA1125" Action="None" />
<Rule Id="SA1206" Action="None" />
<Rule Id="SA1300" Action="None" />
<Rule Id="SA1509" Action="None" />
<Rule Id="SA1008" Action="None" />
<Rule Id="SA1606" Action="None" />
<Rule Id="SA1107" Action="None" />
<Rule Id="SA1504" Action="None" />
<Rule Id="SA1642" Action="None" />
<Rule Id="SA1407" Action="None" />
<Rule Id="SA1624" Action="None" />
<Rule Id="SA1214" Action="None" />
<Rule Id="SA1100" Action="None" />
<Rule Id="SA1501" Action="None" />
<Rule Id="SA1108" Action="None" />
<Rule Id="SA1203" Action="None" />
<Rule Id="SA1002" Action="None" />
</Rules>
<Rules AnalyzerId="xunit.analyzers" RuleNamespace="xunit.analyzers">
<Rule Id="xUnit1013" Action="None" />
<Rule Id="xUnit2000" Action="None" />
<Rule Id="xUnit2009" Action="None" />
<Rule Id="xUnit2002" Action="None" />
<Rule Id="xUnit2003" Action="None" />
<Rule Id="xUnit2004" Action="None" />
<Rule Id="xUnit1004" Action="None" />
</Rules>
</RuleSet>

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

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\sign.snk</AssemblyOriginatorKeyFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CodeAnalysisRuleSet>..\..\src.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<None Update="tools\add-extension.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="$(SolutionDir)stylecop.json" Link="stylecop.json" />
</ItemGroup>
</Project>

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

@ -0,0 +1,25 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.Common
{
using System;
using System.Drawing;
/// <summary>
/// Color extension.
/// </summary>
public static class ColorExtension
{
/// <summary>
/// To hex color.
/// </summary>
/// <param name="color">Color</param>
/// <returns>unit.</returns>
public static uint ToHexColor(this Color color)
{
return (uint)((color.A << 24) | (color.R << 16) |
(color.G << 8) | (color.B << 0));
}
}
}

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

@ -0,0 +1,112 @@
function add-extension
{
param(
[ValidateScript({
if( -Not ($_ | Test-Path) ){
throw "Extension folder does not exist.. check Path parameter."
}
return $true
})]
[System.IO.FileInfo]$Path,
[String]
$Name
)
process
{
$extensionPath=$Path
$extensionName = $Name
$extensionNameServiceProvider = $extensionName+"ServiceProvider"
write-host "Nuget extension path is $extensionPath"
$extensionNameServiceProvider = $extensionName+"ServiceProvider"
$userprofile = [environment]::GetFolderPath('USERPROFILE')
$dll = Join-Path -Path $extensionPath -ChildPath "netcoreapp3.1"
$childPath = "Microsoft.Azure.Workflows.ServiceProvider.Extensions." + $extensionName + ".dll"
$dll = Join-Path -Path $dll -ChildPath $childPath
if ( Test-Path -Path $dll )
{
write-host "Extension dll path is $dll"
}
else
{
throw "Extension dll path does not exist $dll"
}
$extensionModulePath = Join-Path -Path $userprofile -ChildPath ".azure-functions-core-tools"
$extensionModulePath = Join-Path -Path $extensionModulePath -ChildPath "Functions"
$extensionModulePath = Join-Path -Path $extensionModulePath -ChildPath "ExtensionBundles"
$extensionModulePath = Join-Path -Path $extensionModulePath -ChildPath "Microsoft.Azure.Functions.ExtensionBundle.Workflows"
if ( Test-Path -Path $extensionModulePath )
{
write-host "Extension bundle module path is $extensionModulePath"
}
else
{
throw "Extension bundle module path does not exist $extensionModulePath"
}
$latest = Get-ChildItem -Path $extensionModulePath | Sort-Object LastAccessTime -Descending | Select-Object -First 1
$latest.name
$extensionModulePath = Join-Path -Path $extensionModulePath -ChildPath $latest.name
$extensionModulePath = Join-Path -Path $extensionModulePath -ChildPath "bin"
$extensionModulePath = Join-Path -Path $extensionModulePath -ChildPath "extensions.json"
if ( Test-Path -Path $extensionModulePath )
{
write-host "EXTENSION PATH is $extensionModulePath and dll Path is $dll"
}
else
{
throw "The extensions.json in extension bundle does not exist $extensionModulePath"
}
$fullAssemlyName = [System.Reflection.AssemblyName]::GetAssemblyName($dll).FullName
try
{
# Kill all the existing func.exe else modeule extension cannot be modified.
taskkill /IM "func.exe" /F
}
catch
{
write-host "func.exe not found"
}
$extensionFullName = "Microsoft.Azure.Workflows.ServiceProvider.Extensions." + $extensionName
$startupClass = $extensionFullName + "." + $extensionName + "Startup"
# 1. Add Nuget package to existing project
dotnet add package $extensionFullName --version 1.0.0 --source $extensionPath
# 2. Update extensions.json under extension module
$typeFullName = $startupClass + ", " + $fullAssemlyName
$newNode = [pscustomobject] @{
name = $extensionNameServiceProvider
typeName = $typeFullName}
$jsonContent = Get-Content $extensionModulePath -raw | ConvertFrom-Json
if ( ![bool]($jsonContent.extensions.name -match $extensionNameServiceProvider))
{
$jsonContent.extensions += $newNode
}
else
{
$jsonContent.extensions | % {if($_.name -eq $extensionNameServiceProvider){$_.typeName=$typeFullName}}
}
$jsonContent | ConvertTo-Json -depth 32| set-content $extensionModulePath
# 3. update dll in extension module.
$spl = Split-Path $extensionModulePath
Copy-Item $dll -Destination $spl
Write-host "Extension $extensionName is successfully added. "
}
}
# execute the above function here.
add-extension $args[0] $args[1]

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

@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\sign.snk</AssemblyOriginatorKeyFile>
<CodeAnalysisRuleSet>..\..\src.ruleset</CodeAnalysisRuleSet>
<NoWarn>$(NoWarn);NU5104</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.3" />
<PackageReference Include="Microsoft.Azure.Workflows.WebJobs.Extension" Version="1.0.1.*-*" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Microsoft.Azure.Workflows.ServiceProvider.Extensions.Common.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="icon.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="$(SolutionDir)stylecop.json" Link="stylecop.json" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Update="C:\Users\psrivas\.nuget\packages\microsoft.azure.workflows.webjobs.extension\1.0.1.3-preview\build\Microsoft.Azure.Workflows.BuildTasks.DebugSymbolGenerator.runtimeconfig.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</AdditionalFiles>
</ItemGroup>
</Project>

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

@ -0,0 +1,306 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB
{
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading.Tasks;
using Microsoft.Azure.Workflows.ServiceProvider.Extensions.Common;
using Microsoft.Azure.Workflows.ServiceProviders.Abstractions;
using Microsoft.Azure.Workflows.ServiceProviders.WebJobs.Abstractions.Providers;
using Microsoft.WindowsAzure.ResourceStack.Common.Collections;
using Microsoft.WindowsAzure.ResourceStack.Common.Extensions;
using Microsoft.WindowsAzure.ResourceStack.Common.Swagger.Entities;
using Newtonsoft.Json.Linq;
/// <summary>
/// This is the service operation provider class where you define all the operations and apis.
/// </summary>
[ServiceOperationsProvider(Id = CosmosDBServiceOperationProvider.ServiceId, Name = CosmosDBServiceOperationProvider.ServiceName)]
public class CosmosDBServiceOperationProvider : IServiceOperationsTriggerProvider
{
/// <summary>
/// The service name.
/// </summary>
public const string ServiceName = "cosmosdb";
/// <summary>
/// The service id.
/// </summary>
public const string ServiceId = "/serviceProviders/cosmosdb";
/// <summary>
/// Gets or sets service Operations.
/// </summary>
private readonly List<ServiceOperation> serviceOperationsList;
/// <summary>
/// The set of all API Operations.
/// </summary>
private readonly InsensitiveDictionary<ServiceOperation> apiOperationsList;
/// <summary>
/// Initializes a new instance of the <see cref="CosmosDBServiceOperationProvider"/> class.
/// </summary>
public CosmosDBServiceOperationProvider()
{
this.serviceOperationsList = new List<ServiceOperation>();
this.apiOperationsList = new InsensitiveDictionary<ServiceOperation>();
this.apiOperationsList.AddRange(new InsensitiveDictionary<ServiceOperation>
{
{ "receiveDocument", this.GetReceiveDocumentServiceOperation() },
});
this.serviceOperationsList.AddRange(new List<ServiceOperation>
{
{ this.GetReceiveDocumentServiceOperation().CloneWithManifest(this.GetServiceOperationManifest()) },
});
}
/// <summary>
/// Get binding connection information, needed for Azure function triggers.
/// </summary>
/// <param name="operationId">Operation id.</param>
/// <param name="connectionParameters">Connection parameters.</param>
/// <returns>string.</returns>
public string GetBindingConnectionInformation(string operationId, InsensitiveDictionary<JToken> connectionParameters)
{
return ServiceOperationsProviderUtilities
.GetRequiredParameterValue(
serviceId: ServiceId,
operationId: operationId,
parameterName: "connectionString",
parameters: connectionParameters)?
.ToValue<string>();
}
/// <summary>
/// If the registration of service provider is successful then this should resturn the trigger type.
/// </summary>
/// <returns>string.</returns>
public string GetFunctionTriggerType()
{
return "cosmosDBTrigger";
}
/// <summary>
/// Get operations.
/// </summary>
/// <param name="expandManifest">Expand manifest generation.</param>
/// <returns>Service operation list.</returns>
public IEnumerable<ServiceOperation> GetOperations(bool expandManifest)
{
return expandManifest ? this.serviceOperationsList : this.GetApiOperations();
}
/// <summary>
/// Get service operation.
/// </summary>
/// <returns>Service operation api.</returns>
public ServiceOperationApi GetService()
{
return this.GetServiceOperationApi();
}
/// <summary>
/// The CosmosDB service provider is only trigger based connector hence skipped the implementation.
/// </summary>
/// <param name="operationId">Operation Id.</param>
/// <param name="connectionParameters">Connection parameters.</param>
/// <param name="serviceOperationRequest">Service operation request.</param>
/// <returns>Service operation response.</returns>
public Task<ServiceOperationResponse> InvokeOperation(string operationId, InsensitiveDictionary<JToken> connectionParameters, ServiceOperationRequest serviceOperationRequest)
{
throw new NotImplementedException();
}
/// <summary>
/// Implements the Swagger schema defining the input , output and scope.
/// </summary>
private ServiceOperationManifest GetServiceOperationManifest()
{
return new ServiceOperationManifest
{
ConnectionReference = new ConnectionReferenceFormat
{
ReferenceKeyFormat = ConnectionReferenceKeyFormat.ServiceProvider,
},
Settings = new OperationManifestSettings
{
SecureData = new OperationManifestSettingWithOptions<SecureDataOptions>(),
TrackedProperties = new OperationManifestSetting
{
Scopes = new OperationScope[] { OperationScope.Trigger },
},
},
InputsLocation = new InputsLocation[]
{
InputsLocation.Inputs,
InputsLocation.Parameters,
},
Outputs = new SwaggerSchema
{
Type = SwaggerSchemaType.Object,
Properties = new OrdinalDictionary<SwaggerSchema>
{
{
"body", new SwaggerSchema
{
Type = SwaggerSchemaType.Array,
Title = "Receive document",
Description = "Receive document from Azure Cosmos DB",
Items = new SwaggerSchema
{
Type = SwaggerSchemaType.Object,
Properties = new OrdinalDictionary<SwaggerSchema>
{
{
"contentData", new SwaggerSchema
{
Type = SwaggerSchemaType.String,
Title = "Content",
Format = "byte",
Description = "content",
}
},
{
"Properties", new SwaggerSchema
{
Type = SwaggerSchemaType.Object,
Title = "documentProperties",
AdditionalProperties = new JObject
{
{ "type", "object" },
{ "properties", new JObject { } },
{ "required", new JObject { } },
},
Description = "Document DB data properties",
}
},
},
},
}
},
},
},
Inputs = new SwaggerSchema
{
Type = SwaggerSchemaType.Object,
Properties = new OrdinalDictionary<SwaggerSchema>
{
{
"databaseName", new SwaggerSchema
{
Type = SwaggerSchemaType.String,
Title = "Database name",
Description = "Database name",
}
},
{
"collectionName", new SwaggerSchema
{
Type = SwaggerSchemaType.String,
Title = "Collection name",
Description = "Collection name",
}
},
{
"connectionStringSetting", new SwaggerSchema
{
Type = SwaggerSchemaType.String,
Title = "Connection String",
Default = "CosmosDB-connectionString",
Description = "Connection-string",
}
},
},
Required = new string[]
{
"databaseName",
"collectionName",
},
},
Connector = this.GetServiceOperationApi(),
Trigger = TriggerType.Batch,
Recurrence = new RecurrenceSetting
{
Type = RecurrenceType.None,
},
};
}
/// <summary>
/// Gets the api operations.
/// </summary>
private IEnumerable<ServiceOperation> GetApiOperations()
{
return this.apiOperationsList.Values;
}
/// <summary>
/// The receive documents operation which define the connection and top level design.
/// </summary>
private ServiceOperation GetReceiveDocumentServiceOperation()
{
return new ServiceOperation
{
Name = "receiveDocument",
Id = "receiveDocument",
Type = "receiveDocument",
Properties = new ServiceOperationProperties
{
Api = this.GetServiceOperationApi().GetFlattenedApi(),
Summary = "Receive document",
Description = "Receive document from Azure Cosmos DB",
Visibility = Visibility.Important,
OperationType = OperationType.ServiceProvider,
BrandColor = Color.LightSkyBlue.ToHexColor(),
IconUri = new Uri("https://raw.githubusercontent.com/Azure/logicapps-connector-extensions/CosmosDB/src/CosmosDB/icon.png"),
Trigger = TriggerType.Batch,
},
};
}
/// <summary>
/// The Azure cosmos db API which defines the connection.
/// </summary>
private ServiceOperationApi GetServiceOperationApi()
{
return new ServiceOperationApi
{
Name = "cosmosdb",
Id = ServiceId,
Type = DesignerApiType.ServiceProvider,
Properties = new ServiceOperationApiProperties
{
BrandColor = Color.LightSkyBlue.ToHexColor(),
Description = "Connect to Azure Cosmos db to receive document.",
DisplayName = "Cosmos Db",
IconUri = new Uri("https://raw.githubusercontent.com/Azure//logicapps-connector-extensions/CosmosDB/src/CosmosDB/icon.png"),
Capabilities = new ApiCapability[] { ApiCapability.Triggers },
ConnectionParameters = new ConnectionParameters
{
ConnectionString = new ConnectionStringParameters
{
Type = ConnectionStringType.SecureString,
ParameterSource = ConnectionParameterSource.AppConfiguration,
UIDefinition = new UIDefinition
{
DisplayName = "Connection String",
Description = "Azure Cosmos db Connection String",
Tooltip = "Provide Azure Cosmos db Connection String",
Constraints = new Constraints
{
Required = "true",
},
},
},
},
},
};
}
}
}

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

@ -0,0 +1,58 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB
{
using System.Collections.Generic;
using Microsoft.Azure.Documents;
using Microsoft.Azure.WebJobs.Description;
using Microsoft.Azure.WebJobs.Host.Config;
using Microsoft.Azure.Workflows.ServiceProviders.Abstractions;
using Microsoft.WindowsAzure.ResourceStack.Common.Json;
using Newtonsoft.Json.Linq;
/// <summary>
/// Service Provider class which injects all the service operation provider..
/// </summary>
[Extension("CosmosDBServiceProvider", configurationSection: "CosmosDBServiceProvider")]
public class CosmosDBServiceProvider : IExtensionConfigProvider
{
/// <summary>
/// Initializes a new instance of the <see cref="CosmosDBServiceProvider"/> class.
/// </summary>
/// <param name="serviceOperationsProvider">Service operations provider.</param>
/// <param name="operationsProvider">Operation provider.</param>
public CosmosDBServiceProvider(
ServiceOperationsProvider serviceOperationsProvider,
CosmosDBServiceOperationProvider operationsProvider)
{
serviceOperationsProvider.RegisterService(serviceName: CosmosDBServiceOperationProvider.ServiceName, serviceOperationsProviderId: CosmosDBServiceOperationProvider.ServiceId, serviceOperationsProviderInstance: operationsProvider);
}
/// <summary>
/// Convert the array of Cosmos Document to generic JObject array.
/// </summary>
/// <param name="data">Document List.</param>
/// <returns>JObject array.</returns>
public static JObject[] ConvertDocumentToJObject(IReadOnlyList<Document> data)
{
List<JObject> jobjects = new List<JObject>();
foreach (var doc in data)
{
jobjects.Add(item: (JObject)doc.ToJToken());
}
return jobjects.ToArray();
}
/// <summary>
/// You can add any custom implementation in Initialize method.
/// </summary>
/// <param name="context">Context.</param>
public void Initialize(ExtensionConfigContext context)
{
context.AddConverter<IReadOnlyList<Document>, JObject[]>(ConvertDocumentToJObject);
}
}
}

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

@ -0,0 +1,27 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
[assembly: Microsoft.Azure.WebJobs.Hosting.WebJobsStartup(typeof(Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.CosmosDBStartup))]
namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB
{
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Hosting;
using Microsoft.Extensions.DependencyInjection.Extensions;
/// <summary>
/// This is a start up function, the discovery of this extension is based upon IWebJobsStartup implementation.
/// In the function log file you should be able to see the log "Loading startup extension 'CosmosDbServiceProvider'"
/// </summary>
public class CosmosDBStartup : IWebJobsStartup
{
/// <summary>
/// The Configure method is invoked as initialization of the extension.
/// </summary>
/// <param name="builder">Builder.</param>
public void Configure(IWebJobsBuilder builder)
{
builder.AddExtension<CosmosDBServiceProvider>();
builder.Services.TryAddSingleton<CosmosDBServiceOperationProvider>();
}
}
}

Двоичные данные
src/CosmosDB/icon.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 5.3 KiB

24
stylecop.json Normal file
Просмотреть файл

@ -0,0 +1,24 @@
{
// ACTION REQUIRED: This file was automatically added to your project, but it
// will not take effect until additional steps are taken to enable it. See the
// following page for additional information:
//
// https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/EnableConfiguration.md
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"documentationRules": {
"companyName": ".NET Foundation",
"copyrightText": "Copyright (c) .NET Foundation. All rights reserved.\r\nLicensed under the MIT License. See License.txt in the project root for license information.",
"xmlHeader": false,
"documentInterfaces": false,
"documentInternalElements": false,
"documentExposedElements": false,
"documentPrivateElements": false,
"documentPrivateFields": false
},
"orderingRules": {
"usingDirectivesPlacement": "insideNamespace"
}
}
}

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

@ -0,0 +1,93 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.Tests
{
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host.TestCommon;
using Microsoft.Azure.Workflows.ServiceProviders.Abstractions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.ResourceStack.Common.Extensions;
using Xunit;
/// <summary>
/// Cosmos DB end to end tests.
/// </summary>
[Trait("Category", "E2E")]
public class CosmosDBEndToEndTests
{
/// <summary>
/// Logger provider.
/// </summary>
private readonly TestLoggerProvider loggerProvider = new TestLoggerProvider();
/// <summary>
/// CosmsoDB EndToEnd Test.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
public async Task CosmosDBEndToEnd()
{
using var host = await this.StartHostAsync();
var alllogs = this.loggerProvider.GetAllLogMessages();
var logsList = alllogs.ToList();
Assert.True(logsList.Where(item => item.FormattedMessage.ContainsInsensitively("Job host started")).Count() >= 1);
var services = (CosmosDBServiceOperationProvider)host.Services.GetRequiredService(typeof(CosmosDBServiceOperationProvider));
Assert.NotNull(services);
var triggerType = services.GetFunctionTriggerType();
Assert.Equal("cosmosDBTrigger", triggerType);
var service = services.GetService();
Assert.Equal("/serviceProviders/cosmosdb", service.Id);
Assert.Equal("cosmosdb", service.Name);
var operations = services.GetOperations(false);
Assert.Single(operations.ToList());
Assert.Equal("receiveDocument", services.GetOperations(false).FirstOrDefault().Name);
}
/// <summary>
/// Start web host.
/// </summary>
/// <returns>IHost task.</returns>
private async Task<IHost> StartHostAsync()
{
var localSettings = new Dictionary<string, string>
{
["AzureWebJobsStorage"] = "UseDevelopmentStorage=true",
};
var host = new HostBuilder()
.ConfigureWebJobs(builder =>
{
builder.AddCosmosDB();
var serviceOperationProvider = new ServiceOperationsProvider();
var operationProvider = new CosmosDBServiceOperationProvider();
builder.AddExtension(new CosmosDBServiceProvider(serviceOperationProvider, operationProvider));
builder.Services.TryAddSingleton<CosmosDBServiceOperationProvider>();
})
.ConfigureLogging(b =>
{
b.AddProvider(this.loggerProvider);
})
.ConfigureAppConfiguration(c =>
{
c.AddInMemoryCollection(new[]
{
new KeyValuePair<string, string>("AzureWebJobsStorage", "UseDevelopmentStorage=true"),
new KeyValuePair<string, string>("FUNCTIONS_WORKER_RUNTIME", "dotnet"),
});
})
.Build();
await host.StartAsync();
return host;
}
}
}

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

@ -0,0 +1,72 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
namespace Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.Tests
{
using Microsoft.Azure.Workflows.ServiceProviders.Abstractions;
using Microsoft.WindowsAzure.ResourceStack.Common.Json;
using Xunit;
using Xunit.Abstractions;
/// <summary>
/// Cosmos DB operation tests.
/// </summary>
public class CosmosDBOperationsTests
{
/// <summary>
/// output logger for test.
/// </summary>
private readonly ITestOutputHelper outputLogger;
/// <summary>
/// Initializes a new instance of the <see cref="CosmosDBOperationsTests"/> class.
/// </summary>
/// <param name="output">Output</param>
public CosmosDBOperationsTests(ITestOutputHelper output)
{
this.outputLogger = output;
}
/// <summary>
/// Operation connection parameters test.
/// </summary>
[Fact]
public void OperationConnectionParametersTest()
{
var operations = new CosmosDBServiceOperationProvider();
var connectionParameters = operations.GetService().Properties.ConnectionParameters as ConnectionParameters;
var connectionStringParameters = new ConnectionStringParameters
{
Type = ConnectionStringType.SecureString,
ParameterSource = ConnectionParameterSource.AppConfiguration,
UIDefinition = new UIDefinition
{
DisplayName = "Connection String",
Tooltip = "Provide Azure Cosmos db Connection String",
Constraints = new Constraints
{
Required = "true",
},
Description = "Azure Cosmos db Connection String",
},
};
Assert.Equal(connectionParameters.ConnectionString.ToJson(), connectionStringParameters.ToJson());
this.outputLogger.WriteLine("Connection parameters are matched");
}
/// <summary>
/// Operation connection parameters test.
/// </summary>
[Fact]
public void OperationTriggerCapabilityTest()
{
var operations = new CosmosDBServiceOperationProvider();
var apiCapability = operations.GetService().Properties.Capabilities as ApiCapability[];
Assert.Single(apiCapability);
Assert.Equal(ApiCapability.Triggers, apiCapability[0]);
this.outputLogger.WriteLine("Connector supports only trigger");
}
}
}

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

@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\sign.snk</AssemblyOriginatorKeyFile>
<CodeAnalysisRuleSet>..\..\..\src.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.17.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Host.TestCommon" Version="3.0.19" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Moq" Version="4.7.145" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta3-build3705" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\CosmosDB\Microsoft.Azure.Workflows.ServiceProvider.Extensions.CosmosDB.csproj" />
<ProjectReference Include="..\..\..\src\Common\Microsoft.Azure.Workflows.ServiceProvider.Extensions.Common.csproj" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="$(SolutionDir)stylecop.json" Link="stylecop.json" />
</ItemGroup>
</Project>