Azure 应用程序功能的基于文件的工件

Azure 应用程序功能的基于文件的工件,azure,azure-functions,Azure,Azure Functions,我不熟悉应用程序功能。但我已经成功创建了一个自定义应用程序函数,它将接受一些JSON 当我的JSON被上传时,我的应用程序函数将希望根据模式对其进行验证。JSON将出现在POST请求的主体中,以更准确地描述正在发生的事情 以下是验证的基本代码: string schemaJson = @"{ 'description': 'A person', 'type': 'object', 'properties': { 'name': {'type':'string'},

我不熟悉应用程序功能。但我已经成功创建了一个自定义应用程序函数,它将接受一些JSON

当我的JSON被上传时,我的应用程序函数将希望根据模式对其进行验证。JSON将出现在POST请求的主体中,以更准确地描述正在发生的事情

以下是验证的基本代码:

string schemaJson = @"{
  'description': 'A person',
  'type': 'object',
  'properties':
  {
    'name': {'type':'string'},
    'hobbies': {
      'type': 'array',
      'items': {'type':'string'}
    }
  }
}";

JsonSchema schema = JsonSchema.Parse(schemaJson);

JObject person = JObject.Parse(@"{
  'name': 'James',
  'hobbies': ['.NET', 'Blogging', 'Reading', 'Xbox', 'LOLCATS']
}");


IList<string> messages;
bool valid = person.IsValid(schema, out messages);
我想保存一个本地文件,以便加载和验证

实际上,我将有几个文件,http请求中的一个参数将触发我用来验证json模式的文件

让我们想象一下“mycustomerid”是在http请求的头中传递的(或查询字符串或其他内容),mycustomerid的值将驱动我要验证输入json的模式

所以我会有几个文件

customer_1.jsonschema 
customer_2.jsonschema 
customer_3.jsonschema
存储这些文件的最佳做法是什么?这些文件是我相当简单的应用程序功能所必需的?

public static async Task<object> Run(HttpRequestMessage req, TraceWriter log)
{

第一步。使用Kudu控制台在“D:\home\site\wwwroot\HttpTriggerCSharp1”中创建文件“schema.json”

第二步。HttpTrigger以字符串形式读取文件内容的代码:

using System.Net;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    var path = Environment.GetEnvironmentVariable("HOME").ToString() + "\\site\\wwwroot\\HttpTriggerCSharp1\\schema.json";

    string readText = File.ReadAllText(path);

    log.Info(readText);
    return req.CreateResponse(HttpStatusCode.OK, "Hello ");
}
使用System.Net;
公共静态异步任务运行(HttpRequestMessage请求、TraceWriter日志)
{
var path=Environment.GetEnvironmentVariable(“HOME”).ToString()+“\\site\\wwwroot\\HttpTriggerCSharp1\\schema.json”;
字符串readText=File.ReadAllText(路径);
log.Info(readText);
返回req.CreateResponse(HttpStatusCode.OK,“Hello”);
}

Alexey,有关“本地”vs“在azure中”的内容,请参见我的附加说明
            string rootDirectory = string.Empty;
            if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HOME")))
            {
                /* running in azure */
                rootDirectory = Environment.GetEnvironmentVariable("HOME") + "\\site\\wwwroot";
            }
            else
            {
                /* in visual studio, local debugging */
                rootDirectory = ".";
            }
        string path = rootDirectory + "\\MySubFolder\\MyFile.jsonschema";
using System.Net;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    var path = Environment.GetEnvironmentVariable("HOME").ToString() + "\\site\\wwwroot\\HttpTriggerCSharp1\\schema.json";

    string readText = File.ReadAllText(path);

    log.Info(readText);
    return req.CreateResponse(HttpStatusCode.OK, "Hello ");
}