当前位置: 首页>>代码示例>>C#>>正文


C# Queue.CloudQueueMessage类代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Queue.CloudQueueMessage的典型用法代码示例。如果您正苦于以下问题:C# CloudQueueMessage类的具体用法?C# CloudQueueMessage怎么用?C# CloudQueueMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CloudQueueMessage类属于Microsoft.WindowsAzure.Storage.Queue命名空间,在下文中一共展示了CloudQueueMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            var storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
            var queueClient = storageAccount.CreateCloudQueueClient();

            var queue = queueClient.GetQueueReference("samples-asq-nativeintegration"); //"Samples.ASQ.NativeIntegration");

            #region SerializedMessage

            var nativeMessage = @"{""Content"":""Hello from native sender"",""SendOnUtc"":""2015-10-27T20:47:27.4682716Z""}";
            var nativeMessageAsBytes = Encoding.UTF8.GetBytes(nativeMessage);

            #endregion

            #region NecessaryHeaders

            var headers = new Dictionary<string, string>
            {
                { "NServiceBus.EnclosedMessageTypes", "Shared.NativeMessage" },
                { "NServiceBus.MessageIntent", "Send" }
            };

            #endregion
            // TODO: message body is byte
            var message = new CloudQueueMessage(@"{""IdForCorrelation"":null,""Id"":""31949487-2b67-49e0-b961-96f7a834d877"",""MessageIntent"":1,""ReplyToAddress"":""native-sender"",""TimeToBeReceived"":""00:00:00"",""Headers"":{""NServiceBus.EnclosedMessageTypes"":""Shared.NativeMessage"",""NServiceBus.MessageIntent"":""Send""},""Body"":""eyJDb250ZW50IjoiSGVsbG8gZnJvbSBuYXRpdmUgc2VuZGVyIiwiU2VuZE9uVXRjIjoiMjAxNS0xMC0yOFQwNDowNDo0MC45MDg0NDI4WiJ9"",""CorrelationId"":null,""Recoverable"":false}");
            queue.AddMessage(message);

            Console.WriteLine("Native message sent");
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
开发者ID:SeanFeldman,项目名称:NSB.ASQ.NativeSender,代码行数:31,代码来源:Program.cs

示例2: crawlingPhase

        public void crawlingPhase(CloudQueueMessage urlMessage)
        {
            totalUrls++;
            String url = urlMessage.AsString;
            if (!alreadyVisitedUrls.Contains(url))
            {
                alreadyVisitedUrls.Add(url);
                try
                {
                    HtmlWeb hw = new HtmlWeb();
                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    doc = hw.Load(url);
                    String date = "";
                    if (doc.DocumentNode.SelectSingleNode("//head/meta[@property='og:pubdate']") != null)
                    {
                        String stringDate = doc.DocumentNode.SelectSingleNode("//head/meta[@property='og:pubdate']").GetAttributeValue("content", "default").Substring(0, 10);
                        date = DateTime.ParseExact(stringDate, "yyyy-MM-dd", CultureInfo.InvariantCulture).ToString("yyyy/MM/dd");
                    }
                    String fullTitle = doc.DocumentNode.SelectSingleNode("//head/title").InnerText;
                    String[] titles = fullTitle.Split(' ');
                    foreach (string partTitle in titles) {
                        if (!partTitle.Equals(" ") && !partTitle.Equals("-") && !partTitle.Equals("CNN.com") && !partTitle.Equals(""))
                        {
                            CrawlerEntry entry = new CrawlerEntry(url, fullTitle, date, partTitle);
                            TableOperation insertOperation = TableOperation.Insert(entry);
                            table.Execute(insertOperation);
                            tableSize++;
                        }
                    }

                    //get urls in page
                    foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
                    {
                        string href = link.GetAttributeValue("href", string.Empty);
                        HashSet<String> links = new HashSet<String>();
                        String[] hrefSplit = href.Split('/');
                        String html = hrefSplit[hrefSplit.Length - 1];
                        //if the href is not in the disallowed urls, is not already crawled, is not a duplicate link, is a valid html page, and on cnn or bleacherreport
                        if (!disallowedUrls.Any(s => href.Contains(s)) && !alreadyVisitedUrls.Any(s => s.Equals(href)) && !links.Contains(href) && rgx.IsMatch(html) && (href.Contains("cnn.com") || href.Contains("bleacherreport.com")))
                        {
                            //store remaining into queue
                            urlQueue.AddMessage(new CloudQueueMessage(href));

                            //adds link to current link set
                            links.Add(href);
                        }
                    }
                }
                catch
                {

                }
            }

            updateTotalUrls();
            //Update last 10 urls crawled
            updateLastUrl(urlMessage.AsString);

            urlQueue.DeleteMessage(urlMessage);
        }
开发者ID:kinderst,项目名称:Web-Service-Like-Google,代码行数:60,代码来源:Crawler.cs

示例3: CreateCloudQueueMessageFromByteArray

        public static CloudQueueMessage CreateCloudQueueMessageFromByteArray([ReadOnlyArray] byte[] content)
#endif
        {
            CloudQueueMessage message = new CloudQueueMessage(null);
            message.SetMessageContent(content);
            return message;
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:7,代码来源:CloudQueueMessage.cs

示例4: AQ_Standalone_1

        public async Task AQ_Standalone_1()
        {
            queueName = "Test-1-".ToLower() + Guid.NewGuid();
            AzureQueueDataManager manager = await GetTableManager(queueName);
            Assert.AreEqual(0, await manager.GetApproximateMessageCount());

            CloudQueueMessage inMessage = new CloudQueueMessage("Hello, World");
            await manager.AddQueueMessage(inMessage);
            //Nullable<int> count = manager.ApproximateMessageCount;
            Assert.AreEqual(1, await manager.GetApproximateMessageCount());

            CloudQueueMessage outMessage1 = await manager.PeekQueueMessage();
            logger.Info("PeekQueueMessage 1: {0}", AzureStorageUtils.PrintCloudQueueMessage(outMessage1));
            Assert.AreEqual(inMessage.AsString, outMessage1.AsString);

            CloudQueueMessage outMessage2 = await manager.PeekQueueMessage();
            logger.Info("PeekQueueMessage 2: {0}", AzureStorageUtils.PrintCloudQueueMessage(outMessage2));
            Assert.AreEqual(inMessage.AsString, outMessage2.AsString);

            CloudQueueMessage outMessage3 = await manager.GetQueueMessage();
            logger.Info("GetQueueMessage 3: {0}", AzureStorageUtils.PrintCloudQueueMessage(outMessage3));
            Assert.AreEqual(inMessage.AsString, outMessage3.AsString);
            Assert.AreEqual(1, await manager.GetApproximateMessageCount());

            CloudQueueMessage outMessage4 = await manager.GetQueueMessage();
            Assert.IsNull(outMessage4);

            Assert.AreEqual(1, await manager.GetApproximateMessageCount());

            await manager.DeleteQueueMessage(outMessage3);
            Assert.AreEqual(0, await manager.GetApproximateMessageCount());
        }
开发者ID:stanroze,项目名称:orleans,代码行数:32,代码来源:AzureQueueDataManagerTests.cs

示例5: AddQuere

 public async Task AddQuere(RImage img)
 {
     CloudQueue queue = QueueClient.GetQueueReference("myqueues");
     await queue.CreateIfNotExistsAsync();
     CloudQueueMessage message = new CloudQueueMessage(JsonConvert.SerializeObject(img));
     await queue.AddMessageAsync(message);
 }
开发者ID:peacecwz,项目名称:AAYazOkuluCloudService,代码行数:7,代码来源:BlobManager.cs

示例6: SignButton_Click

        protected void SignButton_Click(object sender, EventArgs e)
        {
            if (this.FileUpload1.HasFile)
            {
                this.InitializeStorage();

                // upload the image to blob storage
                string uniqueBlobName = string.Format("guestbookpics/image_{0}{1}", Guid.NewGuid().ToString(), Path.GetExtension(this.FileUpload1.FileName));
                CloudBlockBlob blob = blobStorage.GetContainerReference("guestbookpics").GetBlockBlobReference(uniqueBlobName);
                blob.Properties.ContentType = this.FileUpload1.PostedFile.ContentType;
                blob.UploadFromStream(this.FileUpload1.FileContent);
                System.Diagnostics.Trace.TraceInformation("Uploaded image '{0}' to blob storage as '{1}'", this.FileUpload1.FileName, uniqueBlobName);

                // create a new entry in table storage
                GuestBookEntry entry = new GuestBookEntry() { GuestName = this.NameTextBox.Text, Message = this.MessageTextBox.Text, PhotoUrl = blob.Uri.ToString(), ThumbnailUrl = blob.Uri.ToString() };
                GuestBookDataSource ds = new GuestBookDataSource();
                ds.AddGuestBookEntry(entry);
                System.Diagnostics.Trace.TraceInformation("Added entry {0}-{1} in table storage for guest '{2}'", entry.PartitionKey, entry.RowKey, entry.GuestName);

                // queue a message to process the image
                var queue = queueStorage.GetQueueReference("guestthumbs");
                var message = new CloudQueueMessage(string.Format("{0},{1},{2}", uniqueBlobName, entry.PartitionKey, entry.RowKey));
                queue.AddMessage(message);
                System.Diagnostics.Trace.TraceInformation("Queued message to process blob '{0}'", uniqueBlobName);
            }

            this.NameTextBox.Text = string.Empty;
            this.MessageTextBox.Text = string.Empty;

            this.DataList1.DataBind();
        }
开发者ID:kirpasingh,项目名称:MicrosoftAzureTrainingKit,代码行数:31,代码来源:Default.aspx.cs

示例7: SendWebHookWorkItemsAsync

        /// <inheritdoc />
        public async Task SendWebHookWorkItemsAsync(IEnumerable<WebHookWorkItem> workItems)
        {
            if (workItems == null)
            {
                throw new ArgumentNullException("workItems");
            }

            CloudQueue queue = _manager.GetCloudQueue(_connectionString, WebHookQueue);

            try
            {
                IEnumerable<Task> addTasks = workItems.Select(item =>
                    {
                        string content = JsonConvert.SerializeObject(item, _serializerSettings);
                        CloudQueueMessage message = new CloudQueueMessage(content);
                        return queue.AddMessageAsync(message);
                    });
                await Task.WhenAll(addTasks);
            }
            catch (Exception ex)
            {
                string error = _manager.GetStorageErrorMessage(ex);
                string msg = string.Format(CultureInfo.CurrentCulture, AzureStorageResources.AzureSender_AddFailure, error);
                _logger.Error(msg, ex);
            }
        }
开发者ID:itomek,项目名称:WebHooks,代码行数:27,代码来源:AzureWebHookSender.cs

示例8: CloudQueueCreateMessageAsync

        public async Task CloudQueueCreateMessageAsync()
        {
            CloudQueue queue = DefaultQueueClient.GetQueueReference(TestHelper.GenerateNewQueueName());

            try
            {
                await queue.CreateIfNotExistsAsync();

                CloudQueueMessage message = new CloudQueueMessage(Guid.NewGuid().ToString());
                await queue.AddMessageAsync(message);

                CloudQueueMessage retrMessage = await queue.GetMessageAsync();
                string messageId = retrMessage.Id;
                string popReceipt = retrMessage.PopReceipt;

                // Recreate the message using the messageId and popReceipt.
                CloudQueueMessage newMessage = new CloudQueueMessage(messageId, popReceipt);
                Assert.AreEqual(messageId, newMessage.Id);
                Assert.AreEqual(popReceipt, newMessage.PopReceipt);

                await queue.UpdateMessageAsync(newMessage, TimeSpan.FromSeconds(30), MessageUpdateFields.Visibility);
                CloudQueueMessage retrMessage2 = await queue.GetMessageAsync();
                Assert.AreEqual(null, retrMessage2);
            }
            finally
            {
                queue.DeleteIfExistsAsync().AsTask().Wait();
            }
        }
开发者ID:jdkillian,项目名称:azure-sdk-for-net,代码行数:29,代码来源:CloudQueueMessageTest.cs

示例9: StartCrawling

 public static string StartCrawling()
 {
     CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
     CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
     CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
     CloudTable pageTable = tableClient.GetTableReference("indexedpages");
     while (pageTable.Exists())
     {
         System.Threading.Thread.Sleep(1000);
     }
     pageTable.CreateIfNotExists();
     Debug.WriteLine("Now in StartCrawling");
     CloudQueue cmdQ = queueClient.GetQueueReference("cmdq");
     cmdQ.CreateIfNotExists();
     CloudQueue urlQ = queueClient.GetQueueReference("pagequeue");
     urlQ.CreateIfNotExists();
     urlQ.Clear();
     urlQ.AddMessage(new CloudQueueMessage("http://www.cnn.com/robots.txt"));
     Debug.WriteLine("THIS IS THE MESSAGE ADDED: " + urlQ.PeekMessage().AsString);
     cmdQ.Clear();
     string message = "start";
     CloudQueueMessage cmd = new CloudQueueMessage(message);
     cmdQ.AddMessage(cmd);
     return message;
 }
开发者ID:hudpoi459,项目名称:Info344,代码行数:25,代码来源:Admin.asmx.cs

示例10: DeleteMessage

 public Task DeleteMessage(CloudQueueMessage message, QueueRequestOptions options = null, OperationContext operationContext = null, CancellationToken? cancellationToken = null)
 {
     return AsyncTaskUtil.RunAsyncCancellable(
         _inner.BeginDeleteMessage(message, options, operationContext, null, null),
         _inner.EndDeleteMessage,
         cancellationToken);
 }
开发者ID:Porges,项目名称:azure-storage-async,代码行数:7,代码来源:AsyncCloudQueue.cs

示例11: processQueueMessage

        protected override void processQueueMessage(CloudQueueMessage message)
        {
            base.processQueueMessage(message);

            var rawData = message.AsBytes;
            var stream = new MemoryStream(rawData);
            stream.Seek(0, SeekOrigin.Begin);

            var bFrmt = new BinaryFormatter();
            var resObject = bFrmt.Deserialize(stream);

            if (resObject is CloudQueueBlobMessage)
            {
                var cqbm = resObject as CloudQueueBlobMessage;
                var msgContentRef = container.GetBlockBlobReference(cqbm.BlobName);

                var msRes = new MemoryStream();
                msgContentRef.DownloadToStream(msRes);
                msRes.Seek(0, SeekOrigin.Begin);

                resObject = bFrmt.Deserialize(msRes);
            }

            processMessage(resObject);
        }
开发者ID:NewMediaCenterMoscow,项目名称:UniSocial3,代码行数:25,代码来源:BaseMessageBlobWorker.cs

示例12: AddMessage

 public Task AddMessage(CloudQueueMessage message, TimeSpan? timeToLive = null, TimeSpan? initialVisibilityDelay = null, QueueRequestOptions options = null, OperationContext operationContext = null, CancellationToken? cancellationToken = null)
 {
     return AsyncTaskUtil.RunAsyncCancellable(
         _inner.BeginAddMessage(message, timeToLive, initialVisibilityDelay, options, operationContext, null, null),
         _inner.EndAddMessage,
         cancellationToken);
 }
开发者ID:Porges,项目名称:azure-storage-async,代码行数:7,代码来源:AsyncCloudQueue.cs

示例13: Index

        public ActionResult Index(SendViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.SendBy == 0)
                    HostingEnvironment.QueueBackgroundWorkItem(ct => MessageSender.SendAsync(model));
                else if (model.SendBy == 1)
                {
                    BackgroundJob.Enqueue(() => MessageSender.SendWithEvent(model));
                }
                else
                {
                    //TODO send queue message to use WebJobs
                    var storageAccount = CloudStorageAccount.Parse(
                        ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ConnectionString);
                    var queueClient = storageAccount.CreateCloudQueueClient();
                    var queue = queueClient.GetQueueReference("pending-mail");

                    // Create the queue if it doesn't already exist
                    queue.CreateIfNotExists();

                    var message = new CloudQueueMessage(JsonConvert.SerializeObject(model));
                    queue.AddMessage(message);
                }
                return RedirectToAction("Pending");
            }

            return View(model);
        }
开发者ID:yonglehou,项目名称:MailSender,代码行数:29,代码来源:SendController.cs

示例14: QueueListenerTests

        public QueueListenerTests()
        {
            CloudQueue queue = new CloudQueue(new Uri("https://test.queue.core.windows.net/testqueue"));
            Mock<IStorageQueue> mockQueue = new Mock<IStorageQueue>(MockBehavior.Strict);
            mockQueue.Setup(p => p.SdkObject).Returns(queue);

            _mockTriggerExecutor = new Mock<ITriggerExecutor<IStorageQueueMessage>>(MockBehavior.Strict);
            Mock<IDelayStrategy> mockDelayStrategy = new Mock<IDelayStrategy>(MockBehavior.Strict);
            Mock<IBackgroundExceptionDispatcher> mockExceptionDispatcher = new Mock<IBackgroundExceptionDispatcher>(MockBehavior.Strict);
            TextWriter log = new StringWriter();
            Mock<IQueueProcessorFactory> mockQueueProcessorFactory = new Mock<IQueueProcessorFactory>(MockBehavior.Strict);
            JobHostQueuesConfiguration queuesConfig = new JobHostQueuesConfiguration();
            QueueProcessorFactoryContext context = new QueueProcessorFactoryContext(queue, log, queuesConfig);

            _mockQueueProcessor = new Mock<QueueProcessor>(MockBehavior.Strict, context);
            JobHostQueuesConfiguration queueConfig = new JobHostQueuesConfiguration
            {
                MaxDequeueCount = 5,
                QueueProcessorFactory = mockQueueProcessorFactory.Object
            };

            mockQueueProcessorFactory.Setup(p => p.Create(It.IsAny<QueueProcessorFactoryContext>())).Returns(_mockQueueProcessor.Object);

            _listener = new QueueListener(mockQueue.Object, null, _mockTriggerExecutor.Object, mockDelayStrategy.Object, mockExceptionDispatcher.Object, log, null, queueConfig);

            CloudQueueMessage cloudMessage = new CloudQueueMessage("TestMessage");
            _storageMessage = new StorageQueueMessage(cloudMessage);
        }
开发者ID:Bjakes1950,项目名称:azure-webjobs-sdk,代码行数:28,代码来源:QueueListenerTests.cs

示例15: Remove

 public void Remove(CloudQueueMessage message)
 {
     if (message != null)
     {
         _queue.DeleteMessage(message);
     }
 }
开发者ID:rahulkarnthobb,项目名称:Ijepai-Poc,代码行数:7,代码来源:AzureMessageQueueProvider.cs


注:本文中的Microsoft.WindowsAzure.Storage.Queue.CloudQueueMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。