Exemplo n.º 1
0
        /// <summary>
        /// Sets the options.
        /// </summary>
        /// <param name="options">The command line options.</param>
        private void SetOptions(IAppOptionsService options)
        {
            // Set working path (and reset current directory to working path)
            options.Options.WorkingPath  = new DirectoryInfo(BuildWorkingPath(options.Options.WorkingPath.FullName));
            Environment.CurrentDirectory = options.Options.WorkingPath.FullName;

            _logger.LogDebug(TraceMessages.SetWorkingPath, options.Options.WorkingPath);

            // Set state path
            if (options.Options.StatePath == null)
            {
                options.Options.StatePath = new DirectoryInfo(Path.Join(options.Options.WorkingPath.FullName, "state")).FullName;
            }
            else
            {
                options.Options.StatePath = new DirectoryInfo(BuildWorkingPath(options.Options.StatePath)).FullName;
            }

            _logger.LogDebug(TraceMessages.SetStatePath, options.Options.StatePath);

            if (options.Verb == CommandVerb.Assess)
            {
                // Set output model path if specified
                if (options.Options.OutputModel != null)
                {
                    options.Options.OutputModel = new FileInfo(Path.Combine(options.Options.WorkingPath.FullName, options.Options.OutputModel)).FullName;

                    _logger.LogDebug(TraceMessages.SetOutputModelPath, options.Options.OutputModel);
                }
            }

            if (options.Verb == CommandVerb.Migrate || options.Verb == CommandVerb.Convert)
            {
                // Set the conversion path
                if (options.Options.ConversionPath == null)
                {
                    options.Options.ConversionPath = new DirectoryInfo(Path.Join(options.Options.WorkingPath.FullName, "conversion")).FullName;
                }
                else
                {
                    options.Options.ConversionPath = new DirectoryInfo(BuildWorkingPath(options.Options.ConversionPath)).FullName;
                }

                _logger.LogDebug(TraceMessages.SetConversionPath, options.Options.ConversionPath);
            }

            // Generate unique ID to be used for Azure deployments
            if (string.IsNullOrWhiteSpace(options.Options.UniqueDeploymentId))
            {
                options.Options.UniqueDeploymentId = _generator.Generate(truncate: AppOptionsService.UniqueDeploymentIdLengthLimit);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Sets the log level.
 /// </summary>
 /// <param name="options">The command line options.</param>
 private void SetLogLevel(IAppOptionsService options)
 {
     // Change verbose level, only if verbose logging switched on
     if (options.Options.Verbose)
     {
         if (options.Options.VerboseLevel == '+')
         {
             // Set maximum level
             _loggingService.SetLoggingLevel(LogLevel.Trace);
         }
         else
         {
             // Set minimum level
             _loggingService.SetLoggingLevel(LogLevel.Debug);
         }
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Constructs an instance of the <see cref="App"/> class with its dependencies.
 /// </summary>
 /// <param name="generator">The unique ID generator.</param>
 /// <param name="builder">The migration runner builder.</param>
 /// <param name="provider">The provider used to find stage runners.</param>
 /// <param name="modelProvider">The provider used to find model provider.</param>
 /// <param name="pluginHost">The stage runner plugin host.</param>
 /// <param name="options">The command line options.</param>
 /// <param name="loggingService">The logging service.</param>
 /// <param name="runnerLogger">The logger for the runner.</param>
 /// <param name="logger">The logger for the app.</param>
 public App(
     IUniqueIdGenerator generator,
     IRunnerBuilder builder,
     IStageComponentProvider provider,
     PluginModelComponentProvider modelProvider,
     IPluginHost <IRunnerComponent> pluginHost,
     IAppOptionsService options,
     ILoggingService loggingService,
     ILogger <Runner.Engine.Runner> runnerLogger,
     ILogger <App> logger)
 {
     // Validate and set members
     _generator      = generator ?? throw new ArgumentNullException(nameof(generator));
     _builder        = builder ?? throw new ArgumentNullException(nameof(builder));
     _provider       = provider ?? throw new ArgumentNullException(nameof(provider));
     _modelProvider  = modelProvider ?? throw new ArgumentNullException(nameof(modelProvider));
     _pluginHost     = pluginHost ?? throw new ArgumentNullException(nameof(pluginHost));
     _options        = options ?? throw new ArgumentNullException(nameof(options));
     _loggingService = loggingService ?? throw new ArgumentNullException(nameof(loggingService));
     _runnerLogger   = runnerLogger ?? throw new ArgumentNullException(nameof(runnerLogger));
     _logger         = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Validates the options.
        /// </summary>
        /// <param name="options">The command line options.</param>
        /// <returns>True if the validation succeeded, otherwise False.</returns>
        private bool ValidateOptions(IAppOptionsService options)
        {
            _logger.LogDebug(TraceMessages.ValidatingOptions);

            var errors = options.Validate();

            if (errors != null && errors.Any())
            {
                _logger.LogError(ErrorMessages.ArgumentsFailedValidation, errors.Count());

                foreach (var error in errors)
                {
                    _logger.LogError(ErrorMessages.ArgumentValidationError, error);
                }

                return(false);
            }
            else
            {
                _logger.LogDebug(TraceMessages.OptionsValidationSuccessful);

                return(true);
            }
        }