4

我在 web Jobs sdk 上玩得更多,我只需要通过调度程序调用一个方法,它应该将 1-n 个文件写入存储。WebJobs SDK 的优点是我不需要包含 Azure 存储 SDK,并且所有内容都是“绑定的”。当我指定文件名时它可以工作,但我的“WriteCustomFile”方法只写入一个名为“{name}”的文件

代码:

class Program
{
    static void Main(string[] args)
    {
        JobHost host = new JobHost();
        host.Call(typeof(Program).GetMethod("WriteFile"));
        host.Call(typeof(Program).GetMethod("WriteCustomFile"), new { name = "Helloworld1.txt" });
        host.Call(typeof(Program).GetMethod("WriteCustomFile"), new { name = "Helloworld2.txt" });
        host.Call(typeof(Program).GetMethod("WriteCustomFile"), new { name = "Helloworld3.txt" });
        //host.RunAndBlock();
    }

    [NoAutomaticTrigger]
    public static void WriteFile([Blob("container/foobar.txt")]TextWriter writer)
    {
        writer.WriteLine("Hello World..." + DateTime.UtcNow.ToShortDateString() + " - " + DateTime.UtcNow.ToShortTimeString());
    }

    [NoAutomaticTrigger]
    public static void WriteCustomFile(string name, [Blob("container/{name}")] TextWriter writer)
    {
        writer.WriteLine("Hello World New ..." + name + ":" + DateTime.UtcNow.ToShortDateString() + " - " + DateTime.UtcNow.ToShortTimeString());
    }
}

我想要实现的只是用给定的文件名调用“WriteCustomFile”。我发现的所有示例都考虑到了“Blob 输入/输出”的想法。我找到了这个示例,但它似乎更像是一个 hack ;) http://thenextdoorgeek.com/post/WAWS-WebJob-to-upload-FREB-files-to-Azure-Storage-using-the-WebJobs-SDK

目前有没有办法做到这一点?

4

1 回答 1

8

WebJobs SDK 3.0.1 不支持Host.Call(并从仪表板调用)的“花式”参数绑定 - 我们将在未来的版本中添加它。

目前,解决方法是显式指定 blob 的路径:

static void Main(string[] args)
{
    JobHost host = new JobHost();
    host.Call(
        typeof(Program).GetMethod("WriteCustomFile"), 
        new { 
            name = "Helloworld1.txt", 
            writer = "container/Helloworld1.txt" });
}

[NoAutomaticTrigger]
public static void WriteCustomFile(string name, [Blob("container/{name}")] TextWriter writer)
{
    writer.WriteLine("Hello World New ..." + name + ":" + DateTime.UtcNow.ToShortDateString() + " - " + DateTime.UtcNow.ToShortTimeString());
}
于 2014-07-07T17:15:24.947 回答