public PSConnectionMonitorResultV1 ConvertConnectionMonitorResultToPSConnectionMonitorResultV1(ConnectionMonitorResult ConnectionMonitorResult) { PSConnectionMonitorResultV2 PSConnectionMonitorResultV2 = MapConnectionMonitorResultToPSConnectionMonitorResultV2(ConnectionMonitorResult); PSConnectionMonitorResultV1 ConnectionMonitorResultV1 = new PSConnectionMonitorResultV1() { Name = ConnectionMonitorResult.Name, Id = ConnectionMonitorResult.Id, Etag = ConnectionMonitorResult.Etag, ProvisioningState = ConnectionMonitorResult.ProvisioningState, Type = ConnectionMonitorResult.Type, Location = ConnectionMonitorResult.Location, AutoStart = ConnectionMonitorResult.AutoStart, StartTime = ConnectionMonitorResult.StartTime, MonitoringStatus = ConnectionMonitorResult.MonitoringStatus, ConnectionMonitorType = ConnectionMonitorResult.ConnectionMonitorType, MonitoringIntervalInSeconds = ConnectionMonitorResult.TestConfigurations?[0]?.TestFrequencySec, Tags = new Dictionary <string, string>() }; if (ConnectionMonitorResult.Tags != null) { foreach (KeyValuePair <string, string> KeyValue in ConnectionMonitorResult.Tags) { ConnectionMonitorResultV1.Tags.Add(KeyValue.Key, KeyValue.Value); } } if (ConnectionMonitorResultV1.Source == null) { ConnectionMonitorResultV1.Source = new PSConnectionMonitorSource() { ResourceId = PSConnectionMonitorResultV2.TestGroups?[0]?.Sources?[0]?.ResourceId }; } if (ConnectionMonitorResultV1.Destination == null) { ConnectionMonitorResultV1.Destination = new PSConnectionMonitorDestination() { ResourceId = PSConnectionMonitorResultV2.TestGroups?[0]?.Destinations?[0]?.ResourceId, Address = PSConnectionMonitorResultV2.TestGroups?[0]?.Destinations?[0]?.Address, Port = GetDestinationPort(PSConnectionMonitorResultV2.TestGroups?[0]?.TestConfigurations[0]) }; } return(ConnectionMonitorResultV1); }
public PSConnectionMonitorResultV2 MapConnectionMonitorResultToPSConnectionMonitorResultV2(ConnectionMonitorResult connectionMonitor) { PSConnectionMonitorResultV2 psConnectionMonitor = new PSConnectionMonitorResultV2() { Name = connectionMonitor.Name, Id = connectionMonitor.Id, Etag = connectionMonitor.Etag, ProvisioningState = connectionMonitor.ProvisioningState, Type = connectionMonitor.Type, Location = connectionMonitor.Location, StartTime = connectionMonitor.StartTime, Tags = new Dictionary <string, string>(), ConnectionMonitorType = connectionMonitor.ConnectionMonitorType, Notes = connectionMonitor.Notes, TestGroups = new List <PSNetworkWatcherConnectionMonitorTestGroupObject>() }; if (connectionMonitor.Tags != null) { foreach (KeyValuePair <string, string> KeyValue in connectionMonitor.Tags) { psConnectionMonitor.Tags.Add(KeyValue.Key, KeyValue.Value); } } if (connectionMonitor.Outputs != null) { psConnectionMonitor.Outputs = new List <PSNetworkWatcherConnectionMonitorOutputObject>(); foreach (ConnectionMonitorOutput output in connectionMonitor.Outputs) { psConnectionMonitor.Outputs.Add( new PSNetworkWatcherConnectionMonitorOutputObject() { Type = output.Type, WorkspaceSettings = new PSConnectionMonitorWorkspaceSettings() { WorkspaceResourceId = output.WorkspaceSettings?.WorkspaceResourceId } }); } } if (connectionMonitor.TestGroups != null) { foreach (ConnectionMonitorTestGroup testGroup in connectionMonitor.TestGroups) { PSNetworkWatcherConnectionMonitorTestGroupObject testGroupObject = new PSNetworkWatcherConnectionMonitorTestGroupObject() { Name = testGroup.Name, Disable = testGroup.Disable, TestConfigurations = new List <PSNetworkWatcherConnectionMonitorTestConfigurationObject>(), Sources = new List <PSNetworkWatcherConnectionMonitorEndpointObject>(), Destinations = new List <PSNetworkWatcherConnectionMonitorEndpointObject>() }; if (testGroup.Sources != null) { foreach (string sourceEndpointName in testGroup.Sources) { ConnectionMonitorEndpoint sourceEndpoint = GetEndpoinByName(connectionMonitor.Endpoints, sourceEndpointName); PSNetworkWatcherConnectionMonitorEndpointObject EndpointObject = NetworkResourceManagerProfile.Mapper.Map <PSNetworkWatcherConnectionMonitorEndpointObject>(sourceEndpoint); testGroupObject.Sources.Add(EndpointObject); } } if (testGroup.Destinations != null) { foreach (string destinationEndpointName in testGroup.Destinations) { ConnectionMonitorEndpoint destinationEndpoint = GetEndpoinByName(connectionMonitor.Endpoints, destinationEndpointName); PSNetworkWatcherConnectionMonitorEndpointObject EndpointObject = NetworkResourceManagerProfile.Mapper.Map <PSNetworkWatcherConnectionMonitorEndpointObject>(destinationEndpoint); testGroupObject.Destinations.Add(EndpointObject); } } // Test Configuration if (testGroup.TestConfigurations != null) { foreach (string testConfigurationName in testGroup.TestConfigurations) { ConnectionMonitorTestConfiguration testConfiguration = GetTestConfigurationByName(connectionMonitor.TestConfigurations, testConfigurationName); PSNetworkWatcherConnectionMonitorTestConfigurationObject testConfigurationObject = new PSNetworkWatcherConnectionMonitorTestConfigurationObject() { Name = testConfiguration.Name, PreferredIPVersion = testConfiguration.PreferredIPVersion, TestFrequencySec = testConfiguration.TestFrequencySec, SuccessThreshold = testConfiguration.SuccessThreshold == null ? null : new PSNetworkWatcherConnectionMonitorSuccessThreshold() { ChecksFailedPercent = testConfiguration.SuccessThreshold.ChecksFailedPercent, RoundTripTimeMs = testConfiguration.SuccessThreshold.RoundTripTimeMs }, ProtocolConfiguration = this.GetPSProtocolConfiguration(testConfiguration) }; testGroupObject.TestConfigurations.Add(testConfigurationObject); } } psConnectionMonitor.TestGroups.Add(testGroupObject); } } return(psConnectionMonitor); }