/// <summary> /// Ensures all required properties are set to <see cref="IGraphEnvironment"/> object. /// </summary> /// <param name="newEnvironment">The new <see cref="IGraphEnvironment"/> object.</param> private void ValidateEnvironment(IGraphEnvironment newEnvironment) { if (string.IsNullOrWhiteSpace(newEnvironment.AzureADEndpoint) || string.IsNullOrWhiteSpace(newEnvironment.GraphEndpoint)) { this.ThrowParameterError(ErrorConstants.Message.InvalidUrlParameter, $"{nameof(GraphEndpoint)} or {nameof(AzureADEndpoint)}"); } }
protected override void BeginProcessing() { base.BeginProcessing(); ValidateParameters(); if (MyInvocation.BoundParameters.ContainsKey(nameof(Environment))) { GraphSettings settings = this.GetContextSettings(); if (!settings.TryGetEnvironment(Environment, out environment)) { throw new PSInvalidOperationException(string.Format(ErrorConstants.Message.InvalidEnvironment, Environment)); } } else { environment = GraphEnvironment.BuiltInEnvironments[GraphEnvironmentConstants.EnvironmentName.Global]; } }
/// <summary> /// Merges two <see cref="IGraphEnvironment"/> into one. /// </summary> /// <param name="environment1">The environment to merge into.</param> /// <param name="environment2">The environment to merge.</param> /// <returns>A merged <see cref="IGraphEnvironment"/>.</returns> public static IGraphEnvironment Merge(this IGraphEnvironment environment1, IGraphEnvironment environment2) { if (environment1 == null || environment2 == null) { throw new ArgumentNullException(nameof(environment1)); } if (!string.Equals(environment1.Name, environment2.Name, StringComparison.InvariantCultureIgnoreCase)) { throw new ArgumentException("Environment names do not match."); } GraphEnvironment mergedEnvironment = new GraphEnvironment { Name = environment1.Name, Type = environment1.Type, AzureADEndpoint = environment1.AzureADEndpoint ?? environment2.AzureADEndpoint, GraphEndpoint = environment1.GraphEndpoint ?? environment2.GraphEndpoint }; return(mergedEnvironment); }