Exemplo n.º 1
0
 public void TerminateInstances(TerminateInstancesRequest request)
 {
     Util.RetryMethod(() => DoTerminateInstances(request), RetryCount);
 }
Exemplo n.º 2
0
        public void DoTerminateInstances(TerminateInstancesRequest request)
        {
            int PostMessageSize = 9;

            for (var i = 0; i < request.InstanceIds.Count; i += PostMessageSize)
            {
                List<string> chunk = request.InstanceIds.Skip(i).Take(PostMessageSize).ToList();

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

                lParams.Add(string.Format("AWSAccessKeyId={0}", Util.UrlEncode(AccessKey)));
                lParams.Add(string.Format("Action={0}", "TerminateInstances"));
                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-07-20"));

                for (int a = 0; a < chunk.Count; a++)
                {
                    lParams.Add(string.Format("InstanceId.{0}={1}", a + 1, Util.UrlEncode(chunk[a])));
                }

                lParams.Sort(StringComparer.Ordinal);

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

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

                var wRequest = WebRequest.Create(string.Format("{0}?{1}", URL, 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(TerminateInstancesResponse));
                    var terminateInstancesResponse = (TerminateInstancesResponse)serializer.Deserialize(element.CreateReader());
                }
            }
        }