---
languages:
- csharp
page_type: sample
products:
- azure
- azure-functions
- azure-app-service
- azure-cosmos-db
- azure-cognitive-services
description: "This sample showcases the new Azure Functions tooling for C# Class Libraries in Visual Studio."
name: "Customer Reviews App with Cognitive Services"
urlFragment: customer-reviews-cognitive-services
---
# Sample - Customer Reviews App with Cognitive Services (Azure Functions tools for Visual Studio 2017)
This sample showcases the new Azure Functions tooling for C# Class Libraries in Visual Studio. It has a website where customers submit product reviews, stored in Azure storage blobs and CosmosDB; and an Azure Function to perform automated moderation of the customer reviews using Microsoft Cognitive Services. It uses an Azure storage queue to decouple the website from the function.
## Setup ##
Please [follow the Setup Instructions](SETUP.md) to get your environment configured.
## Sample Highlights ##
### Sample Architecture ###
Here's a view of the architecture of the sample:
![](Media/Picture20.png)
### Deliver as a Demo ###
**Here is the [demo script](DEMOSCRIPT.md)**.
And here's an example recording of the demo:
[![VS 2017 Azure Functions Demo Video on YouTube](https://img.youtube.com/vi/r__XV__I21k/0.jpg)](https://www.youtube.com/watch?v=r__XV__I21k)
### Section 1: Azure Functions tools for Visual Studio 2017 ###
This section highlights the benefits of creating Azure Functions in Visual Studio 2017: compiled class libraries, attribute based function definition, intellisense, live unit testing, local debugging.
| Screen | Steps | Notes |
|--------|-------|--------|
|![](Media/Picture1.png)<p>![](Media/Picture1a.png)|In Visual Studio with the Content Moderator solution open, right Click on the ContentModerationFunction project and select Add -> Class -> Azure Function.| The demo includes a website for customers to upload cat product reviews, including a picture and a comment. You can change the whole sample with a different type of product reviews by updating the sample images and the cognitive services code. The team already built a function to automate the moderation of those reviews, using an Azure Storage queue to decouple the website and the automated moderation performed by the serverless function using Azure Functions. By using Azure Functions, you don’t have to maintain a separate server. The platform scales out automatically based on the workload, and you pay per execution. And now with the great Visual Studio tooling you can be super productive in this new compute model. The first thing to notice is we have an updated File->New experience to create a new Azure Function project or to add a new Azure Function class, where you can set the triggers and bindings right here. But you can cancel out of it and explore the one we already created for the reviews moderation.|
|![](Media/Picture2.png)|Review the Azure Function class definition.<p>You can see IntelliSense by typing ``image`` in the code inside the method.|Our new tooling is based on .NET class libraries, which means you get the full support of Visual Studio 2017 features like IntelliSense, debugging and more.|
|![](Media/Picture3.png)|Enable Live Unit Testing if using Visual Studio 2017 Update 3 Enterprise Edition.|You can also take advantage of the new Live Unit testing feature to see the latest unit test status right in the editor. There's two simple tests that get run from the Tests project.|
|![](Media/Picture4.png)|Check out the Queue, Blob, and CosmosDB attributes in the method |You can now use attributes on your Function method declarations for its triggers and bindings, so you don’t need a separate metadata file for this. This makes it really easy to understand your function. As you can see, this function is triggering from a storage queue, where the website puts alerts for my function to know that there’s a new review; and binds to blob storage where the review picture is, and to a CosmosDB document where the review text and other metadata are.|
|![](Media/Picture5.png)|Look at the text moderation code|The function right now is only reviewing the text of the review, by calling out to the [Content Moderation Microsoft Cognitive API](https://docs.microsoft.com/en-us/azure/cognitive-services/Content-Moderator/text-moderation-api) to ensure the text is safe. Now you can edit the function to also moderate the image itelf to ensure it’s safe and contains a picture of a cat.|
|![](Media/Picture6.png)|Select the following two lines:<p> ``InputDocument.IsApproved = passesText;``<br>``Bool containsCat = true;`` <p> and replace them with three new lines:<p>``(bool containsCat, string caption) = await PassesImageModerationAsync(image);``<br> ``inputDocument.IsApproved = containsCat && passesText;``<br> ``inputDocument.Caption = caption;``<p>If you use AutoHotKey there's a ``Serverless.ahk`` file in the ``Reset\assets`` folder with ``Control+Shift+a`` configured to paste these lines.|Now you're also using the Vision API to review the image too. It ensures there's a cat in the image.|
|![](Media/Picture7.png)|Add a breakpoint to the ``EmitCustomTelemetry`` line.<p>Click the Run button to start debugging.<p>Switch to browser tab with your Reviews website open.|Now that your code changes are done, you can make sure this is all working. By setting a breakpoint you now debug this function locally, while still interacting with Azure Storage and CosmosDB. You’ve started debugging locally.|
|![](Media/Picture8.png)|Click on the ``+ Add Picture`` button on the website.|you can add a new photo that will add a message to the Storage queue and trigger the function running in Visual Studio. Try a photo that will fail image moderation (a photo without a cat).|
|![](Media/Picture9.png)<p>![](Media/Picture9a.png)|Click on ``+Image``.<p>Select the dog image.<p>Click on Review textbox.<p>Enter a review text in the textbox (or enter ctrl+shift+b to paste review text if using AutoHotKey).<p>Click create, wait for image and Pending status to show.<p>Switch to Visual Studio|Given this is a cat review site our Function should fail anything that’s not a cat. And that should trigger our function with this new review.|
|![](Media/Picture10.png)|Once the breakpoint is hit, check out the values of queueInput, containsCat, and caption (not inputDocument.Caption).<p>Click Continue button and switch back to website| This is the amazing part, that no other serverless platform offers: you can trigger off Azure events even when you're running locally. This is not an emulator or simulator, it’s the actual Azure Functions runtime on your local machine.<p>The function triggered from the queue message that the website created, and you can see the queue contents right here. You can also see the result that comes back from Cognitive Services. It will even give you a caption of the picture you uploaded. The function also uses the binding to update the status of the document in CosmosDB.|
|![](Media/Picture11.png)|After the function finishes executing, refresh the website page. It should show the result of the moderation as Rejected and a description of the picture. Switch back to Visual Studio|If you're happy with the function code update, it's time to ship it!|
|![](Media/Picture12.png)|If you have Live Unit Tests going, check that the green unit tests ticks are there. Right click on project and select Publish. |The unit tests would have automatically run again when you added the image moderation code. Let’s have a look at how easy you can publish and deploy the function. The easiest way to do this is to right click on my project and select Publish.|
|![](Media/Picture13.png)|If using VSTS you can cancel out of publish window, otherwise you can publish it directly from here in Visual Studio.|Here you can decide to publish directly to an Azure Function that you already have created on Azure, or create a new one using the Publish wizard.<p>If you
没有合适的资源?快使用搜索试试~ 我知道了~
AzureFunctions工具 它有一个网站供客户提交评论,存储在Azure.zip
共154个文件
png:29个
dll:14个
js:12个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 68 浏览量
2023-04-18
00:29:50
上传
评论
收藏 12.19MB ZIP 举报
温馨提示
AzureFunctions工具 它有一个网站供客户提交评论,存储在Azure.zip
资源推荐
资源详情
资源评论
收起资源包目录
AzureFunctions工具 它有一个网站供客户提交评论,存储在Azure.zip (154个子文件)
Serverless.ahk 591B
Provision.cmd 475B
Reset.cmd 473B
ApplicationInsights.config 4KB
AnalyzeImage.cs 5KB
ReviewProvider.cs 4KB
Startup.cs 2KB
UnitTests.cs 2KB
ReviewController.cs 1KB
Startup.cs 928B
Program.cs 718B
CatReview.cs 652B
StatusLabelViewComponent.cs 263B
CreateCatReview.cs 257B
HomeController.cs 224B
Create.cshtml 3KB
Index.cshtml 2KB
_Layout.cshtml 1KB
Details.cshtml 1KB
Index.cshtml 370B
Error.cshtml 264B
Default.cshtml 252B
_ViewImports.cshtml 190B
_ValidationScriptsPartial.cshtml 174B
_ViewStart.cshtml 31B
ContentModeratorFunction.csproj 1KB
ContentModeratorFunction.Tests.csproj 1KB
CatsReviewApp.csproj 814B
bootstrap.css 188KB
bootstrap.min.css 152KB
bootstrap.css 118KB
bootstrap.min.css 96KB
bootstrap-grid.css 63KB
bootstrap-grid.min.css 47KB
bootstrap-reboot.css 5KB
bootstrap-reboot.min.css 4KB
site.css 4KB
Microsoft.Data.OData.dll 1.45MB
Microsoft.Azure.Documents.Client.dll 1.16MB
Microsoft.WindowsAzure.Storage.dll 775KB
Microsoft.Data.Edm.dll 644KB
Microsoft.Data.Services.Client.dll 644KB
Newtonsoft.Json.dll 502KB
Microsoft.WindowsAzure.StorageClient.dll 360KB
Interop.SHDocVw.dll 156KB
System.Spatial.dll 114KB
Interop.WUApiLib.dll 84KB
DemoToolkit.Cmdlets.dll 77KB
DemoToolkit.Tasks.dll 66KB
Interop.IWshRuntimeLibrary.dll 48KB
DemoToolkit.Common.dll 21KB
.DS_Store 8KB
.DS_Store 6KB
.DS_Store 6KB
._.DS_Store 4KB
._.DS_Store 4KB
._.DS_Store 4KB
nuget.exe 4.07MB
.gitattributes 2KB
.gitignore 4KB
favicon.ico 31KB
approved-02.jpg 675KB
approved-03.jpg 355KB
rejected-01.jpg 201KB
demo-upload.jpg 161KB
moxie.jpg 142KB
approved-04.jpg 142KB
approved-01.JPG 68KB
jquery.js 265KB
bootstrap.bundle.js 218KB
bootstrap.js 129KB
jquery.min.js 85KB
bootstrap.bundle.min.js 77KB
bootstrap.min.js 57KB
jquery.validate.js 48KB
additional-methods.js 41KB
jquery.validate.min.js 23KB
jquery.validate.unobtrusive.js 19KB
additional-methods.min.js 18KB
jquery.validate.unobtrusive.min.js 6KB
template.json 14KB
BuildDefinition.json 11KB
._template.json 4KB
launchSettings.json 655B
appsettings.json 535B
local.settings.json 464B
parameters.json 239B
appsettings.Development.json 159B
host.json 65B
LICENSE 1KB
LICENSE 1KB
bootstrap.min.css.map 611KB
bootstrap.css.map 481KB
bootstrap.bundle.js.map 393KB
bootstrap.bundle.min.js.map 305KB
bootstrap.js.map 245KB
bootstrap.min.js.map 186KB
bootstrap-grid.css.map 148KB
jquery.min.map 129KB
bootstrap-grid.min.css.map 106KB
共 154 条
- 1
- 2
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功