Example #1
0
        /// <summary>
        /// This is used to generate the configuration for the instance
        /// </summary>
        /// <returns>The configuration to use or null if the file should not be spell checked (disabled or not a
        /// type of file that can be spell checked such as a binary file).</returns>
        public SpellCheckerConfiguration GenerateConfiguration(IEnumerable <string> codeAnalysisFiles)
        {
            var config = new SpellCheckerConfiguration();

            try
            {
                foreach (var c in this.ConfigurationFiles)
                {
                    config.Load(c.Value);
                }

                // Merge any code analysis dictionary settings
                if (codeAnalysisFiles != null)
                {
                    foreach (string cad in codeAnalysisFiles)
                    {
                        if (File.Exists(cad))
                        {
                            config.ImportCodeAnalysisDictionary(cad);
                        }
                    }
                }

                // If wanted, set the language based on the resource filename
                if (config.DetermineResourceFileLanguageFromName &&
                    Path.GetExtension(this.Filename).Equals(".resx", StringComparison.OrdinalIgnoreCase))
                {
                    // Localized resource files are expected to have filenames in the format
                    // BaseName.Language.resx (i.e. LocalizedForm.de-DE.resx).
                    string ext = Path.GetExtension(Path.GetFileNameWithoutExtension(this.Filename));

                    if (ext.Length > 1)
                    {
                        ext = ext.Substring(1);

                        SpellCheckerDictionary match;

                        if (SpellCheckerDictionary.AvailableDictionaries(
                                config.AdditionalDictionaryFolders).TryGetValue(ext, out match))
                        {
                            // Clear any existing dictionary languages and use just the one that matches the
                            // file's language.
                            config.DictionaryLanguages.Clear();
                            config.DictionaryLanguages.Add(match.Culture);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Ignore errors, we just won't load the configurations after the point of failure
                System.Diagnostics.Debug.WriteLine(ex);
            }

            return((!config.IncludeInProjectSpellCheck || config.ShouldExcludeFile(this.CanonicalName) ||
                    IsBinaryFile(this.CanonicalName)) ? null : config);
        }