Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
Migration from Azure Functions v1 to v2 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudmaichac authored and nzthiago committed Oct 13, 2018
1 parent 3854e98 commit 1bd1099
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSTest.TestAdapter.1.1.17\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.17\build\net45\MSTest.TestAdapter.props')" />
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down Expand Up @@ -42,19 +42,19 @@
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.1.17\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.1.17\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Web.Extensions" />
</ItemGroup>
Expand All @@ -68,7 +68,9 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="App.config" />
<None Include="packages.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="TestImages\moxie.jpg">
Expand All @@ -87,8 +89,8 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.17\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.17\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.17\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.17\build\net45\MSTest.TestAdapter.targets'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.1.1.17\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.17\build\net45\MSTest.TestAdapter.targets')" />
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" />
</Project>
10 changes: 5 additions & 5 deletions Source/ContentModeratorFunction.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.CSharp" version="4.3.0" targetFramework="net462" />
<package id="MSTest.TestAdapter" version="1.1.17" targetFramework="net462" />
<package id="MSTest.TestFramework" version="1.1.17" targetFramework="net462" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net462" />
<package id="System.ValueTuple" version="4.3.0" targetFramework="net462" />
<package id="Microsoft.CSharp" version="4.5.0" targetFramework="net462" />
<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net462" />
<package id="MSTest.TestFramework" version="1.3.2" targetFramework="net462" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net462" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net462" />
</packages>
13 changes: 8 additions & 5 deletions Source/ContentModeratorFunction/AnalyzeImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
using System.Threading.Tasks;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Azure.CognitiveServices.Vision.ComputerVision;
using Microsoft.Azure.CognitiveServices.Vision.ComputerVision.Models;
using Microsoft.Azure.WebJobs;
using Microsoft.ProjectOxford.Vision;
using Newtonsoft.Json.Linq;

namespace ContentModeratorFunction
Expand All @@ -18,7 +19,7 @@ public class AnalyzeImage
public static async Task ReviewImageAndText(
[QueueTrigger("%queue-name%")] ReviewRequestItem queueInput,
[Blob("input-images/{BlobName}", FileAccess.Read)] Stream image,
[DocumentDB("customerReviewData", "reviews", Id = "{DocumentId}", PartitionKey = "Reviews", ConnectionStringSetting = "customerReviewDataDocDB")] dynamic inputDocument)
[CosmosDB("customerReviewData", "reviews", Id = "{DocumentId}", PartitionKey = "Reviews", ConnectionStringSetting = "customerReviewDataDocDB")] dynamic inputDocument)
{
bool passesText = await PassesTextModeratorAsync(inputDocument);

Expand All @@ -31,8 +32,10 @@ public static async Task ReviewImageAndText(

public static async Task<(bool, string)> PassesImageModerationAsync(Stream image)
{
var client = new VisionServiceClient(ApiKey);
var result = await client.AnalyzeImageAsync(image, VisualFeatures);
var client = new ComputerVisionClient(
new ApiKeyServiceClientCredentials(ApiKey),
new DelegatingHandler[] { });
var result = await client.AnalyzeImageInStreamAsync(image, VisualFeatures);

bool containsCat = result.Description.Tags.Take(5).Contains(SearchTag);
string message = result?.Description?.Captions.FirstOrDefault()?.Text;
Expand Down Expand Up @@ -66,7 +69,7 @@ public static async Task<bool> PassesTextModeratorAsync(dynamic document)
private static readonly string ApiKey = Environment.GetEnvironmentVariable("MicrosoftVisionApiKey");
static HttpClient httpClient = new HttpClient();

private static readonly VisualFeature[] VisualFeatures = { VisualFeature.Description };
private static readonly VisualFeatureTypes[] VisualFeatures = { VisualFeatureTypes.Description };

public class ReviewRequestItem
{
Expand Down
29 changes: 11 additions & 18 deletions Source/ContentModeratorFunction/ContentModeratorFunction.csproj
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.KeyVault.Core" version="1.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs" version="2.1.0-beta1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Core" version="2.1.0-beta1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DocumentDB" Version="1.1.0-beta1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" Version="2.1.0-beta1" />
<PackageReference Include="Microsoft.Azure.WebJobs.ServiceBus" Version="2.1.0-beta1" />
<PackageReference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" Version="1.0.4" />
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
<PackageReference Include="Microsoft.Data.Edm" version="5.6.4" />
<PackageReference Include="Microsoft.Data.OData" version="5.6.4" />
<PackageReference Include="Microsoft.Data.Services.Client" version="5.6.4" />
<PackageReference Include="Microsoft.ProjectOxford.Vision" Version="1.0.393" />
<PackageReference Include="Newtonsoft.Json" version="9.0.1" />
<PackageReference Include="System.Net.Http" Version="4.3.1" />
<PackageReference Include="System.Spatial" version="5.6.4" />
<PackageReference Include="WindowsAzure.Storage" version="7.2.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" version="1.0.0-alpha6" />
<PackageReference Include="Microsoft.Azure.CognitiveServices.Vision.ComputerVision" Version="3.2.0" />
<PackageReference Include="Microsoft.Azure.KeyVault.Core" version="3.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" Version="3.0.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="Newtonsoft.Json" version="11.0.2" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" version="1.0.23" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 1bd1099

Please sign in to comment.