Esempio n. 1
0
        protected static List<Message> FormatMessagesFromInputStream(Queue queue, System.IO.TextReader tr)
        {
            List<Message> lMessages = new List<Message>();

            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.Load(tr);

            foreach (System.Xml.XmlNode n in doc.SelectNodes("QueueMessagesList/QueueMessage"))
            {
                Message msg = new Message()
                {
                    MessageId = Guid.Parse(n.SelectSingleNode("MessageId").InnerText),
                    InsertTime = DateTime.Parse(n.SelectSingleNode("InsertionTime").InnerText),
                    ExpirationTime = DateTime.Parse(n.SelectSingleNode("ExpirationTime").InnerText),
                    DequeueCount = int.Parse(n.SelectSingleNode("DequeueCount").InnerText),
                    Body = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(n.SelectSingleNode("MessageText").InnerText)),
                    Queue = queue
                };

                if (n.SelectSingleNode("PopReceipt") != null)
                    msg.PopReceipt = n.SelectSingleNode("PopReceipt").InnerText;

                if (n.SelectSingleNode("TimeNextVisible") != null)
                    msg.TimeNextVisible = DateTime.Parse(n.SelectSingleNode("TimeNextVisible").InnerText);

                lMessages.Add(msg);
            }

            return lMessages;
        }
Esempio n. 2
0
        public Dictionary<string, string> PutMessage(
            Message message,
            int timeoutSeconds = 0,
           Guid? xmsclientrequestId = null)
        {
            int visibilitytimeoutSeconds = 0;
            if (message.TimeNextVisible.HasValue)
                visibilitytimeoutSeconds = Math.Max(0, (int)(message.TimeNextVisible.Value - DateTime.Now).TotalSeconds);

            int messageTTLSeconds = (int)(message.ExpirationTime - DateTime.Now).TotalSeconds;

            var ret = Internal.InternalMethods.PutMessage(
                this.AzureQueueService.UseHTTPS,
                this.AzureQueueService.SharedKey,
                this.AzureQueueService.AccountName,
                Name,
                string.Format(
                    "<QueueMessage><MessageText>{0:S}</MessageText></QueueMessage>",
                    Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(message.Body))),
                    visibilitytimeoutSeconds,
                    messageTTLSeconds,
                    timeoutSeconds,
                    xmsclientrequestId);

            message.InsertTime = DateTime.Now;
            message.Queue = this;
            return ret;
        }