本文整理汇总了C#中IStorage.DownloadText方法的典型用法代码示例。如果您正苦于以下问题:C# IStorage.DownloadText方法的具体用法?C# IStorage.DownloadText怎么用?C# IStorage.DownloadText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IStorage
的用法示例。
在下文中一共展示了IStorage.DownloadText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public static void Execute(IQueue queue, IStorage storage, IKeyReader reader)
{
while (true)
{
// Get the next message
string msgId;
string popReceipt;
string retrievedMessage = queue.GetMessage(out msgId, out popReceipt);
//Process the message in less than 30 seconds, and then delete the message
if (!String.IsNullOrEmpty(retrievedMessage))
{
Console.WriteLine("Top message");
Console.WriteLine("Json:");
Console.WriteLine(retrievedMessage);
try
{
PrintModel print = JsonConvert.DeserializeObject<PrintModel>(retrievedMessage);
Console.WriteLine("Deserialized Print Model");
Console.WriteLine("First Name: " + print.FirstName);
Console.WriteLine("Last Name: " + print.LastName);
Console.WriteLine("Phrase: " + print.Phrase);
// download the blob
// deserialize it
// add the new print
// serialize it
// upload the blob
// the container where we'll put existing prints and the new print
var prints = new PrintsModel();
if (storage.Exists())
{
// existing content
string blobJson = storage.DownloadText();
// try to deserialize it
try
{
prints = JsonConvert.DeserializeObject<PrintsModel>(blobJson);
}
catch (Exception)
{
// couldn't deserialize the blob, so forget it, the new blob will
// overwrite it
}
}
else
{
// no existing blob
}
// add the new print
prints.Add(print);
// serialize it
string jsonWithNewPrint = JsonConvert.SerializeObject(prints);
// upload the blob
storage.UploadText(jsonWithNewPrint);
}
catch (Exception)
{
Console.WriteLine("Error deserializing object");
}
finally
{
Console.WriteLine("Deleting message");
queue.DeleteMessage(msgId, popReceipt);
}
}
else
{
Console.WriteLine("No messages");
}
// check again in 5 seconds
System.Threading.Thread.Sleep(5000);
if (reader.KeyAvailable)
{
break;
}
}
}