public static CloudTarget FromRegistryText(KeyValuePair <string, string[]> target) { string[] registryText = target.Value; if (registryText == null || registryText.Length < 1) { throw new ArgumentException("Invalid registry setting.", "target"); } string apiTypeTag = registryText[(int)CloudTargetPart.TypeTag]; if (CloudTarget.V2ApiTags.Contains(apiTypeTag)) { Uri targetUrl = new Uri(registryText[(int)CloudTargetPart.TargetUrl]); string description = registryText[(int)CloudTargetPart.Description]; string email = registryText[(int)CloudTargetPart.Email]; bool ignoreSSLErrors = Convert.ToBoolean((int)CloudTargetPart.IgnoreSSLErrors); string version = registryText[(int)CloudTargetPart.Version]; CloudTarget registryTarget = CloudTarget.CreateV2Target(targetUrl, description, email, ignoreSSLErrors, version); registryTarget.TargetId = Guid.Parse(target.Key); return(registryTarget); } else { throw new InvalidOperationException("Unknown registry target."); } }
public static void SaveTarget(CloudTarget target) { if (target == null) { return; } if (GetValuesFromCloudTargets().ContainsKey(target.TargetId.ToString())) { throw new InvalidOperationException("Specified target ID already exists in the collection!"); } CloudTargetManager.AddValueToCloudTargets( target.TargetId.ToString(), target.ToRegistryText()); }
public static CloudTarget[] GetTargets() { Dictionary <string, string[]> targets = GetValuesFromCloudTargets(); List <CloudTarget> result = new List <CloudTarget>(targets.Count); foreach (KeyValuePair <string, string[]> target in targets) { try { Guid targetId = new Guid(target.Key); } catch (Exception ex) { Logger.Error(string.Format(CultureInfo.InvariantCulture, "There is an invalid key in the registry: {0}", target.Key), ex); continue; } try { var cloudTarget = CloudTarget.FromRegistryText(target); result.Add(cloudTarget); } catch (Exception ex) { Logger.Warning( string.Format( CultureInfo.InvariantCulture, "Error while loading target: {0}. It will be ignored. Details: {1}", target.Key, ex.ToString())); } } return(result.ToArray()); }