public static FilePropertyProvider Load(string filePath) { if (string.IsNullOrWhiteSpace(filePath)) { throw new ArgumentNullException(nameof(filePath)); } if (!File.Exists(filePath)) { throw new FileNotFoundException(Resources.ERROR_SettingsFileNotFound, filePath); } var properties = AnalysisProperties.Load(filePath); var provider = new FilePropertyProvider(properties, false); return provider; }
/// <summary> /// Attempts to construct and return a file-based properties provider /// </summary> /// <param name="defaultPropertiesFileDirectory">Directory in which to look for the default properties file (optional)</param> /// <param name="commandLineArguments">List of command line arguments (optional)</param> /// <returns>False if errors occurred when constructing the provider, otherwise true</returns> /// <remarks>If a properties file could not be located then an empty provider will be returned</remarks> public static bool TryCreateProvider(IEnumerable <ArgumentInstance> commandLineArguments, string defaultPropertiesFileDirectory, ILogger logger, out IAnalysisPropertyProvider provider) { if (commandLineArguments == null) { throw new ArgumentNullException(nameof(commandLineArguments)); } if (string.IsNullOrWhiteSpace(defaultPropertiesFileDirectory)) { throw new ArgumentNullException(nameof(defaultPropertiesFileDirectory)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } // If the path to a properties file was specified on the command line, use that. // Otherwise, look for a default properties file in the default directory. var settingsFileArgExists = ArgumentInstance.TryGetArgumentValue(DescriptorId, commandLineArguments, out var propertiesFilePath); if (ResolveFilePath(propertiesFilePath, defaultPropertiesFileDirectory, logger, out var locatedPropertiesFile)) { if (locatedPropertiesFile == null) { provider = EmptyPropertyProvider.Instance; } else { provider = new FilePropertyProvider(locatedPropertiesFile, !settingsFileArgExists); } return(true); } provider = null; return(false); }