本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Queue.CloudQueue.AddMessage方法的典型用法代码示例。如果您正苦于以下问题:C# CloudQueue.AddMessage方法的具体用法?C# CloudQueue.AddMessage怎么用?C# CloudQueue.AddMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Queue.CloudQueue
的用法示例。
在下文中一共展示了CloudQueue.AddMessage方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
/// <summary>
/// The main entry point.
/// </summary>
/// <param name="args">
/// The command line arguments. Not used.
/// </param>
private static void Main(string[] args)
{
Console.WriteLine("Hello!");
// Create a connection to the web api server
string command;
var client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:10281/");
do
{
// Load the file to transmit
string fileName = string.Empty;
while (string.IsNullOrEmpty(fileName) || !File.Exists(fileName))
{
Console.Write("Enter the full name of the file you like to send to server: ");
fileName = Console.ReadLine();
}
var fileInfo = new FileInfo(fileName);
// Get the SAS-URLs from the server
Console.WriteLine("Asking Server for SAS-URLs");
HttpResponseMessage resp = client.GetAsync("api/Data").Result;
resp.EnsureSuccessStatusCode();
var dataDto = resp.Content.ReadAsAsync<DataDto>().Result;
Console.WriteLine("Server responds:");
Console.WriteLine("BLOB Container URL: " + dataDto.BlobContainerUrl);
Console.WriteLine("BLOB Container SAS Token: " + dataDto.BlobSasToken);
Console.WriteLine("Queue URL: " + dataDto.QueueUrl);
Console.WriteLine("Queue SAS Token: " + dataDto.QueueSasToken);
// Load file to BLOB Storage
Console.WriteLine("Create or overwrite the blob with contents from a local file...");
var container = new CloudBlobContainer(new Uri(dataDto.BlobContainerUrl + dataDto.BlobSasToken));
CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileInfo.Name);
using (var fileStream = File.OpenRead(fileInfo.FullName))
{
blockBlob.UploadFromStream(fileStream);
}
Console.WriteLine("done.");
// Add message to queue
Console.Write("Add a new message to the queue...");
var queue = new CloudQueue(new Uri(dataDto.QueueUrl + dataDto.QueueSasToken));
var message = new CloudQueueMessage(blockBlob.Uri.ToString());
queue.AddMessage(message);
Console.WriteLine("done.");
Console.WriteLine("Press Enter to upload the next file or type 'quit' for exit");
command = Console.ReadLine();
}
while (command != "quit");
}
示例2: enqueue
public bool enqueue(string queueName, Message operationMessage)
{
var message = JsonConvert.SerializeObject(operationMessage);
try
{
queue = queueClient.GetQueueReference(queueName);
queue.CreateIfNotExists();
queue.AddMessage(new CloudQueueMessage(message));
return true;
}
catch (Exception e)
{
Console.WriteLine(e.InnerException);
return false;
}
}
示例3: QueueBase64EncodingTestVerifyLength
private static bool QueueBase64EncodingTestVerifyLength(CloudQueue queue, CloudQueueMessage message)
{
const long MaxMessageSize = 64 * 1024; // 64kb
if (queue.EncodeMessage && Convert.ToBase64String(message.AsBytes).Length > MaxMessageSize
|| !queue.EncodeMessage && message.AsBytes.Length > MaxMessageSize)
{
TestHelper.ExpectedException<ArgumentException>(() => { queue.AddMessage(message); }, "Binary data must be Base64 encoded");
return true;
}
return false;
}
示例4: QueueBase64EncodingTest
/// <summary>
/// Perform a PUT and GET queue message test customized by a few parameters.
/// </summary>
private void QueueBase64EncodingTest(CloudQueue queue, CloudQueue queueRefWithoutBase64Encoding, bool useBase64Encoding, bool useString, bool hasInvalidCharacter, int messageLength, char invalidXmlChar, char validXmlChar)
{
queue.EncodeMessage = useBase64Encoding;
CloudQueueMessage originalMessage = null;
bool expectedExceptionThrown = false;
if (!useString)
{
// hasInvalidCharacter is ignored
byte[] data = new byte[messageLength];
Random random = new Random();
random.NextBytes(data);
originalMessage = new CloudQueueMessage(data);
}
else
{
string message = CreateMessageString(messageLength, hasInvalidCharacter, invalidXmlChar, validXmlChar);
originalMessage = new CloudQueueMessage(message);
}
// check invalid use case and length validation
if (!useString && !queue.EncodeMessage)
{
TestHelper.ExpectedException<ArgumentException>(() => { queue.AddMessage(originalMessage); }, "Binary data must be Base64 encoded");
expectedExceptionThrown = true;
}
else
{
expectedExceptionThrown = QueueBase64EncodingTestVerifyLength(queue, originalMessage);
}
if (!expectedExceptionThrown)
{
// check invalid XML characters validation
if (!queue.EncodeMessage && hasInvalidCharacter && messageLength > 0)
{
TestHelper.ExpectedException<ArgumentException>(() => { queue.AddMessage(originalMessage); }, "Invalid characters should throw if Base64 encoding is not used");
expectedExceptionThrown = true;
}
else
{
// good to send messages
queue.AddMessage(originalMessage);
queue.AddMessage(originalMessage);
if (useString)
{
QueueBase64EncodingTestDownloadMessageAndVerify(queue, queueRefWithoutBase64Encoding, originalMessage.AsString);
}
else
{
QueueBase64EncodingTestDownloadMessageAndVerify(queue, queueRefWithoutBase64Encoding, originalMessage.AsBytes);
}
}
}
}
示例5: UpdateQueueSASTest
public void UpdateQueueSASTest()
{
CloudQueueClient client = GenerateCloudQueueClient();
CloudQueue queue = client.GetQueueReference(GenerateNewQueueName());
try
{
queue.Create();
string messageContent = Guid.NewGuid().ToString();
CloudQueueMessage message = new CloudQueueMessage(messageContent);
queue.AddMessage(message);
SharedAccessQueuePolicy policy = new SharedAccessQueuePolicy()
{
SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
Permissions = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.ProcessMessages,
};
string id = Guid.NewGuid().ToString();
string sasToken = queue.GetSharedAccessSignature(policy, null);
StorageCredentials sasCreds = new StorageCredentials(sasToken);
CloudQueue sasQueue = new CloudQueue(queue.Uri, sasCreds);
TestHelper.ExpectedException(
() => sasQueue.PeekMessage(),
"Peek when Sas does not allow Read access on the queue",
HttpStatusCode.NotFound);
sasQueue.AddMessage(message);
SharedAccessQueuePolicy policy2 = new SharedAccessQueuePolicy()
{
SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
Permissions = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.ProcessMessages | SharedAccessQueuePermissions.Read,
};
string sasToken2 = queue.GetSharedAccessSignature(policy2, null);
sasCreds.UpdateSASToken(sasToken2);
sasQueue = new CloudQueue(queue.Uri, sasCreds);
sasQueue.PeekMessage();
}
finally
{
queue.DeleteIfExists();
}
}