public override void ExecuteCmdlet() { var newEnvironment = new AzureEnvironment {Name = Name}; newEnvironment.Endpoints[AzureEnvironment.Endpoint.PublishSettingsFileUrl] = PublishSettingsFileUrl; newEnvironment.Endpoints[AzureEnvironment.Endpoint.ServiceManagement] = ServiceEndpoint; newEnvironment.Endpoints[AzureEnvironment.Endpoint.ResourceManager] = ResourceManagerEndpoint; newEnvironment.Endpoints[AzureEnvironment.Endpoint.ManagementPortalUrl] = ManagementPortalUrl; newEnvironment.Endpoints[AzureEnvironment.Endpoint.StorageEndpointSuffix] = StorageEndpoint; newEnvironment.Endpoints[AzureEnvironment.Endpoint.ActiveDirectory] = ActiveDirectoryEndpoint; newEnvironment.Endpoints[AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId] = ActiveDirectoryServiceEndpointResourceId; newEnvironment.Endpoints[AzureEnvironment.Endpoint.Gallery] = GalleryEndpoint; newEnvironment.Endpoints[AzureEnvironment.Endpoint.Graph] = GraphEndpoint; newEnvironment.Endpoints[AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix] = AzureKeyVaultDnsSuffix; newEnvironment.Endpoints[AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId] = AzureKeyVaultServiceEndpointResourceId; ProfileClient.AddOrSetEnvironment(newEnvironment); List<object> args = new List<object> { "Name", newEnvironment.Name }; foreach (AzureEnvironment.Endpoint property in Enum.GetValues(typeof(AzureEnvironment.Endpoint))) { args.AddRange(new object[] { property, newEnvironment.GetEndpoint(property) }); } WriteObject(base.ConstructPSObject(null, args.ToArray())); }
private AzureEnvironment MergeEnvironmentProperties(AzureEnvironment environment1, AzureEnvironment environment2) { if (environment1 == null || environment2 == null) { throw new ArgumentNullException("environment1"); } if (!string.Equals(environment1.Name, environment2.Name, StringComparison.InvariantCultureIgnoreCase)) { throw new ArgumentException("Environment names do not match."); } AzureEnvironment mergedEnvironment = new AzureEnvironment { Name = environment1.Name }; // Merge all properties foreach (AzureEnvironment.Endpoint property in Enum.GetValues(typeof(AzureEnvironment.Endpoint))) { string propertyValue = environment1.GetEndpoint(property) ?? environment2.GetEndpoint(property); if (propertyValue != null) { mergedEnvironment.Endpoints[property] = propertyValue; } } return mergedEnvironment; }