//--- Constructors --- /// <summary> /// Constructor for creating an instance. /// </summary> /// <param name="privateKey">Private AWS key.</param> /// <param name="publicKey">Public AWS key.</param> /// <param name="accountId">AWS account ID.</param> /// <param name="endpoint">Region name or custom SQS endpoint to use.</param> /// <param name="secure">Boolean indicating if HTTPS should be used.</param> /// <param name="proxyHost">The proxy host if any.</param> /// <param name="proxyPort">The proxy port if any.</param> public SqsClientConfig(string privateKey, string publicKey, string accountId, string endpoint, bool secure, string proxyHost = null, int? proxyPort = 0) { if(string.IsNullOrEmpty(accountId)) { throw new ArgumentNullException("accountId"); } if(string.IsNullOrEmpty(endpoint)) { throw new ArgumentNullException("endpoint"); } this.PrivateKey = privateKey; this.PublicKey = publicKey; this.AccountId = accountId; this.ProxyHost = proxyHost; this.ProxyPort = proxyPort; // read end-point settings XUri uri; switch(endpoint) { case "default": case "us-east-1": // US East (N. Virginia) uri = new XUri("http://sqs.us-east-1.amazonaws.com"); break; case "us-west-2": // US West (Oregon) uri = new XUri("http://sqs.us-west-2.amazonaws.com"); break; case "us-west-1": // US West (N. California) uri = new XUri("http://sqs.us-west-1.amazonaws.com"); break; case "eu-west-1": // EU (Ireland) uri = new XUri("http://sqs.eu-west-1.amazonaws.com"); break; case "eu-central-1": // EU (Frankfurt) uri = new XUri("http://sqs.eu-central-1.amazonaws.com"); break; case "ap-southeast-1": // Asia Pacific (Singapore) uri = new XUri("http://sqs.ap-southeast-1.amazonaws.com"); break; case "ap-southeast-2": // Asia Pacific (Sydney) uri = new XUri("http://sqs.ap-southeast-2.amazonaws.com"); break; case "ap-northeast-1": // Asia Pacific (Tokyo) uri = new XUri("http://sqs.ap-northeast-1.amazonaws.com"); break; case "sa-east-1": // South America (Sao Paulo) uri = new XUri("http://sqs.sa-east-1.amazonaws.com"); break; default: uri = XUri.TryParse(endpoint); break; } if(uri == null) { throw new ArgumentException("invalid value for SQS end-point", "endpoint"); } if(secure) { uri = uri.WithScheme("https"); } this.Endpoint = uri; }
private Result<DreamMessage> FetchFeed(XUri uri) { // replace the invalid feed:// scheme with http:// if(uri.Scheme.EqualsInvariantIgnoreCase("feed")) { uri = uri.WithScheme("http"); } lock(_feeds) { // check if we have a cached result XDoc feed; if(_feeds.TryGetValue(uri, out feed)) { Result<DreamMessage> result = new Result<DreamMessage>(); result.Return(DreamMessage.Ok(feed)); return result; } } Plug plug = Plug.New(uri, TimeSpan.FromSeconds(Config["timeout"].AsDouble ?? Plug.DEFAULT_TIMEOUT.TotalSeconds)); return plug.GetAsync(); }