Click here to Skip to main content
15,886,788 members
Articles / Programming Languages / C#

Amazon S3 Sync

Rate me:
Please Sign up or sign in to vote.
4.92/5 (6 votes)
1 Dec 2010Apache5 min read 47.9K   1.6K   23  
Synchronize files from your computer to Amazon S3.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace AllServicesGettingStarted
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            //when the form loads, set the text box values from the saved settings
            Properties.Settings MySettings = new Properties.Settings();
            TextBoxAWSAccessKeyId.Text = MySettings.AWSAccessKeyId;
            TextBoxAWSSecretAccessKey.Text = MySettings.AWSSecretAccessKey;
        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            //when the form closes, save the text box values
            Properties.Settings MySettings = new Properties.Settings();
            MySettings.AWSAccessKeyId = TextBoxAWSAccessKeyId.Text;
            MySettings.AWSSecretAccessKey = TextBoxAWSSecretAccessKey.Text;
            MySettings.Save();
        }

        private void LinkLabelGetAmazonAccount_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("http://aws.amazon.com/");
        }
 
        private String FormatLogData(String RequestURL, String RequestMethod, Dictionary<String, String> RequestHeaders, int ResponseStatusCode, String ResponseStatusDescription, Dictionary<String, String> ResponseHeaders, String ResponseString, int ErrorNumber, String ErrorDescription)
        {
            String ReturnString = "";

            if (ErrorNumber != 0)
            {
                ReturnString += "SprightlySoft ErrorDescription: " + ErrorDescription + Environment.NewLine ;
                ReturnString += "SprightlySoft ErrorNumber: " + ErrorNumber + Environment.NewLine;
                ReturnString += Environment.NewLine;
            }

            if (ResponseStatusCode != 0)
            {
                ReturnString += "Request URL: " + RequestURL + Environment.NewLine ;
                ReturnString += "Request Method: " + RequestMethod + Environment.NewLine;

                foreach (KeyValuePair<String, String> MyHeader in RequestHeaders)
                {
                    ReturnString += "Request Header: " + MyHeader.Key + ":" + MyHeader.Value + Environment.NewLine;
                }

                ReturnString += Environment.NewLine;
                ReturnString += "Response Status Code: " + ResponseStatusCode + Environment.NewLine;
                ReturnString += "Response Status Description: " + ResponseStatusDescription + Environment.NewLine;

                foreach (KeyValuePair<String, String> MyHeader in ResponseHeaders)
                {
                    ReturnString += "Response Header: " + MyHeader.Key + ":" + MyHeader.Value + Environment.NewLine;
                }

                if (ResponseString != "")
                {
                    ReturnString += Environment.NewLine;

                    try
                    {
                        System.Xml.XmlDocument XmlDoc = new System.Xml.XmlDocument();
                        XmlDoc.LoadXml(ResponseString);

                        ReturnString += "Response XML: " + Environment.NewLine + ResponseString + Environment.NewLine;

                        System.Xml.XmlNode XmlNode;
                        XmlNode = XmlDoc.SelectSingleNode("/Error/Message");

                        if (XmlNode != null)
                        {
                            ReturnString += Environment.NewLine;
                            ReturnString += "Amazon Error Message: " + XmlNode.InnerText + Environment.NewLine;
                        }
                    }
                    catch (Exception e)
                    {
                        ReturnString += "Response String: " + Environment.NewLine + ResponseString + Environment.NewLine;
                    }

                }
            }

            return ReturnString;
        }


        private void ButtonEC2DescribeImages_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //Amazon Elastic Compute Cloud (EC2), DescribeImages: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeImages.html

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            String  RequestURL;
            RequestURL = "https://ec2.amazonaws.com/?Action=DescribeImages&Version=2010-08-31";
            RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));
            RequestURL += "&Filter.1.Name=is-public&Filter.1.Value.1=true";
            RequestURL += "&Filter.2.Name=architecture&Filter.2.Value.1=x86_64";
            RequestURL += "&Filter.3.Name=platform&Filter.3.Value.1=windows";

            String RequestMethod;
            RequestMethod = "GET";

            String SignatureValue;
            SignatureValue = MyREST.GetSignatureVersion2Value(RequestURL, RequestMethod, "", TextBoxAWSSecretAccessKey.Text);

            RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);

            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            if (RetBool == true)
            {
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
                System.Xml.XmlNode MyXmlNode;
                System.Xml.XmlNodeList MyXmlNodeList;

                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(MyREST.ResponseString);

                MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                MyXmlNamespaceManager.AddNamespace("amz", "http://ec2.amazonaws.com/doc/2010-08-31/");

                MyXmlNodeList = MyXmlDocument.SelectNodes("amz:DescribeImagesResponse/amz:imagesSet/amz:item", MyXmlNamespaceManager);

                if (MyXmlNodeList.Count == 0)
                {
                    ResponseMessage = "No images found.";
                }
            else
                {                
                foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                {
                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:imageId", MyXmlNamespaceManager);
                        ResponseMessage += "imageId = " + MyXmlNode.InnerText;

                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:name", MyXmlNamespaceManager);
                        if (MyXmlNode != null)
                        {
                            ResponseMessage += "   Name = " + MyXmlNode.InnerText;
                        }

                        ResponseMessage += Environment.NewLine;
                    }
                }

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Success";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }
            else
            {
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }

	    private void ButtonElasticMapReduceDescribeJobFlows_Click(object sender, EventArgs e)
	    {
	        (sender as Button).Enabled = false;

	        //Amazon Elastic MapReduce, DescribeJobFlows: http://docs.amazonwebservices.com/ElasticMapReduce/latest/API/API_DescribeJobFlows.html

	        SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

	        //the CreatedBefore parameter is set so you can see how to format the value
	        DateTime CreatedBefore;
	        CreatedBefore = DateTime.Now;

	        String  RequestURL;
	        RequestURL = "https://elasticmapreduce.amazonaws.com/?Operation=DescribeJobFlows&Version=2009-03-31";
	        RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));
	        RequestURL += "&CreatedBefore=" + Uri.EscapeDataString(CreatedBefore.ToUniversalTime().ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));

	        String RequestMethod;
	        RequestMethod = "GET";

	        String SignatureValue;
	        SignatureValue = MyREST.GetSignatureVersion2Value(RequestURL, RequestMethod, "", TextBoxAWSSecretAccessKey.Text);

	        RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

	        Boolean RetBool;
	        RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);

	        System.Diagnostics.Debug.Print("");
	        System.Diagnostics.Debug.Print(MyREST.LogData);
	        System.Diagnostics.Debug.Print("");

	        String ResponseMessage = "";

	        if (RetBool == true)
	        {
		        System.Xml.XmlDocument MyXmlDocument;
		        System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
		        System.Xml.XmlNode MyXmlNode;
		        System.Xml.XmlNodeList MyXmlNodeList;

		        MyXmlDocument = new System.Xml.XmlDocument();
		        MyXmlDocument.LoadXml(MyREST.ResponseString);

		        MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
		        MyXmlNamespaceManager.AddNamespace("amz", "http://elasticmapreduce.amazonaws.com/doc/2009-03-31");

		        MyXmlNodeList = MyXmlDocument.SelectNodes("amz:DescribeJobFlowsResponse/amz:DescribeJobFlowsResult/amz:JobFlows/amz:member", MyXmlNamespaceManager);

		        if (MyXmlNodeList.Count == 0)
                {
			        ResponseMessage = "No job flows exist.";
		        }
                else
                {
			        foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                    {
				        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:Name", MyXmlNamespaceManager);
				        ResponseMessage += "Name = " + MyXmlNode.InnerText;

				        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:ExecutionStatusDetail/amz:CreationDateTime", MyXmlNamespaceManager);
				        ResponseMessage += "   CreationDateTime = " + MyXmlNode.InnerText;

				        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:ExecutionStatusDetail/amz:State", MyXmlNamespaceManager);
				        ResponseMessage += "   State = " + MyXmlNode.InnerText;

				        ResponseMessage += Environment.NewLine;
			        }
		        }

			    DialogOutput MyDialogOutput = new DialogOutput();
			    MyDialogOutput.Text = "Success";
			    MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
			    MyDialogOutput.ShowDialog(this);
	        }
            else
            {
		        ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

			    DialogOutput MyDialogOutput = new DialogOutput();
			    MyDialogOutput.Text = "Error";
			    MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
			    MyDialogOutput.ShowDialog(this);
	        }

	        (sender as Button).Enabled = true;
	    }

        private void ButtonAutoScalingDescribeAutoScalingGroups_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //Auto Scaling, DescribeAutoScalingGroups: http://docs.amazonwebservices.com/AutoScaling/latest/DeveloperGuide/API_DescribeAutoScalingGroups.html

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            String  RequestURL;
            RequestURL = "https://autoscaling.amazonaws.com/?Action=DescribeAutoScalingGroups&Version=2009-05-15";
            RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&SignatureVersion=2&SignatureMethod=HmacSHA1&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));
            RequestURL += "&AutoScalingGroupNames.member.1=webtier";

            String RequestMethod;
            RequestMethod = "GET";

            String SignatureValue;
            SignatureValue = MyREST.GetSignatureVersion2Value(RequestURL, RequestMethod, "", TextBoxAWSSecretAccessKey.Text);

            RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);

            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            if (RetBool == true)
            {
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
                System.Xml.XmlNode MyXmlNode;
                System.Xml.XmlNodeList MyXmlNodeList;

                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(MyREST.ResponseString);

                MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                MyXmlNamespaceManager.AddNamespace("amz", "http://autoscaling.amazonaws.com/doc/2009-05-15/");

                MyXmlNodeList = MyXmlDocument.SelectNodes("amz:DescribeAutoScalingGroupsResponse/amz:DescribeAutoScalingGroupsResult/amz:AutoScalingGroups/amz:member", MyXmlNamespaceManager);

                if (MyXmlNodeList.Count == 0)
                {
                    ResponseMessage = "No auto scaling groups exist.";
                }
                else
                {
                    foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                    {
                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:AutoScalingGroupName", MyXmlNamespaceManager);
                        ResponseMessage += "AutoScalingGroupName = " + MyXmlNode.InnerText;

                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:CreatedTime", MyXmlNamespaceManager);
                        ResponseMessage += "   CreatedTime = " + MyXmlNode.InnerText;

                        ResponseMessage += Environment.NewLine;
                    }
                }

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Success";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }
            else
            {
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }

        private void ButtonCloudFrontGETDistributionList_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //CloudFront, GET Distribution List: http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/ListDistributions.html

            String Marker = "";
            int MaxItems = 100;  //100 is the maximum number of distributions you want in the response body
            Boolean IsTruncated = false;

            Boolean RetBool;
            System.Xml.XmlDocument MyXmlDocument;
            System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
            System.Xml.XmlNode MyXmlNode;
            System.Xml.XmlNodeList MyXmlNodeList;
            String ResponseMessage = "";

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();
            String  RequestURL;
            Dictionary<String, String> ExtraRequestHeaders = new Dictionary<String, String>();
            String AmzDate;
            String AuthorizationValue;

            //put the following code in a loop as we may be listing many pages
            do
            {
                RequestURL = "https://cloudfront.amazonaws.com/2010-11-01/distribution?Marker=" + System.Uri.EscapeDataString(Marker) + "&MaxItems=" + System.Uri.EscapeDataString(MaxItems.ToString());

                ExtraRequestHeaders = new Dictionary<String, String>();

                AmzDate = DateTime.UtcNow.ToString("r");
                ExtraRequestHeaders.Add("x-amz-date", AmzDate);

                AuthorizationValue = MyREST.GetCloudFrontAuthorizationValue(TextBoxAWSAccessKeyId.Text, TextBoxAWSSecretAccessKey.Text, AmzDate);
                ExtraRequestHeaders.Add("Authorization", AuthorizationValue);

                RetBool = MyREST.MakeRequest(RequestURL, "GET", ExtraRequestHeaders, "");

                System.Diagnostics.Debug.Print("");
                System.Diagnostics.Debug.Print(MyREST.LogData);
                System.Diagnostics.Debug.Print("");

                if (RetBool == true)
                {
                    MyXmlDocument = new System.Xml.XmlDocument();
                    MyXmlDocument.LoadXml(MyREST.ResponseString);

                    MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                    MyXmlNamespaceManager.AddNamespace("amz", "http://cloudfront.amazonaws.com/doc/2010-11-01/");

                    MyXmlNode = MyXmlDocument.SelectSingleNode("amz:DistributionList/amz:NextMarker", MyXmlNamespaceManager);
                    if (MyXmlNode != null)
                    {
                        //set the Marker to the NextMarker value
                        Marker = MyXmlNode.InnerText;
                    }

                    MyXmlNode = MyXmlDocument.SelectSingleNode("amz:DistributionList/amz:IsTruncated", MyXmlNamespaceManager);
                    IsTruncated = Convert.ToBoolean(MyXmlNode.InnerText);

                    MyXmlNodeList = MyXmlDocument.SelectNodes("amz:DistributionList/amz:DistributionSummary", MyXmlNamespaceManager);

                    if (MyXmlNodeList.Count == 0)
                    {
                        ResponseMessage = "No distributions exist.";
                    }
                    else
                    {
                        foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                        {
                            MyXmlNode = ItemXmlNode.SelectSingleNode("amz:Id", MyXmlNamespaceManager);
                            ResponseMessage = ResponseMessage + "Id = " + MyXmlNode.InnerText;

                            MyXmlNode = ItemXmlNode.SelectSingleNode("amz:Status", MyXmlNamespaceManager);
                            ResponseMessage = ResponseMessage + "     Status = " + MyXmlNode.InnerText;

                            MyXmlNode = ItemXmlNode.SelectSingleNode("amz:LastModifiedTime", MyXmlNamespaceManager);
                            ResponseMessage = ResponseMessage + "     LastModifiedTime = " + Convert.ToDateTime(MyXmlNode.InnerText);

                            MyXmlNode = ItemXmlNode.SelectSingleNode("amz:DomainName", MyXmlNamespaceManager);
                            ResponseMessage = ResponseMessage + "     DomainName = " + MyXmlNode.InnerText;

                            MyXmlNode = ItemXmlNode.SelectSingleNode("amz:Origin", MyXmlNamespaceManager);
                            ResponseMessage = ResponseMessage + "     Origin = " + MyXmlNode.InnerText;

                            MyXmlNode = ItemXmlNode.SelectSingleNode("amz:CNAME", MyXmlNamespaceManager);
                            if (MyXmlNode != null)
                            {
                                ResponseMessage = ResponseMessage + "     CNAME = " + MyXmlNode.InnerText;
                            }

                            MyXmlNode = ItemXmlNode.SelectSingleNode("amz:Comment", MyXmlNamespaceManager);
                            if (MyXmlNode != null)
                            {
                                ResponseMessage = ResponseMessage + "     Comment = " + MyXmlNode.InnerText;
                            }

                            MyXmlNode = ItemXmlNode.SelectSingleNode("amz:Enabled", MyXmlNamespaceManager);
                            ResponseMessage = ResponseMessage + "     Enabled = " + MyXmlNode.InnerText;

                            MyXmlNode = ItemXmlNode.SelectSingleNode("amz:TrustedSigners/amz:Self", MyXmlNamespaceManager);
                            if (MyXmlNode != null)
                            {
                                ResponseMessage = ResponseMessage + "     TrustedSigners Self = " + MyXmlNode.InnerText;
                            }

                            MyXmlNode = ItemXmlNode.SelectSingleNode("amz:TrustedSigners/amz:AwsAccountNumber", MyXmlNamespaceManager);
                            if (MyXmlNode != null)
                            {
                                ResponseMessage = ResponseMessage + "     TrustedSigners AwsAccountNumber = " + MyXmlNode.InnerText;
                            }

                            ResponseMessage = ResponseMessage + Environment.NewLine;
                        }
                    }

                }
                else
                {
                    ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                    DialogOutput MyDialogOutput = new DialogOutput();
                    MyDialogOutput.Text = "Error";
                    MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                    MyDialogOutput.ShowDialog(this);

                    break;
                }

                if (IsTruncated == false)
                {
                    //if there are no more pages to get, show the output and exit
                    DialogOutput MyDialogOutput = new DialogOutput();
                    MyDialogOutput.Text = "Success";
                    MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                    MyDialogOutput.ShowDialog(this);

                    break;
                }

            } while (IsTruncated == true);

            (sender as Button).Enabled = true;
        }

        private void ButtonSimpleDBListDomains_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //Amazon SimpleDB, ListDomains: http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide/SDB_API_ListDomains.html

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            String  RequestURL;
            RequestURL = "https://sdb.amazonaws.com/";

            //You can post parameters instead of putting them in the query string.  This is useful if you want to avoid creating a URL that is too long when sending many parameters.
            String PostData;
            PostData = "Action=ListDomains&Version=2009-04-15&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));

            String RequestMethod;
            RequestMethod = "POST";

            String SignatureValue;
            SignatureValue = MyREST.GetSignatureVersion2Value(RequestURL, RequestMethod, PostData, TextBoxAWSSecretAccessKey.Text);

            PostData += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

            Dictionary<String, String> ExtraRequestHeaders = new Dictionary<String, String>();
            ExtraRequestHeaders.Add("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");

            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, ExtraRequestHeaders, PostData);

            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            if (RetBool == true)
            {
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
                System.Xml.XmlNodeList MyXmlNodeList;

                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(MyREST.ResponseString);

                MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                MyXmlNamespaceManager.AddNamespace("amz", "http://autoscaling.amazonaws.com/doc/2009-05-15/");

                MyXmlNodeList = MyXmlDocument.SelectNodes("amz:ListDomainsResponse/amz:ListDomainsResult/amz:DomainName", MyXmlNamespaceManager);

                if (MyXmlNodeList.Count == 0)
                {
                    ResponseMessage = "No SimpleDB domains exist.";
                }
                else
                {
                    foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                    {
                        ResponseMessage += "DomainName = " + ItemXmlNode.InnerText;

                        ResponseMessage += Environment.NewLine;
                    }
                }

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Success";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }
            else
            {
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }

        private void ButtonRDSDescribeDBInstances_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //Amazon Relational Database Service (RDS), DescribeDBInstances: http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/APIDescribeDBInstances.html

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            String  RequestURL;
            RequestURL = "https://rds.amazonaws.com/?Action=DescribeDBInstances&Version=2010-07-28";
            RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));

            String RequestMethod;
            RequestMethod = "GET";

            String SignatureValue;
            SignatureValue = MyREST.GetSignatureVersion2Value(RequestURL, RequestMethod, "", TextBoxAWSSecretAccessKey.Text);

            RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);

            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            if (RetBool == true)
            {
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
                System.Xml.XmlNode MyXmlNode;
                System.Xml.XmlNodeList MyXmlNodeList;

                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(MyREST.ResponseString);

                MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                MyXmlNamespaceManager.AddNamespace("amz", "http://rds.amazonaws.com/doc/2010-07-28/");

                MyXmlNodeList = MyXmlDocument.SelectNodes("amz:DescribeDBInstancesResponse/amz:DescribeDBInstancesResult/amz:DBInstances/amz:DBInstance", MyXmlNamespaceManager);

                if (MyXmlNodeList.Count == 0)
                {
                    ResponseMessage = "No instances exist.";
                }
                else
                {
                    foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                    {
                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:DBInstanceIdentifier", MyXmlNamespaceManager);
                        ResponseMessage += "DBInstanceIdentifier = " + MyXmlNode.InnerText;

                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:DBInstanceStatus", MyXmlNamespaceManager);
                        ResponseMessage += "   DBInstanceStatus = " + MyXmlNode.InnerText;

                        ResponseMessage += Environment.NewLine;
                    }
                }

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Success";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }
            else
            {
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }

        private void ButtonFWSListAllFulfillmentOrders_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //Amazon Fulfillment Web Service (FWS), ListAllFulfillmentOrders: http://docs.amazonwebservices.com/fws/latest/APIReference/ListAllFulfillmentOrders.html

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            String  RequestURL;
            RequestURL = "https://fba-outbound.amazonaws.com/?Action=ListAllFulfillmentOrders&Version=2007-08-02";
            RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));
            RequestURL += "&NumberOfResultsRequested=3";

            String RequestMethod;
            RequestMethod = "GET";

            String SignatureValue;
            SignatureValue = MyREST.GetFulfillmentWebServiceSignatureValue(RequestURL, TextBoxAWSSecretAccessKey.Text);

            RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);

            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            if (RetBool == true)
            {
                System.Xml.XmlDocument EnvelopeXmlDocument;
                System.Xml.XmlNamespaceManager EnvelopeXmlNamespaceManager;
                System.Xml.XmlNode EnvelopeXmlNode;
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
                System.Xml.XmlNode MyXmlNode;
                System.Xml.XmlNodeList MyXmlNodeList;

                EnvelopeXmlDocument = new System.Xml.XmlDocument();
                EnvelopeXmlDocument.LoadXml(MyREST.ResponseString);

                EnvelopeXmlNamespaceManager = new System.Xml.XmlNamespaceManager(EnvelopeXmlDocument.NameTable);
                EnvelopeXmlNamespaceManager.AddNamespace("env", "http://schemas.xmlsoap.org/soap/envelope/");

                EnvelopeXmlNode = EnvelopeXmlDocument.SelectSingleNode("env:Envelope/env:Body", EnvelopeXmlNamespaceManager);

                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(EnvelopeXmlNode.InnerXml);

                MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                MyXmlNamespaceManager.AddNamespace("amz", "http://fba-outbound.amazonaws.com/doc/2007-08-02/");

                MyXmlNodeList = MyXmlDocument.SelectNodes("amz:ListAllFulfillmentOrdersResponse/amz:ListAllFulfillmentOrdersResult/amz:FulfillmentOrder", MyXmlNamespaceManager);

                if (MyXmlNodeList.Count == 0)
                {
                    ResponseMessage = "No fulfillment orders exist.";
                }
                else
                {
                    foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                    {
                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:MerchantFulfillmentOrderId", MyXmlNamespaceManager);
                        ResponseMessage += "MerchantFulfillmentOrderId = " + MyXmlNode.InnerText;

                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:ReceivedDateTime", MyXmlNamespaceManager);
                        ResponseMessage += "   ReceivedDateTime = " + MyXmlNode.InnerText;

                        ResponseMessage += Environment.NewLine;
                    }
                }

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Success";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }
            else
            {
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }

        private void ButtonIAMListUsers_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //AWS Identity and Access Management (IAM), ListUsers: http://docs.amazonwebservices.com/IAM/latest/APIReference/API_ListUsers.html

            String Marker = "";
            int MaxItems = 100;
            String PathPrefix = "";
            Boolean IsTruncated = false;

            Boolean RetBool;
            System.Xml.XmlDocument MyXmlDocument;
            System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
            System.Xml.XmlNode MyXmlNode;
            System.Xml.XmlNodeList MyXmlNodeList;
            String ResponseMessage = "";

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();
            String  RequestURL;
            String RequestMethod;

            //put the following code in a loop as we may be listing many pages
            do
            {
                RequestURL = "https://iam.amazonaws.com/?Action=ListUsers&Version=2010-05-08&MaxItems=" + System.Uri.EscapeDataString(MaxItems.ToString());
                RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));
                if (Marker != "")
                {
                    RequestURL += "&Marker=" + System.Uri.EscapeDataString(Marker);
                }
                if (PathPrefix != "")
                {
                    RequestURL += "&PathPrefix=" + System.Uri.EscapeDataString(PathPrefix);
                }

                RequestMethod = "GET";

                String SignatureValue;
                SignatureValue = MyREST.GetSignatureVersion2Value(RequestURL, RequestMethod, "", TextBoxAWSSecretAccessKey.Text);

                RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

                RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);

                System.Diagnostics.Debug.Print("");
                System.Diagnostics.Debug.Print(MyREST.LogData);
                System.Diagnostics.Debug.Print("");

                if (RetBool == true)
                {
                    MyXmlDocument = new System.Xml.XmlDocument();
                    MyXmlDocument.LoadXml(MyREST.ResponseString);

                    MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                    MyXmlNamespaceManager.AddNamespace("amz", "https://iam.amazonaws.com/doc/2010-05-08/");

                    MyXmlNode = MyXmlDocument.SelectSingleNode("amz:ListUsersResponse/amz:ListUsersResult/amz:IsTruncated", MyXmlNamespaceManager);
                    IsTruncated = Convert.ToBoolean(MyXmlNode.InnerText);

                    MyXmlNodeList = MyXmlDocument.SelectNodes("amz:ListUsersResponse/amz:ListUsersResult/amz:Users/amz:member", MyXmlNamespaceManager);

                    if (MyXmlNodeList.Count == 0)
                    {
                        ResponseMessage = "No users exist.";
                    }
                    else
                    {
                        foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                        {
                            MyXmlNode = ItemXmlNode.SelectSingleNode("amz:UserName", MyXmlNamespaceManager);
                            ResponseMessage = ResponseMessage + "UserName = " + MyXmlNode.InnerText;

                            MyXmlNode = ItemXmlNode.SelectSingleNode("amz:UserId", MyXmlNamespaceManager);
                            ResponseMessage = ResponseMessage + "     UserId = " + MyXmlNode.InnerText;

                            ResponseMessage = ResponseMessage + Environment.NewLine;
                        }
                    }
                }
                else
                {
                    ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                    DialogOutput MyDialogOutput = new DialogOutput();
                    MyDialogOutput.Text = "Error";
                    MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                    MyDialogOutput.ShowDialog(this);

                    break;
                }

                if (IsTruncated == false)
                {
                    //if there are no more pages to get, show the output and exit
                    DialogOutput MyDialogOutput = new DialogOutput();
                    MyDialogOutput.Text = "Success";
                    MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                    MyDialogOutput.ShowDialog(this);

                    break;
                }

            } while (IsTruncated == true);

            (sender as Button).Enabled = true;
        }

        private void ButtonSQSListQueues_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //Amazon Simple Queue Service (SQS), ListQueues: http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QueryListQueues.html

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            String  RequestURL;
            RequestURL = "https://sqs.us-east-1.amazonaws.com/?Action=ListQueues&Version=2009-02-01";
            RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));

            String RequestMethod;
            RequestMethod = "GET";

            String SignatureValue;
            SignatureValue = MyREST.GetSignatureVersion2Value(RequestURL, RequestMethod, "", TextBoxAWSSecretAccessKey.Text);

            RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);

            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            if (RetBool == true)
            {
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
                System.Xml.XmlNodeList MyXmlNodeList;

                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(MyREST.ResponseString);

                MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                MyXmlNamespaceManager.AddNamespace("amz", "http://queue.amazonaws.com/doc/2009-02-01/");

                MyXmlNodeList = MyXmlDocument.SelectNodes("amz:ListQueuesResponse/amz:ListQueuesResult/amz:QueueUrl", MyXmlNamespaceManager);

                if (MyXmlNodeList.Count == 0)
                {
                    ResponseMessage = "No queues exist.";
                }
                else
                {
                    foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                    {
                        ResponseMessage += "QueueUrl = " + ItemXmlNode.InnerText;
                        ResponseMessage += Environment.NewLine;
                    }
                }

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Success";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }
            else
            {
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }

        private void ButtonSNSListTopics_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //Amazon Simple Notification Service (SNS), ListTopics: http://docs.amazonwebservices.com/sns/latest/api/API_ListTopics.html

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            String  RequestURL;
            RequestURL = "https://sns.us-east-1.amazonaws.com/?Action=ListTopics&Version=2010-03-31";
            RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));

            String RequestMethod;
            RequestMethod = "GET";

            String SignatureValue;
            SignatureValue = MyREST.GetSignatureVersion2Value(RequestURL, RequestMethod, "", TextBoxAWSSecretAccessKey.Text);

            RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);

            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            if (RetBool == true)
            {
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
                System.Xml.XmlNode MyXmlNode;
                System.Xml.XmlNodeList MyXmlNodeList;

                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(MyREST.ResponseString);

                MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                MyXmlNamespaceManager.AddNamespace("amz", "http://sns.amazonaws.com/doc/2010-03-31/");

                MyXmlNodeList = MyXmlDocument.SelectNodes("amz:ListTopicsResponse/amz:ListTopicsResult/amz:Topics/amz:member", MyXmlNamespaceManager);

                if (MyXmlNodeList.Count == 0)
                {
                    ResponseMessage = "No topics exist.";
                }
                else
                {
                    foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                    {
                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:TopicArn", MyXmlNamespaceManager);
                        ResponseMessage += "TopicArn = " + MyXmlNode.InnerText;

                        ResponseMessage += Environment.NewLine;
                    }
                }

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Success";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }
            else
            {
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }

        private void ButtonCloudWatchListMetrics_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //Amazon CloudWatch, ListMetrics: http://docs.amazonwebservices.com/AmazonCloudWatch/latest/DeveloperGuide/API-ListMetrics.html

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            String  RequestURL;
            RequestURL = "https://monitoring.amazonaws.com/?Action=ListMetrics&Version=2009-05-15";
            RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));

            String RequestMethod;
            RequestMethod = "GET";

            String SignatureValue;
            SignatureValue = MyREST.GetSignatureVersion2Value(RequestURL, RequestMethod, "", TextBoxAWSSecretAccessKey.Text);

            RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);

            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            if (RetBool == true)
            {
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
                System.Xml.XmlNode MyXmlNode;
                System.Xml.XmlNodeList MyXmlNodeList;

                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(MyREST.ResponseString);

                MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                MyXmlNamespaceManager.AddNamespace("amz", "http://monitoring.amazonaws.com/doc/2009-05-15/");

                MyXmlNodeList = MyXmlDocument.SelectNodes("amz:ListMetricsResponse/amz:ListMetricsResult/amz:Metrics/amz:member", MyXmlNamespaceManager);

                if (MyXmlNodeList.Count == 0)
                {
                    ResponseMessage = "No metrics exist.";
                }
                else
                {
                    foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                    {
                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:MeasureName", MyXmlNamespaceManager);
                        ResponseMessage += "MeasureName = " + MyXmlNode.InnerText;

                        ResponseMessage += Environment.NewLine;
                    }
                }

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Success";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }
            else
            {
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }

        private void ButtonVPCDescribeVpcs_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //Amazon Virtual Private Cloud (VPC), DescribeVpcs: http://docs.amazonwebservices.com/AmazonVPC/latest/APIReference/ApiReference-query-DescribeVpcs.html

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            String  RequestURL;
            RequestURL = "https://ec2.amazonaws.com/?Action=DescribeVpcs&Version=2010-08-31";
            RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));

            String RequestMethod;
            RequestMethod = "GET";

            String SignatureValue;
            SignatureValue = MyREST.GetSignatureVersion2Value(RequestURL, RequestMethod, "", TextBoxAWSSecretAccessKey.Text);

            RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);

            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            if (RetBool == true)
            {
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
                System.Xml.XmlNode MyXmlNode;
                System.Xml.XmlNodeList MyXmlNodeList;

                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(MyREST.ResponseString);

                MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                MyXmlNamespaceManager.AddNamespace("amz", "http://ec2.amazonaws.com/doc/2010-08-31/");

                MyXmlNodeList = MyXmlDocument.SelectNodes("amz:DescribeVpcsResponse/amz:vpcSet/amz:item", MyXmlNamespaceManager);

                if (MyXmlNodeList.Count == 0)
                {
                    ResponseMessage = "No VPCs exist.";
                }
                else
                {
                    foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                    {
                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:vpcId", MyXmlNamespaceManager);
                        ResponseMessage += "vpcId = " + MyXmlNode.InnerText;

                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:state", MyXmlNamespaceManager);
                        ResponseMessage += "   state = " + MyXmlNode.InnerText;

                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:cidrBlock", MyXmlNamespaceManager);
                        ResponseMessage += "   cidrBlock = " + MyXmlNode.InnerText;

                        ResponseMessage += Environment.NewLine;
                    }
                }

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Success";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }
            else
            {
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }

        private void ButtonElasticLoadBalancingDescribeLoadBalancers_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //Elastic Load Balancing, DescribeLoadBalancers: http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/DeveloperGuide/API_DescribeLoadBalancers.html

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            String  RequestURL;
            RequestURL = "https://elasticloadbalancing.amazonaws.com/?Action=DescribeLoadBalancers&Version=2010-07-01";
            RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&SignatureVersion=2&SignatureMethod=HmacSHA1&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));

            String RequestMethod;
            RequestMethod = "GET";

            String SignatureValue;
            SignatureValue = MyREST.GetSignatureVersion2Value(RequestURL, RequestMethod, "", TextBoxAWSSecretAccessKey.Text);

            RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);

            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            if (RetBool == true)
            {
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
                System.Xml.XmlNode MyXmlNode;
                System.Xml.XmlNodeList MyXmlNodeList;

                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(MyREST.ResponseString);

                MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                MyXmlNamespaceManager.AddNamespace("amz", "http://elasticloadbalancing.amazonaws.com/doc/2010-07-01/");

                MyXmlNodeList = MyXmlDocument.SelectNodes("amz:DescribeLoadBalancersResponse/amz:DescribeLoadBalancersResult/amz:LoadBalancerDescriptions/amz:member", MyXmlNamespaceManager);

                if (MyXmlNodeList.Count == 0)
                {
                    ResponseMessage = "No load balancers exist.";
                }
                else
                {
                    foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                    {
                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:LoadBalancerName", MyXmlNamespaceManager);
                        ResponseMessage += "LoadBalancerName = " + MyXmlNode.InnerText;

                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:CreatedTime", MyXmlNamespaceManager);
                        ResponseMessage += "   CreatedTime = " + MyXmlNode.InnerText;

                        ResponseMessage += Environment.NewLine;
                    }
                }

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Success";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }
            else
            {
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }

        private void ButtonFPSGetAccountActivity_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //Amazon Flexible Payments Service (FPS and ASP), GetAccountActivity: http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAccountManagementGuide/GetAccountActivity.html

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            //get all transactions in the past day
            DateTime StartDate;
            StartDate = DateTime.Now.AddDays(-1);

            String  RequestURL;
            RequestURL = "https://fps.amazonaws.com/?Action=GetAccountActivity&Version=2008-09-17";
            RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));
            RequestURL += "&StartDate=" + Uri.EscapeDataString(StartDate.ToUniversalTime().ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));

            String RequestMethod;
            RequestMethod = "GET";

            String SignatureValue;
            SignatureValue = MyREST.GetSignatureVersion2Value(RequestURL, RequestMethod, "", TextBoxAWSSecretAccessKey.Text);

            RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);

            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            if (RetBool == true)
            {
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
                System.Xml.XmlNode MyXmlNode;
                System.Xml.XmlNodeList MyXmlNodeList;

                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(MyREST.ResponseString);

                MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                MyXmlNamespaceManager.AddNamespace("amz", "http://fps.amazonaws.com/doc/2008-09-17/");

                MyXmlNodeList = MyXmlDocument.SelectNodes("amz:GetAccountActivityResponse/amz:GetAccountActivityResult/amz:Transaction", MyXmlNamespaceManager);

                if (MyXmlNodeList.Count == 0)
                {
                    ResponseMessage = "No transactions exist.";
                }
                else
                {
                    foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                    {
                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:TransactionId", MyXmlNamespaceManager);
                        ResponseMessage += "TransactionId = " + MyXmlNode.InnerText;

                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:DateReceived", MyXmlNamespaceManager);
                        ResponseMessage += "   DateReceived = " + MyXmlNode.InnerText;

                        ResponseMessage += Environment.NewLine;
                    }
                }

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Success";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }
            else
            {
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }

        private void ButtonDevPayGetActiveSubscriptionsByPid_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //Amazon DevPay, GetActiveSubscriptionsByPid: http://docs.amazonwebservices.com/AmazonDevPay/latest/DevPayDeveloperGuide/GetActiveSubscriptionsByPid.html

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            String  RequestURL;
            RequestURL = "https://ls.amazonaws.com/?Action=GetActiveSubscriptionsByPid&Version=2008-04-28";
            RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&SignatureVersion=1&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));
            RequestURL += "&PersistentIdentifier=PMNGLKRRYHLOXDQKEMKLRTBAULA";

            String RequestMethod;
            RequestMethod = "GET";

            String SignatureValue;
            SignatureValue = MyREST.GetDevPaySignatureValue(RequestURL, TextBoxAWSSecretAccessKey.Text);

            RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);

            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            if (RetBool == true)
            {
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
                System.Xml.XmlNodeList MyXmlNodeList;

                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(MyREST.ResponseString);

                MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                MyXmlNamespaceManager.AddNamespace("amz", "http://ls.amazonaws.com/doc/2008-04-28/");

                MyXmlNodeList = MyXmlDocument.SelectNodes("amz:GetActiveSubscriptionsByPidResponse/amz:GetActiveSubscriptionsByPidResult/amz:ProductCode", MyXmlNamespaceManager);

                if (MyXmlNodeList.Count == 0)
                {
                    ResponseMessage = "No products exist.";
                }
                else
                {
                    foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                    {
                        ResponseMessage += "ProductCode = " + ItemXmlNode.InnerText;

                        ResponseMessage += Environment.NewLine;
                    }
                }

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Success";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }
            else
            {
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }

        private void ButtonS3GETService_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //Amazon Simple Storage Service (S3), GET Service: http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTServiceGET.html

            //create an instance of the REST class
            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            String  RequestURL;
            //Build the URL to call. Do not specify a bucket name or key name when listing all buckets
            RequestURL = MyREST.BuildS3RequestURL(true, "s3.amazonaws.com", "", "", "");

            String RequestMethod;
            RequestMethod = "GET";

            Dictionary<String, String> ExtraRequestHeaders = new Dictionary<String, String>();
            //add a date header
            ExtraRequestHeaders.Add("x-amz-date", DateTime.UtcNow.ToString("r"));

            String AuthorizationValue;
            //generate the authorization header value
            AuthorizationValue = MyREST.GetS3AuthorizationValue(RequestURL, RequestMethod, ExtraRequestHeaders, TextBoxAWSAccessKeyId.Text, TextBoxAWSSecretAccessKey.Text);
            //add the authorization header
            ExtraRequestHeaders.Add("Authorization", AuthorizationValue);

            //call MakeRequest to submit the REST request
            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, ExtraRequestHeaders, "");

            //print the log data to the Output window
            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            //check if the result of the operation was successful
            if (RetBool == true)
            {
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
                System.Xml.XmlNode MyXmlNode;
                System.Xml.XmlNodeList MyXmlNodeList;

                //load the response XML from Amazon into an XmlDocument
                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(MyREST.ResponseString);

                //specify the namespace for XML path expressions
                MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                MyXmlNamespaceManager.AddNamespace("amz", "http://s3.amazonaws.com/doc/2006-03-01/");

                //extract all values from the response XML
                MyXmlNode = MyXmlDocument.SelectSingleNode("amz:ListAllMyBucketsResult/amz:Owner/amz:ID", MyXmlNamespaceManager);
                ResponseMessage = ResponseMessage + "Owner ID = " + MyXmlNode.InnerText + Environment.NewLine;

                MyXmlNode = MyXmlDocument.SelectSingleNode("amz:ListAllMyBucketsResult/amz:Owner/amz:DisplayName", MyXmlNamespaceManager);
                ResponseMessage = ResponseMessage + "Owner DisplayName = " + MyXmlNode.InnerText + Environment.NewLine;
                ResponseMessage = ResponseMessage + Environment.NewLine;

                MyXmlNodeList = MyXmlDocument.SelectNodes("amz:ListAllMyBucketsResult/amz:Buckets/amz:Bucket", MyXmlNamespaceManager);

                foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                {
                    MyXmlNode = ItemXmlNode.SelectSingleNode("amz:Name", MyXmlNamespaceManager);
                    ResponseMessage = ResponseMessage + "Bucket Name = " + MyXmlNode.InnerText;

                    MyXmlNode = ItemXmlNode.SelectSingleNode("amz:CreationDate", MyXmlNamespaceManager);
                    ResponseMessage = ResponseMessage + "     CreationDate = " + Convert.ToDateTime(MyXmlNode.InnerText) + Environment.NewLine;
                }

                //display values from the XML in the DialogOutput form
                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Success";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }
            else
            {
                //build an error message
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                //display the error message
                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }

        private void ButtonAWSImportExportListJobs_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //AWS Import/Export, ListJobs: http://docs.amazonwebservices.com/AWSImportExport/latest/API/WebListJobs.html

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            String  RequestURL;
            RequestURL = "https://importexport.amazonaws.com";

            String PostData;
            PostData = "Operation=ListJobs&Version=2010-06-01";
            PostData += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));

            String RequestMethod;
            RequestMethod = "POST";

            String SignatureValue;
            SignatureValue = MyREST.GetSignatureVersion2Value(RequestURL, RequestMethod, PostData, TextBoxAWSSecretAccessKey.Text);

            PostData += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

            Dictionary<String, String> ExtraRequestHeaders = new Dictionary<String, String>();
            ExtraRequestHeaders.Add("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");

            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, ExtraRequestHeaders, PostData);

            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            if (RetBool == true)
            {
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
                System.Xml.XmlNode MyXmlNode;
                System.Xml.XmlNodeList MyXmlNodeList;

                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(MyREST.ResponseString);

                MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                MyXmlNamespaceManager.AddNamespace("amz", "http://importexport.amazonaws.com/doc/2010-06-01/");

                MyXmlNodeList = MyXmlDocument.SelectNodes("amz:ListJobsResponse/amz:ListJobsResult/amz:Jobs/amz:member", MyXmlNamespaceManager);

                if (MyXmlNodeList.Count == 0)
                {
                    ResponseMessage = "No jobs exist.";
                }
                else
                {
                    foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                    {
                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:JobId", MyXmlNamespaceManager);
                        ResponseMessage += "JobId = " + MyXmlNode.InnerText;

                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:CreationDate", MyXmlNamespaceManager);
                        ResponseMessage += "   CreationDate = " + MyXmlNode.InnerText;

                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:IsCanceled", MyXmlNamespaceManager);
                        ResponseMessage += "   IsCanceled = " + MyXmlNode.InnerText;

                        ResponseMessage += Environment.NewLine;
                    }
                }

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Success";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }
            else
            {
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }

        private void ButtonAlexaWebInformationServiceUrlInfo_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //Alexa Web Information Service, UrlInfo: http://docs.amazonwebservices.com/AlexaWebInfoService/2005-07-11/ApiReference_UrlInfoAction.html

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            String  RequestURL;
            RequestURL = "http://awis.amazonaws.com/?Action=UrlInfo&Version=2005-07-11";
            RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));
            RequestURL += "&ResponseGroup=Rank&Url=yahoo.com";

            String RequestMethod;
            RequestMethod = "GET";

            String SignatureValue;
            SignatureValue = MyREST.GetAlexaSignatureValue(RequestURL, TextBoxAWSSecretAccessKey.Text);

            RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);

            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            if (RetBool == true)
            {
                System.Xml.XmlDocument EnvelopeXmlDocument;
                System.Xml.XmlNamespaceManager EnvelopeXmlNamespaceManager;
                System.Xml.XmlNode EnvelopeXmlNode;
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
                System.Xml.XmlNode MyXmlNode;

                EnvelopeXmlDocument = new System.Xml.XmlDocument();
                EnvelopeXmlDocument.LoadXml(MyREST.ResponseString);

                EnvelopeXmlNamespaceManager = new System.Xml.XmlNamespaceManager(EnvelopeXmlDocument.NameTable);
                EnvelopeXmlNamespaceManager.AddNamespace("env", "http://alexa.amazonaws.com/doc/2005-10-05/");

                EnvelopeXmlNode = EnvelopeXmlDocument.SelectSingleNode("env:UrlInfoResponse", EnvelopeXmlNamespaceManager);

                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(EnvelopeXmlNode.InnerXml);

                MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                MyXmlNamespaceManager.AddNamespace("amz", "http://awis.amazonaws.com/doc/2005-07-11");

                MyXmlNode = MyXmlDocument.SelectSingleNode("amz:Response/amz:UrlInfoResult/amz:Alexa/amz:ContentData/amz:SiteData/amz:Title", MyXmlNamespaceManager);

                if (MyXmlNode == null)
                {
                    ResponseMessage = "Url title does not exist.";
                }
                else
                {
                    ResponseMessage = "Title = " + MyXmlNode.InnerText;
                }

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Success";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }
            else
            {
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }

        private void ButtonAlexaTopSitesTopSites_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //Alexa Top Sites , TopSites: http://docs.amazonwebservices.com/AlexaTopSites/2005-11-21_2/ApiReference/TopSitesAction.html#ResponseGroups

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            String  RequestURL;
            RequestURL = "http://ats.amazonaws.com/?Action=TopSites";
            RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));
            RequestURL += "&ResponseGroup=Country";

            String RequestMethod;
            RequestMethod = "GET";

            String SignatureValue;
            SignatureValue = MyREST.GetAlexaSignatureValue(RequestURL, TextBoxAWSSecretAccessKey.Text);

            RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);

            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            if (RetBool == true)
            {
                System.Xml.XmlDocument EnvelopeXmlDocument;
                System.Xml.XmlNamespaceManager EnvelopeXmlNamespaceManager;
                System.Xml.XmlNode EnvelopeXmlNode;
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
                System.Xml.XmlNode MyXmlNode;
                System.Xml.XmlNodeList MyXmlNodeList;

                EnvelopeXmlDocument = new System.Xml.XmlDocument();
                EnvelopeXmlDocument.LoadXml(MyREST.ResponseString);

                EnvelopeXmlNamespaceManager = new System.Xml.XmlNamespaceManager(EnvelopeXmlDocument.NameTable);
                EnvelopeXmlNamespaceManager.AddNamespace("env", "http://ats.amazonaws.com/doc/2005-10-05/");

                EnvelopeXmlNode = EnvelopeXmlDocument.SelectSingleNode("env:TopSitesResponse", EnvelopeXmlNamespaceManager);

                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(EnvelopeXmlNode.InnerXml);

                MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                MyXmlNamespaceManager.AddNamespace("amz", "http://ats.amazonaws.com/doc/2005-11-21");

                MyXmlNodeList = MyXmlDocument.SelectNodes("amz:Response/amz:TopSitesResult/amz:Alexa/amz:TopSites/amz:Country", MyXmlNamespaceManager);

                if (MyXmlNodeList.Count == 0)
                {
                    ResponseMessage = "No countries exist.";
                }
                else
                {
                    foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                    {
                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:CountryName", MyXmlNamespaceManager);
                        ResponseMessage += "CountryName = " + MyXmlNode.InnerText;

                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:CountryCode", MyXmlNamespaceManager);
                        ResponseMessage += "   CountryCode = " + MyXmlNode.InnerText;

                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:TotalSites", MyXmlNamespaceManager);
                        ResponseMessage += "   TotalSites = " + MyXmlNode.InnerText;

                        ResponseMessage += Environment.NewLine;
                    }
                }

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Success";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }
            else
            {
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }

        private void ButtonMechanicalTurkGetAccountBalance_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //Amazon Mechanical Turk, GetAccountBalance: http://docs.amazonwebservices.com/AWSMechTurk/latest/AWSMturkAPI/ApiReference_GetAccountBalanceOperation.html

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            String  RequestURL;
            RequestURL = "https://mechanicalturk.amazonaws.com/?Service=AWSMechanicalTurkRequester&Operation=GetAccountBalance&Version=2008-08-02";
            RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));

            String RequestMethod;
            RequestMethod = "GET";

            String SignatureValue;
            SignatureValue = MyREST.GetMechanicalTurkSignatureValue(RequestURL, TextBoxAWSSecretAccessKey.Text);

            RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);

            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            if (RetBool == true)
            {
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNode MyXmlNode;

                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(MyREST.ResponseString);

                MyXmlNode = MyXmlDocument.SelectSingleNode("GetAccountBalanceResponse/GetAccountBalanceResult/AvailableBalance/Amount");

                if (MyXmlNode == null)
                {
                    ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                    DialogOutput MyDialogOutput = new DialogOutput();
                    MyDialogOutput.Text = "Error";
                    MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                    MyDialogOutput.ShowDialog(this);
                }
                else
                {
                    ResponseMessage = "Amount = " + MyXmlNode.InnerText;

                    DialogOutput MyDialogOutput = new DialogOutput();
                    MyDialogOutput.Text = "Success";
                    MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                    MyDialogOutput.ShowDialog(this);
                }
            }
            else
            {
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }

        private void ButtonProductAdvertisingAPIItemSearch_Click(object sender, EventArgs e)
        {
            (sender as Button).Enabled = false;

            //Product Advertising API, ItemSearch: http://docs.amazonwebservices.com/AWSECommerceService/2010-10-01/DG/ItemSearch.html

            SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

            String RequestURL;
            RequestURL = "https://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&Operation=ItemLookup&Version=2010-10-01";
            RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));
            RequestURL += "&ItemId=9781904233657";
            RequestURL += "&IdType=ISBN";
            RequestURL += "&SearchIndex=Books";

            String RequestMethod;
            RequestMethod = "GET";

            String SignatureValue;
            SignatureValue = MyREST.GetSignatureVersion2Value(RequestURL, RequestMethod, "", TextBoxAWSSecretAccessKey.Text);

            RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

            Boolean RetBool;
            RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);

            System.Diagnostics.Debug.Print("");
            System.Diagnostics.Debug.Print(MyREST.LogData);
            System.Diagnostics.Debug.Print("");

            String ResponseMessage = "";

            if (RetBool == true)
            {
                System.Xml.XmlDocument MyXmlDocument;
                System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
                System.Xml.XmlNode MyXmlNode;
                System.Xml.XmlNodeList MyXmlNodeList;

                MyXmlDocument = new System.Xml.XmlDocument();
                MyXmlDocument.LoadXml(MyREST.ResponseString);

                MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
                MyXmlNamespaceManager.AddNamespace("amz", "http://webservices.amazon.com/AWSECommerceService/2010-10-01");

                MyXmlNodeList = MyXmlDocument.SelectNodes("amz:ItemLookupResponse/amz:Items/amz:Item", MyXmlNamespaceManager);

                if (MyXmlNodeList.Count == 0)
                {
                    ResponseMessage = "No items found.";
                }
                else
                {
                    foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
                    {
                        MyXmlNode = ItemXmlNode.SelectSingleNode("amz:ItemAttributes/amz:Title", MyXmlNamespaceManager);
                        ResponseMessage += "Title = " + MyXmlNode.InnerText;

                        ResponseMessage += Environment.NewLine;
                    }
                }

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Success";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }
            else
            {
                ResponseMessage = FormatLogData(MyREST.RequestURL, MyREST.RequestMethod, MyREST.RequestHeaders, MyREST.ResponseStatusCode, MyREST.ResponseStatusDescription, MyREST.ResponseHeaders, MyREST.ResponseStringFormatted, MyREST.ErrorNumber, MyREST.ErrorDescription);

                DialogOutput MyDialogOutput = new DialogOutput();
                MyDialogOutput.Text = "Error";
                MyDialogOutput.TextBoxOutput.Text = ResponseMessage;
                MyDialogOutput.ShowDialog(this);
            }

            (sender as Button).Enabled = true;
        }
    
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions