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 ("dbinstanceidentifier".Equals(key)) { existingInfo.DbInstanceIdentifier = value; return; } if ("endpointaddress".Equals(key)) { existingInfo.EndpointAddress = value; return; } if ("endpointport".Equals(key)) { int result; if (!int.TryParse(value, out result)) { throw new ArgumentException(string.Format("The connection info property '{0}' can only have an integer value but '{1}' was used instead.", key, value)); } existingInfo.EndpointPort = result; 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 { AmazonRDSClient 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.CreateDBInstance(CreateDbInstanceRequest(devOptions)); // fix 5/22/14 resolves amazon aws deprecation if (response.DBInstance != null) { //var conInfo = new ConnectionInfo() //{ // DbInstanceIdentifier = devOptions.DbInstanceIndentifier //}; //provisionResult.IsSuccess = true; //provisionResult.ConnectionData = conInfo.ToString(); //Thread.Sleep(TimeSpan.FromMinutes(6)); do { var verificationResponse = client.DescribeDBInstances(new DescribeDBInstancesRequest() { DBInstanceIdentifier = devOptions.DbInstanceIdentifier }); // fix on next few lines 5/22/14 resolve amazon aws deprecation. if (verificationResponse.DBInstances.Any() && verificationResponse.DBInstances[0].DBInstanceStatus == "available") { var dbInstance = verificationResponse.DBInstances[0]; var conInfo = new ConnectionInfo() { DbInstanceIdentifier = devOptions.DbInstanceIdentifier, EndpointAddress = dbInstance.Endpoint.Address, EndpointPort = dbInstance.Endpoint.Port }; provisionResult.IsSuccess = true; provisionResult.ConnectionData = conInfo.ToString(); break; } Thread.Sleep(TimeSpan.FromSeconds(10d)); } while (true); } } catch (Exception e) { provisionResult.EndUserMessage = e.Message; } return provisionResult; }