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 ("accountid".Equals(key)) { existingInfo.AccountId = value; return; } if ("vaultname".Equals(key)) { existingInfo.VaultName = value; return; } if ("location".Equals(key)) { existingInfo.Location = value; return; } throw new ArgumentException(string.Format("The connection info '{0}' was not expected and is not understood.", key)); }
// Provision RDS Instance // 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 { AmazonGlacierClient client; DeveloperOptions devOptions; var parseOptionsResult = ParseDevOptions(developerOptions, manifest, 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.CreateVault(CreateVaultRequest(devOptions)); // fix 5/22/14 resolves amazon aws deprecation // wait for response to come back with a location while (true) { if (response.Location != null) { var conInfo = new ConnectionInfo() { AccountId = devOptions.AccountId, VaultName = devOptions.VaultName, Location = response.Location }; provisionResult.IsSuccess = true; provisionResult.ConnectionData = conInfo.ToString(); break; } Thread.Sleep(10); } } catch (Exception e) { provisionResult.EndUserMessage = e.Message; } return provisionResult; }