protected void Page_Load(object sender, EventArgs e) { String toCurrency = Request.Params["toCurrency"]; double amount = 0; double rate = 1; SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST(); String RequestURL = "http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD"; RequestURL += "&ToCurrency=" + toCurrency; String RequestMethod = "GET"; Boolean RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null); try { amount = Convert.ToDouble(Request.Params["amount"]); } catch (Exception error) { result.InnerText = error.ToString(); } if (RetBool == true) { System.Xml.XmlDocument MyXmlDocument; MyXmlDocument = new System.Xml.XmlDocument(); MyXmlDocument.LoadXml(MyREST.ResponseString); try { rate = Convert.ToDouble(MyXmlDocument.InnerText.Replace(".", ",")); if (rate == 0) { rate = 1; } } catch (Exception error) { result.InnerText += error.ToString(); } } result.InnerHtml = " " + String.Format("{0:0.00}", rate * amount); }
public String Calculate(String toCurrency, String amount) { double rate = 1; SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST(); String RequestURL = "http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD"; RequestURL += "&ToCurrency=" + toCurrency; String RequestMethod = "GET"; Boolean RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null); if (RetBool == true) { System.Xml.XmlDocument MyXmlDocument; MyXmlDocument = new System.Xml.XmlDocument(); MyXmlDocument.LoadXml(MyREST.ResponseString); try { rate = Convert.ToDouble(MyXmlDocument.InnerText.Replace(".", ",")); if (rate == 0) { rate = 1; } } catch (Exception error) { return error.ToString(); } } return " " + String.Format("{0:0.00}", rate * Convert.ToDouble(amount)); }
private System.Xml.XmlNodeList getItems(String title, String searchIndex, String Itempage) { SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST(); String RequestURL; RequestURL = "https://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&Operation=ItemSearch&Version=2011-08-01"; RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString("AKIAJIS6X7GHSGTU7AQQ"); RequestURL += "&AssociateTag=ENTER_YOUR_ASSOCIATE_TAG_HERE"; RequestURL += "&SignatureVersion=2&SignatureMethod=HmacSHA256"; RequestURL += "&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z")); RequestURL += "&Title=" + System.Uri.EscapeDataString(title); RequestURL += "&SearchIndex=" + searchIndex; RequestURL += "&ResponseGroup=" + System.Uri.EscapeDataString("ItemAttributes,Images,EditorialReview"); RequestURL += "&Sort=salesrank"; RequestURL += "&ItemPage=" + Itempage; String RequestMethod; RequestMethod = "GET"; String SignatureValue; SignatureValue = MyREST.GetSignatureVersion2Value(RequestURL, RequestMethod, "", "ydILyRh/cOIs3c2JDRpORf0o/C1gTf8cm5iGcIEt"); RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue); Boolean RetBool; RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null); 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://webservices.amazon.com/AWSECommerceService/2011-08-01"); MyXmlNodeList = MyXmlDocument.SelectNodes("amz:ItemSearchResponse/amz:Items/amz:Item", MyXmlNamespaceManager); return MyXmlNodeList; } else { return null; } }
public static int Main(string[] args) { try { NameValueCollection settings = new NameValueCollection(); List<string> indexedArgs = new List<string>(); string command = null; foreach (var arg in args) { if (arg.StartsWith("--")) { if (arg.Contains("=")) { // Key/Value pair int equalIndex = arg.IndexOf('='); string key = arg.Substring(2, equalIndex - 2); string value = arg.Substring(equalIndex + 1); settings.Add(key.ToLower(), value); continue; } } else { if (command == null) command = arg.ToUpper(); else indexedArgs.Add(arg); } } if (string.IsNullOrEmpty(command)) throw new ArgumentException("Missing command"); if (string.IsNullOrEmpty(settings["accesskey"])) throw new ArgumentException("Missing AccessKey"); if (string.IsNullOrEmpty(settings["accesssecret"])) throw new ArgumentException("Missing AccessSecret"); if (string.IsNullOrEmpty(settings["server"])) settings.Add("server", "s3.amazonaws.com"); string endpoint = settings["server"]; if (endpoint.EndsWith("/")) endpoint = endpoint.Substring(0, endpoint.Length - 1); if (!string.IsNullOrEmpty(settings["bucket"])) endpoint += "/" + settings["bucket"]; if (command == "PUT") { if (indexedArgs.Count < 1) throw new ArgumentException("Missing filename"); var upload = new SprightlySoftAWS.S3.Upload(); foreach (var localFile in indexedArgs) { string fileName = System.IO.Path.GetFileName(localFile); var requestURL = upload.BuildS3RequestURL(true, endpoint, string.Empty, fileName, string.Empty); var headers = new Dictionary<string, string>(); headers.Add("x-amz-date", DateTime.UtcNow.ToString("r")); var authValue = upload.GetS3AuthorizationValue(requestURL, "PUT", headers, settings["accesskey"], settings["accesssecret"]); headers.Add("Authorization", authValue); if (!upload.UploadFile(requestURL, "PUT", headers, localFile)) throw new Exception(string.Format("Failed to upload file: {0} Error: {1}", localFile, upload.ErrorDescription)); } return 0; } else if (command == "DELETE") { if (indexedArgs.Count < 1) throw new ArgumentException("Missing filename"); var delete = new SprightlySoftAWS.REST(); foreach (var remoteFilename in indexedArgs) { var requestURL = delete.BuildS3RequestURL(true, endpoint, string.Empty, remoteFilename, string.Empty); var headers = new Dictionary<string, string>(); headers.Add("x-amz-date", DateTime.UtcNow.ToString("r")); var authValue = delete.GetS3AuthorizationValue(requestURL, "DELETE", headers, settings["accesskey"], settings["accesssecret"]); headers.Add("Authorization", authValue); if (!delete.MakeRequest(requestURL, "PUT", headers, remoteFilename)) throw new Exception(string.Format("Failed to delete file: {0} Error: {1}", remoteFilename, delete.ErrorDescription)); } return 0; } else if (command == "GET") { if (indexedArgs.Count < 1) throw new ArgumentException("Missing filename"); var download = new SprightlySoftAWS.S3.Download(); foreach (var remoteFilename in indexedArgs) { var requestURL = download.BuildS3RequestURL(true, endpoint, string.Empty, remoteFilename, string.Empty); var headers = new Dictionary<string, string>(); headers.Add("x-amz-date", DateTime.UtcNow.ToString("r")); var authValue = download.GetS3AuthorizationValue(requestURL, "GET", headers, settings["accesskey"], settings["accesssecret"]); headers.Add("Authorization", authValue); string localFilename = System.IO.Path.GetFullPath(remoteFilename); System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(localFilename)); if (!download.DownloadFile(requestURL, "GET", headers, localFilename, false)) throw new Exception(string.Format("Failed to download file: {0} Error: {1}", remoteFilename, download.ErrorDescription)); } return 0; } else Console.WriteLine("Unknown command: " + command); return 1; } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return 255; } }