public override void Execute()
        {
            base.Execute();

            MNM.ConnectivityParameters parameters = new MNM.ConnectivityParameters();

            parameters.Source            = new MNM.ConnectivitySource();
            parameters.Source.ResourceId = this.SourceId;
            parameters.Source.Port       = this.SourcePort;

            parameters.Destination            = new MNM.ConnectivityDestination();
            parameters.Destination.ResourceId = this.DestinationId;
            parameters.Destination.Address    = this.DestinationAddress;
            parameters.Destination.Port       = this.DestinationPort;

            if (this.ProtocolConfiguration != null && string.Equals(this.ProtocolConfiguration.Protocol, "Http", StringComparison.OrdinalIgnoreCase))
            {
                IList <MNM.HTTPHeader> headers = new List <MNM.HTTPHeader>();
                if (this.ProtocolConfiguration.Header != null)
                {
                    foreach (DictionaryEntry entry in this.ProtocolConfiguration.Header)
                    {
                        headers.Add(new MNM.HTTPHeader((string)entry.Key, (string)entry.Value));
                    }
                }

                MNM.HTTPConfiguration httpConfiguration = new MNM.HTTPConfiguration(this.ProtocolConfiguration.Method, headers, this.ProtocolConfiguration.ValidStatusCode.OfType <int?>().ToList());
                parameters.ProtocolConfiguration = new MNM.ProtocolConfiguration(httpConfiguration);
            }

            MNM.ConnectivityInformation result = new MNM.ConnectivityInformation();
            if (string.Equals(this.ParameterSetName, "SetByLocation", StringComparison.OrdinalIgnoreCase))
            {
                var networkWatcher = this.GetNetworkWatcherByLocation(this.Location);

                if (networkWatcher == null)
                {
                    throw new ArgumentException("There is no network watcher in location {0}", this.Location);
                }

                this.ResourceGroupName  = NetworkBaseCmdlet.GetResourceGroup(networkWatcher.Id);
                this.NetworkWatcherName = networkWatcher.Name;
                result = this.NetworkWatcherClient.CheckConnectivity(this.ResourceGroupName, this.NetworkWatcherName, parameters);
            }
            else if (string.Equals(this.ParameterSetName, "SetByResource", StringComparison.OrdinalIgnoreCase))
            {
                result = this.NetworkWatcherClient.CheckConnectivity(this.NetworkWatcher.ResourceGroupName, this.NetworkWatcher.Name, parameters);
            }
            else
            {
                result = this.NetworkWatcherClient.CheckConnectivity(this.ResourceGroupName, this.NetworkWatcherName, parameters);
            }

            PSConnectivityInformation psResult = NetworkResourceManagerProfile.Mapper.Map <PSConnectivityInformation>(result);

            WriteObject(psResult);
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the ProtocolConfiguration class.
 /// </summary>
 /// <param name="hTTPConfiguration">HTTP configuration of the
 /// connectivity check.</param>
 public ProtocolConfiguration(HTTPConfiguration hTTPConfiguration = default(HTTPConfiguration))
 {
     HTTPConfiguration = hTTPConfiguration;
     CustomInit();
 }