Exemplo n.º 1
0
        /// <summary>
        /// Attempt to find a properties file - either the one specified by the user, or the default properties file.
        /// Returns true if the path to a file could be resolved, otherwise false.
        /// </summary>
        private static bool ResolveFilePath(string propertiesFilePath, string defaultPropertiesFileDirectory, ILogger logger,
                                            out AnalysisProperties properties)
        {
            properties = null;
            var isValid = true;

            var resolvedPath = propertiesFilePath ?? TryGetDefaultPropertiesFilePath(defaultPropertiesFileDirectory, logger);

            if (resolvedPath != null)
            {
                // The File APIs below will automatically work with relative paths, but we resolve
                // the path anyway because we want to show better error messages, containing the
                // actual path where we were looking for the properties files.
                resolvedPath = Path.GetFullPath(resolvedPath);

                if (File.Exists(resolvedPath))
                {
                    try
                    {
                        logger.LogDebug(Resources.MSG_Properties_LoadingPropertiesFromFile, resolvedPath);
                        properties = AnalysisProperties.Load(resolvedPath);
                    }
                    catch (InvalidOperationException)
                    {
                        logger.LogError(Resources.ERROR_Properties_InvalidPropertiesFile, resolvedPath);
                        isValid = false;
                    }
                }
                else
                {
                    logger.LogError(Resources.ERROR_Properties_GlobalPropertiesFileDoesNotExist, resolvedPath);
                    isValid = false;
                }
            }
            return(isValid);
        }
Exemplo n.º 2
0
 private FilePropertyProvider(AnalysisProperties properties, bool isDefaultPropertiesFile)
 {
     PropertiesFile          = properties ?? throw new ArgumentNullException(nameof(properties));
     IsDefaultPropertiesFile = isDefaultPropertiesFile;
 }