public void ValidateConnectionMonitor(PSNetworkWatcherConnectionMonitorObject connectionMonitor, bool throwIfTestGroupNotSet = true) { if (throwIfTestGroupNotSet && (connectionMonitor.TestGroups == null || !connectionMonitor.TestGroups.Any())) { throw new PSArgumentException(Properties.Resources.ConnectionMonitorMustHaveTestGroups); } if (connectionMonitor.TestGroups != null) { foreach (PSNetworkWatcherConnectionMonitorTestGroupObject testGroup in connectionMonitor.TestGroups) { this.ValidateTestGroup(testGroup); } } if (connectionMonitor.Outputs != null) { foreach (PSNetworkWatcherConnectionMonitorOutputObject output in connectionMonitor.Outputs) { this.ValidateOutput(output); } } }
public override void Execute() { base.Execute(); if (ParameterSetName.Contains("SetByResource")) { this.NetworkWatcherName = this.NetworkWatcher.Name; this.ResourceGroupName = this.NetworkWatcher.ResourceGroupName; } else if (ParameterSetName.Contains("SetByLocation")) { var networkWatcher = this.GetNetworkWatcherByLocation(this.Location); if (networkWatcher == null) { throw new ArgumentException(Properties.Resources.NoNetworkWatcherFound); } this.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id); this.NetworkWatcherName = networkWatcher.Name; } PSNetworkWatcherConnectionMonitorObject connectionMonitor = new PSNetworkWatcherConnectionMonitorObject() { NetworkWatcherName = this.NetworkWatcherName, ResourceGroupName = this.ResourceGroupName, Name = this.Name, TestGroups = this.TestGroup?.ToList(), Outputs = this.Output?.ToList(), Notes = this.Note, Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true) }; this.ValidateConnectionMonitor(connectionMonitor, throwIfTestGroupNotSet: false); WriteObject(connectionMonitor); }