public static ConnectionInfo Parse(string connectionInfo) { ConnectionInfo info = new ConnectionInfo(); if (!string.IsNullOrWhiteSpace(connectionInfo)) { var propertyPairs = connectionInfo.Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries); foreach (var propertyPair in propertyPairs) { var optionPairParts = propertyPair.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); if (optionPairParts.Length == 2) { MapToProperty(info, optionPairParts[0].Trim().ToLowerInvariant(), optionPairParts[1].Trim()); } else { throw new ArgumentException( string.Format( "Unable to parse connection info which should be in the form of 'property=value&nextproperty=nextValue'. The property '{0}' was not properly constructed", propertyPair)); } } } return info; }
public static void MapToProperty(ConnectionInfo existingInfo, string key, string value) { if ("TopicArn".Equals(key)) { existingInfo.TopicArn = value; return; } if ("QueueName".Equals(key)) { existingInfo.QueueName = value; return; } throw new ArgumentException(string.Format("The connection info '{0}' was not expected and is not understood.", key)); }
// Provision SNS Topic // Input: AddonDeprovisionRequest request // Output: ProvisionAddOnResult public override ProvisionAddOnResult Provision(AddonProvisionRequest request) { // i think this is a bug. but I'm going to throw an empty string to it to clear the warning. var provisionResult = new ProvisionAddOnResult(""); AddonManifest manifest = request.Manifest; string developerOptions = request.DeveloperOptions; try { AmazonSimpleNotificationServiceClient client; DeveloperOptions devOptions; var parseOptionsResult = ParseDevOptions(developerOptions, out devOptions); if (!parseOptionsResult.IsSuccess) { provisionResult.EndUserMessage = parseOptionsResult.EndUserMessage; return provisionResult; } var establishClientResult = EstablishClient(manifest, DeveloperOptions.Parse(developerOptions), out client); if (!establishClientResult.IsSuccess) { provisionResult.EndUserMessage = establishClientResult.EndUserMessage; return provisionResult; } var response = client.CreateTopic(CreateTopicRequest(devOptions)); do { var verificationResponse = client.GetTopicAttributes(new GetTopicAttributesRequest() { TopicArn = response.TopicArn }); // ok so the attributes works as follows: // attributes[0] - topicarn // attributes[1] - owner // attributes[2] - policy // attributes[3] - displayname // attributes[4] - subscriptionspending // attributes[5] - subscriptionsconfirmed // attributes[6] - subscriptionsdeleted // attributes[7] - deliverypolicy // attributes[8] - effectivedeliverypolicy if (verificationResponse.Attributes["TopicArn"].Equals(response.TopicArn)) { var conInfo = new ConnectionInfo() { TopicArn = verificationResponse.Attributes["TopicArn"], QueueName = verificationResponse.Attributes["DisplayName"] }; provisionResult.IsSuccess = true; provisionResult.ConnectionData = conInfo.ToString(); break; } Thread.Sleep(TimeSpan.FromSeconds(10d)); } while (true); } catch (Exception e) { provisionResult.EndUserMessage = e.Message; } return provisionResult; }