[英]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): 在这里,我设法将这些行设置为当前日期和时间,但我的意愿是将它们设置为接收到的其他变量,例如,
cameraName
和dateTime
,而不复制它们(我设法通过以下两行来做到这一点,但是只是复制列):
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.