简体   繁体   English

在Azure EventHubTrigger Function应用中设置列

[英]Set columns in Azure EventHubTrigger Function app

I'd like to set the first two columns of an Azure Table (PartitionKey and RowKey) based on some variables I'm sending to the IoT Hub but I'm unsure how given my low familiarity with C#. 我想根据要发送到IoT中心的一些变量设置Azure表的前两列(PartitionKey和RowKey),但是我不确定我对C#的了解程度如何。 My current code is the following: 我当前的代码如下:

#r "Microsoft.WindowsAzure.Storage"

using System;
using Microsoft.WindowsAzure.Storage.Table;

public static void Run(DataPoint myIoTHubMessage, out DataPoint outputTable, TraceWriter log)
{
   log.Info($"C# IoT Hub trigger function processed a message: {myIoTHubMessage}");

   myIoTHubMessage.PartitionKey = DateTime.Now.ToString("dd-MM-yyyy");
   myIoTHubMessage.RowKey = DateTime.Now.ToString("HH:mm:ss");

   outputTable = myIoTHubMessage;
}

public class DataPoint : TableEntity
{
   public string cameraName { get; set; }
   public string dateTime { get; set; }
   public double Area { get; set; }
}

Here I managed to set these rows to the current date and time, but my will is to set them to other variables received, such as cameraName and dateTime for instance, without duplicating them (I managed to do that with the following two lines, but that just duplicates columns): 在这里,我设法将这些行设置为当前日期和时间,但我的意愿是将它们设置为接收到的其他变量,例如, cameraNamedateTime ,而不复制它们(我设法通过以下两行来做到这一点,但是只是复制列):

   myIoTHubMessage.PartitionKey = myIoTHubMessage.cameraName;
   myIoTHubMessage.RowKey = myIoTHubMessage.dateTime;

Is there any way to have just the 3 variables as columns? 有什么办法可以将3个变量作为列?

I'm not sure if I understood You correctly, but You want to have output with 3 properties: PartitionKey, RowKey and Area? 我不确定我是否正确理解您,但是您是否希望输出具有3个属性:PartitionKey,RowKey和Area?

If yes, then try to define new class for output and use it to return data: 如果是,则尝试为输出定义新类并使用它返回数据:

public static void Run(DataPoint myIoTHubMessage, out OutPutData outputTable, TraceWriter log)
{
   log.Info($"C# IoT Hub trigger function processed a message: {myIoTHubMessage}");

    outputTable = new OutPutData
    {
        PartitionKey = myIoTHubMessage.cameraName,
        RowKey = myIoTHubMessage.dateTime,
        Area = myIoTHubMessage.area
    };
}

public class DataPoint : TableEntity
{
   public string cameraName { get; set; }
   public string dateTime { get; set; }
   public double Area { get; set; }
}

public class OutPutData : TableEntity
{
   public double Area { get; set; }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure function 未由 EventHubTrigger 触发 - Azure function not triggered by EventHubTrigger Azure Function EventHubTrigger 如何从 Azure App Configuration 中读取 EventHubName 和 Connection 字符串? - Azure Function EventHubTrigger how to read EventHubName and Connection string from Azure App Configuration? 运行多个实例的Azure Function EventHubTrigger - Azure Function EventHubTrigger running multiple instances EventHubTrigger 在 Azure Functions 中不起作用 - EventHubTrigger is not working in Azure Functions 函数 v1 中的 EventHubTrigger - 设置 initialOffsetOptions - EventHubTrigger in functions v1 - set initialOffsetOptions 使用eventhubtrigger时是否可以设置开始位置? - Is it possible to set start position when using eventhubtrigger? 使用 azure appsettings 读取 azure webjob 中 EventHubTrigger 的连接字符串 - Use azure appsettings to read connection string for EventHubTrigger in azure webjob 如何使用 Azure Function 设置应用设置值? - How do I set app setting value using Azure Function? 在最新的 Azure.EventHubs SDK 和 .NET 核心 3.1 中找不到 ErrorTrigger、TraceFilter、EventHubTrigger、ConsumerGroup - ErrorTrigger, TraceFilter, EventHubTrigger, ConsumerGroup not found in latest Azure.EventHubs SDK with .NET Core 3.1 以编程方式在Azure功能中设置RunOnStartup? - Programmatically set RunOnStartup in Azure Function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM