Ejemplo n.º 1
0
        public GetQueueAttributesResponse DoGetQueueAttributes(GetQueueAttributesRequest request)
        {
            List<string> lParams = new List<string>();

            lParams.Add(string.Format("&AWSAccessKeyId={0}", Util.UrlEncode(AccessKey)));
            lParams.Add(string.Format("&Action={0}", "GetQueueAttributes"));
            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.AttributeNames.Count; i++)
            {
                lParams.Add(string.Format("&AttributeName.{0}={1}", i + 1, Util.UrlEncode(request.AttributeNames[i])));
            }

            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() as HttpWebResponse)
            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(GetQueueAttributesResponse));
                var setQueueAttributesResponse = (GetQueueAttributesResponse)serializer.Deserialize(element.CreateReader());

                foreach (var attribute in setQueueAttributesResponse.GetQueueAttributesResult.Attributes)
                {
                    var propType = typeof(GetQueueAttributesResult).GetProperty(attribute.Name);
                    var converter = TypeDescriptor.GetConverter(propType.PropertyType);
                    var value = converter.ConvertFromString(attribute.Value);
                    propType.SetValue(setQueueAttributesResponse.GetQueueAttributesResult, value);
                }

                return setQueueAttributesResponse;
            }
        }
Ejemplo n.º 2
0
 public GetQueueAttributesResponse GetQueueAttributes(GetQueueAttributesRequest request)
 {
     return Util.RetryMethod<GetQueueAttributesResponse>(() => DoGetQueueAttributes(request), RetryCount);
 }