Exemplo n.º 1
0
        private SendMessageBatchResponse DoSendMessageBatch(SendMessageBatchRequest request)
        {
            if (request.Entries.Count == 0)
                throw new ArgumentOutOfRangeException();

            List<string> lParams = new List<string>();

            lParams.Add(string.Format("&AWSAccessKeyId={0}", Util.UrlEncode(AccessKey)));
            lParams.Add(string.Format("&Action={0}", "SendMessageBatch"));
            lParams.Add(string.Format("&SignatureMethod={0}", "HmacSHA256"));
            lParams.Add(string.Format("&SignatureVersion={0}", "2"));
            lParams.Add(string.Format("&Timestamp={0}", Util.UrlEncode(DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"))));
            lParams.Add(string.Format("&Version={0}", "2012-11-05"));

            for (int i = 0; i < request.Entries.Count; i++)
            {
                lParams.Add(string.Format("&SendMessageBatchRequestEntry.{0}.Id={1}", i + 1, Util.UrlEncode(request.Entries[i].Id)));
                lParams.Add(string.Format("&SendMessageBatchRequestEntry.{0}.DelaySeconds={1}", i + 1, request.Entries[i].DelaySeconds));
                lParams.Add(string.Format("&SendMessageBatchRequestEntry.{0}.MessageBody={1}", i + 1, Util.UrlEncode(request.Entries[i].MessageBody)));
            }

            lParams.Sort(StringComparer.Ordinal);

            var parameters = string.Join("", lParams);
            parameters = parameters.Substring(1);

            string sig = Util.GetSignature(request.QueueUrl, "GET", parameters, SecretKey);
            parameters = string.Format("{0}&Signature={1}", parameters, Util.UrlEncode(sig));

            var wRequest = WebRequest.Create(string.Format("{0}?{1}", request.QueueUrl, parameters)) as HttpWebRequest;
            wRequest.Method = "GET";
            wRequest.ContentType = "application/x-www-form-urlencoded";
            wRequest.KeepAlive = false;

            using (var response = wRequest.GetResponse())
            using (var stream = response.GetResponseStream())
            using (var reader = new StreamReader(stream))
            {
                var body = reader.ReadToEnd();
                var element = XElement.Parse(body);

                XmlSerializer serializer = new XmlSerializer(typeof(SendMessageBatchResponse));
                var sendMessageBatchResponse = (SendMessageBatchResponse)serializer.Deserialize(element.CreateReader());
                return sendMessageBatchResponse;
            }
        }
Exemplo n.º 2
0
 public SendMessageBatchResponse SendMessageBatch(SendMessageBatchRequest request)
 {
     return Util.RetryMethod<SendMessageBatchResponse>(() => DoSendMessageBatch(request), RetryCount);
 }