Example #1
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="filename">The filename to load</param>
        /// <param name="spellCheckConfiguration">The spell checker configuration for the file</param>
        protected TextClassifier(string filename, SpellCheckerConfiguration spellCheckConfiguration)
        {
            this.Filename = filename;
            this.SpellCheckConfiguration = spellCheckConfiguration;

            ignoredClassifications = new List <RangeClassification>();

            // Get the ignored classifications based on the extension.  If there are none, check for the
            // file type.
            string ext = Path.GetExtension(filename);

            if (!String.IsNullOrWhiteSpace(ext))
            {
                ext = ext.Substring(1);
            }

            var exclusions = spellCheckConfiguration.IgnoredClassificationsFor(PropertyNames.Extension + ext);

            if (!exclusions.Any())
            {
                exclusions = spellCheckConfiguration.IgnoredClassificationsFor(PropertyNames.FileType +
                                                                               ClassifierFactory.ClassifierIdFor(filename));
            }

            RangeClassification rangeType;

            foreach (string exclusion in exclusions)
            {
                if (Enum.TryParse <RangeClassification>(exclusion, out rangeType))
                {
                    ignoredClassifications.Add(rangeType);
                }
            }

            if (!File.Exists(filename))
            {
                this.SetText(String.Empty);
            }
            else
            {
                using (StreamReader sr = new StreamReader(filename, Encoding.Default, true))
                {
                    this.SetText(sr.ReadToEnd());
                }
            }
        }