private async Task AddTargetType(IEnumerable <string> arguments, IEnumerable <IParameter> parameters, CancellationToken cancellationToken)
        {
            var firstArgument       = arguments.FirstOrDefault();
            var parameterDictionary = parameters.ToDictionary();

            if (string.IsNullOrEmpty(firstArgument))
            {
                throw ModuleException("Target type requires a name", LogLevel.Error);
            }

            var targetType = new TargetType
            {
                Name = firstArgument
            };

            if (parameterDictionary.TryGetValue("description", out var description))
            {
                targetType.Description = description;
            }

            if (await targetTypeService.TryAddAsync(targetType, cancellationToken))
            {
                cacheState.TryAddOrUpdate(CacheStateItem.Create(nameof(IDeploymentCache.TargetTypes), systemClock.UtcNow));
                await consoleWrapper.WriteLineAsync("Target type saved", true, LogLevel.Information);
            }
            else
            {
                throw ModuleException("Target type not saved", LogLevel.Error);
            }
        }
        private async Task AddTarget(IEnumerable <string> arguments, IEnumerable <IParameter> parameters, CancellationToken cancellationToken)
        {
            var firstArgument = arguments.FirstOrDefault();

            if (!string.IsNullOrEmpty(firstArgument) && firstArgument.Equals("type"))
            {
                await AddTargetType(arguments.RemoveAt(0), parameters, cancellationToken);

                return;
            }

            var parametersDictionary = parameters.ToDictionary();
            var targetType           = await GetTargetTypeFromParameters(parametersDictionary, cancellationToken);

            if (targetType == null)
            {
                throw ModuleException("Target type {0} not found", LogLevel.Error);
            }

            var target = new Target
            {
                Reference    = firstArgument,
                TargetTypeId = targetType.Id
            };

            if (parametersDictionary.TryGetValue("connectionString", out var connectionString))
            {
                target.ConnectionString = connectionString;
            }

            if (parametersDictionary.TryGetValue("databaseName", out var databaseName))
            {
                target.DatabaseName = databaseName;
            }

            if (parametersDictionary.TryGetValue("targetReference", out var targetReference))
            {
                target.FullyQualifiedTargetReference = targetReference;
            }

            if (string.IsNullOrEmpty(target.ConnectionString) ||
                string.IsNullOrEmpty(target.DatabaseName))
            {
                throw ModuleException("A connection string or database name must be supplied", LogLevel.Error);
            }

            if (string.IsNullOrEmpty(target.FullyQualifiedTargetReference))
            {
                throw ModuleException("A fully qualified target reference must be supplied", LogLevel.Error);
            }

            if (await targetService.TryAddAsync(target, cancellationToken))
            {
                cacheState.TryAddOrUpdate(CacheStateItem.Create(nameof(IDeploymentCache.Targets), systemClock.UtcNow));
                await consoleWrapper.WriteLineAsync("Deployment saved", true, LogLevel.Information);
            }
            else
            {
                throw ModuleException("Deployment not saved", LogLevel.Error);
            }
        }