我试图将一个变量“ userinput”保存到我的Azure表存储中,当用户向聊天机器人发送“ no”时,该变量填充用户发送给聊天机器人的第一条消息。
这是我当前用于将变量“ userinput”上载到表存储中的代码:
private void storeuserinput(Activity activity)
{
var uid = activity.From.Id;
var uname = activity.From.Name;
if (activity.Text?.ToLower().ToString() == "no" || activity.Text?.ToLower().ToString() == "NO" || activity.Text?.ToLower().ToString() == "No" || activity.Text?.ToLower().ToString() == "Nope" || activity.Text?.ToLower().ToString() == "nope")
{
var userinput = firstmessage;
// Parse the connection string and return a reference to the storage account.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the table client.
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
// Retrieve a reference to the table.
CloudTable table = tableClient.GetTableReference("NoSolutionFound");
// Create a new customer entity.
unansweredQuestion input = new unansweredQuestion();
input.Query = userinput;
// Create the TableOperation object that inserts the customer entity.
TableOperation insertOperation = TableOperation.Insert(input);
// Execute the insert operation.
table.Execute(insertOperation);
}
//extract other data from "activity" object
//your code logic here
//store data in your table storage
//Note: specifcial scenario of user send attachment
}
public class unansweredQuestion : TableEntity
{
public unansweredQuestion() { } // the parameter-less constructor must be provided
public string Query { get; set; }
}
运行我的代码时,我的存储表仍然为空,并且输出框中出现两个错误:
Microsoft.WindowsAzure.ServiceRuntime错误:102:角色环境。 未能初始化。 hr:-2147024894
从ServiceRuntime获取“ StorageConnectionString”:失败。
抛出异常:Microsoft.WindowsAzure.Storage.dll中的“ Microsoft.WindowsAzure.Storage.StorageException”