4

我正在关注 Pluralsight 教程,它有点过时了,所以我试图填补空白。它说使用 BlobAttribute 来设置文件名,但我不断收到错误消息,指出找不到类型或命名空间。

我正在使用 CSX,但我一辈子都无法让它工作。当我将该行复制到 C# 测试函数应用程序中时,它工作得很好。我现在不想切换到那条路线,因为它不是教程的一部分,我试图坚持他们的流程,但他们也没有解释这一点。Microsoft.Azure.WebJobs using statements 主要只是我尝试让它工作。

任何想法如何让 BlobAttribute 在 CSX 中工作?

#r "Newtonsoft.Json"
#r "Microsoft.Azure.WebJobs"
#r "Microsoft.Azure.WebJobs.Extensions"

using System;
using Newtonsoft.Json;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions;

public class Order
{
public string OrderID {get;set;}
public string ProductID {get;set;}
public string Email{get;set;}
public decimal Price {get;set;}
}

public static void Run(Order myQueueItem, ILogger log, IBinder binder)
{    
log.LogInformation($"C# Queue trigger function processed: 
{myQueueItem.OrderID}");

using(var outputBlob = binder.Bind<TextWriter>(new BlobAttribute($"{myQueueItem.OrderID}.lic")))    
{
    outputBlob.WriteLine($"OrderID: {myQueueItem.OrderID}");
    outputBlob.WriteLine($"ProductID: {myQueueItem.ProductID}");
    outputBlob.WriteLine($"Email: {myQueueItem.Email}");
    outputBlob.WriteLine($"Price: {myQueueItem.Price}");
    outputBlob.WriteLine($"Purchase Date: {DateTime.UtcNow}");

    var md5 = System.Security.Cryptography.MD5.Create();
    var hash = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(myQueueItem.Email + "secret"));
    outputBlob.WriteLine($"Secret Code: 
{BitConverter.ToString(hash).Replace("-","")}");
    }
}
4

2 回答 2

2

BlobAttribute位于 assembly Microsoft.Azure.WebJobs.Extensions.Storage,添加引用#r "Microsoft.Azure.WebJobs.Extensions.Storage"可以修复。

此外,看到这一行

using(var outputBlob = binder.Bind<TextWriter>(new BlobAttribute($"{myQueueItem.OrderID}.lic")))

BlobAttribute要求 blob 路径为 containerName/fileName,因此您可能需要在文件之前添加一些容器,例如

using(var outputBlob = binder.Bind<TextWriter>(new BlobAttribute($"mycontainer/{myQueueItem.OrderID}.lic")))
于 2019-02-11T02:20:32.960 回答
2

为了解决同样的问题

  1. 视觉工作室

工具 > NuGet 包管理器 > 包管理器控制台 > Install-Package Microsoft.Azure.WebJobs.Extensions.Storage -Version 3.0.6

  1. 视觉工作室代码

终端 > cd <Working dir>>dotnet add package Microsoft.Azure.WebJobs.Extensions.Storage

于 2020-07-28T10:36:54.193 回答