Exemplo n.º 1
0
    internal static int WriteDefaultSettingsCommand(CommandLineOptions options)
    {
        Log.Logger.Information("Writing default settings to {SettingsFile}", options.SettingsFile);

        // Save default config
        ConfigFileJsonSchema.WriteDefaultsToFile(options.SettingsFile);

        return(0);
    }
Exemplo n.º 2
0
    public void Open_OldSchemas_Opens(string fileName)
    {
        ConfigFileJsonSchema configFileJsonSchema = ConfigFileJsonSchema.FromFile(SampleFiles.GetSampleFilePath(fileName));

        Assert.NotNull(configFileJsonSchema);
    }
Exemplo n.º 3
0
    private static Program Create(CommandLineOptions options, bool verifyTools)
    {
        // Load config from JSON
        if (!File.Exists(options.SettingsFile))
        {
            Log.Logger.Error("Settings file not found : {SettingsFile}", options.SettingsFile);
            return(null);
        }
        Log.Logger.Information("Loading settings from : {SettingsFile}", options.SettingsFile);
        ConfigFileJsonSchema config = ConfigFileJsonSchema.FromFile(options.SettingsFile);

        // Compare the schema version
        if (config.SchemaVersion != ConfigFileJsonSchema.Version)
        {
            Log.Logger.Warning("Settings JSON schema mismatch : {SchemaVersion} != {Version}, {FileName}",
                               config.SchemaVersion,
                               ConfigFileJsonSchema.Version,
                               options.SettingsFile);

            // Upgrade the file schema
            Log.Logger.Information("Writing upgraded settings file : {FileName}", options.SettingsFile);
            ConfigFileJsonSchema.ToFile(options.SettingsFile, config);
        }

        // Set the static options from the loaded settings
        Options = options;
        Config  = config;

        // Set the FileEx options
        FileEx.Options.TestNoModify  = Options.TestNoModify;
        FileEx.Options.RetryCount    = config.MonitorOptions.FileRetryCount;
        FileEx.Options.RetryWaitTime = config.MonitorOptions.FileRetryWaitTime;

        // Set the FileEx Cancel object
        FileEx.Options.Cancel = CancelSource.Token;

        // Use log file
        if (!string.IsNullOrEmpty(options.LogFile))
        {
            // Delete if not in append mode
            if (!options.LogAppend &&
                !FileEx.DeleteFile(options.LogFile))
            {
                Log.Logger.Error("Failed to clear the logfile : {LogFile}", options.LogFile);
                return(null);
            }

            // Recreate the logger with a file
            CreateLogger(options.LogFile);
            Log.Logger.Information("Logging output to : {LogFile}", options.LogFile);
        }

        // Log app and runtime version
        string appVersion     = Assembly.GetExecutingAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>()?.InformationalVersion;
        string runtimeVersion = Environment.Version.ToString();

        Log.Logger.Information("Application Version : {AppVersion}, Runtime Version : {RuntimeVersion}", appVersion, runtimeVersion);

        // Verify tools
        if (verifyTools)
        {
            // Upgrade tools if auto update is enabled
            if (Config.ToolsOptions.AutoUpdate &&
                !Tools.CheckForNewTools())
            {
                return(null);
            }

            // Verify tools
            if (!Tools.VerifyTools())
            {
                return(null);
            }
        }

        // Create program instance
        return(new Program());
    }