Ejemplo n.º 1
0
        /// <summary>
        ///		Perform Cmdlet processing.
        /// </summary>
        protected override void ProcessRecord()
        {
            WriteVerbose($"Remove CloudControl connection '{Name}'...");

            SessionState.ReadConnections();

            CloudControlClient client;

            if (SessionState.Clients().TryGetValue(Name, out client))
            {
                WriteVerbose($"Closing connection '{Name}'...");
                client.Dispose();
                WriteVerbose($"Closed connection '{Name}'.");
            }

            if (!SessionState.Connections().Remove(Name))
            {
                WriteError(
                    Errors.ConnectionDoesNotExist(Name)
                    );

                return;
            }

            SessionState.WriteConnections();
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Persist connection settings for the current runspace.
        /// </summary>
        /// <param name="sessionState">
        ///		The session state containing connection settings to persist.
        /// </param>
        public static void WriteConnections(this SessionState sessionState)
        {
            if (sessionState == null)
            {
                throw new ArgumentNullException(nameof(sessionState));
            }

            SettingsStore.WriteConnectionSettings(
                sessionState.Connections()
                );
        }
        /// <summary>
        ///		Perform Cmdlet processing.
        /// </summary>
        protected override void ProcessRecord()
        {
            SessionState.ReadConnections();

            switch (ParameterSetName)
            {
            case "All":
            {
                IEnumerable <ConnectionSettings> connections =
                    SessionState.Connections().Values.OrderBy(
                        connection => connection.Name
                        );

                foreach (ConnectionSettings connection in connections)
                {
                    WriteObject(connection);
                }

                break;
            }

            case "By Name":
            {
                ConnectionSettings connection;
                if (SessionState.Connections().TryGetValue(Name, out connection))
                {
                    WriteObject(connection);
                }

                break;
            }

            default:
            {
                ThrowTerminatingError(
                    Errors.UnrecognizedParameterSet(this)
                    );

                break;
            }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Get or create a <see cref="CloudControlClient"/> for Cmdlet.
        /// </summary>
        /// <returns>
        ///     The <see cref="CloudControlClient"/>.
        /// </returns>
        protected CloudControlClient GetClient()
        {
            SessionState.ReadConnections();

            if (String.IsNullOrWhiteSpace(ConnectionName))
            {
                ConnectionName = SessionState.GetDefaultCloudControlConnectionName();
            }

            if (String.IsNullOrWhiteSpace(ConnectionName))
            {
                ThrowTerminatingError(
                    Errors.ConnectionRequired(this)
                    );

                return(null);
            }

            CloudControlClient client;

            if (!SessionState.Clients().TryGetValue(ConnectionName, out client))
            {
                ConnectionSettings connection;
                if (!SessionState.Connections().TryGetValue(ConnectionName, out connection))
                {
                    ThrowTerminatingError(
                        Errors.ConnectionDoesNotExist(ConnectionName)
                        );

                    return(null);
                }

                client = CloudControlClient.Create(
                    new Uri($"https://api-{connection.Region.ToLower()}.dimensiondata.com/"),
                    connection.CreateNetworkCredential()
                    );
                SessionState.Clients().Add(ConnectionName, client);
            }

            return(client);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///		Perform Cmdlet processing.
        /// </summary>
        protected override void ProcessRecord()
        {
            WriteVerbose($"Create CloudControl connection '{Name}'...");

            SessionState.ReadConnections();

            if (SessionState.Connections().ContainsKey(Name))
            {
                WriteError(
                    Errors.ConnectionExists(Name)
                    );

                return;
            }

            ConnectionSettings settings = new ConnectionSettings
            {
                Name   = Name,
                Region = Region
            };

            if (Credentials != null)
            {
                settings.UserName = Credentials.UserName;
                settings.Password = Credentials.Password.ToInsecureString();
            }
            else
            {
                settings.UserName = UserName;
                settings.Password = Password;
            }
            SessionState.Connections().Add(settings.Name, settings);

            if (SetDefault)
            {
                SessionState.SetDefaultCloudControlConnection(Name);
            }

            SessionState.WriteConnections();
        }