private void WriteResults(string fileName, string workingDir,
            BuildLogger logger)
        {
            if (_spellCheckResult == null)
            {
                return;
            }
            IList<BuildMisspelledWord> mispellWords = 
                _spellCheckResult.MisspelledWords;
            if (mispellWords == null || mispellWords.Count == 0)
            {
                return;
            }
            int misspellCount = mispellWords.Count;
            
            string filePrefix = _spellChecking.LogFilePrefix;
            if (String.IsNullOrEmpty(filePrefix))
            {   
                filePrefix = "SpellChecking";
            }

            string outputFile = filePrefix + "-" + Path.ChangeExtension(
                fileName, ".log");

            StringBuilder builder = new StringBuilder();
            using (StreamWriter writer = new StreamWriter(
                Path.Combine(workingDir, outputFile), false, Encoding.UTF8))
            {
                for (int i = 0; i < misspellCount; i++)
                {
                    BuildMisspelledWord mispellWord = mispellWords[i];

                    if (mispellWord.IsValid)
                    {
                        builder.Length = 0;
                        foreach (string suggestion in mispellWord.Suggestions)
                        {
                            builder.AppendFormat("\"{0}\" ", suggestion);
                        }

                        writer.WriteLine("Word=\"{0}\",Line={1},Position={2},Suggestions={3}",
                            mispellWord.Word, mispellWord.Line,
                            mispellWord.Position, builder.ToString());
                    }
                }  
            }

            if (logger != null)
            {
                logger.WriteLine(
                    "Misspelled words information written to: " + outputFile, 
                    BuildLoggerLevel.Info);
            }
        }
        private void SpellCheckTextNode(string nodeText, string tag, int line, int pos)
        {
            if (String.IsNullOrEmpty(nodeText))
            {
                return;
            }

            string word = String.Empty;

            string textLine = nodeText + " ";  // Move a breaking character beyond the end mark...

            for (int i = 0; i < textLine.Length; i++)
            {
                char ch = textLine[i];
                if (ch == ' ' || ch == '-' || ch == '.' || ch == ',' || ch == ':'  ||
                    ch == ';' || ch == '?' || ch == '!' || ch == '&' || ch == '\'' ||
                    ch == '/' || ch == '(' || ch == ')' || ch == '[' || ch == ']'  ||
                    ch == '{' || ch == '}')
                {
                    if (word.Length >= 2)
                    {
                        if (!_spellChecker.Spell(word))
                        {
                            BuildMisspelledWord misspelledWord = new BuildMisspelledWord(line,
                                pos - word.Length, word, tag, _spellChecker.Suggest(word));

                            _spellCheckResult.Add(misspelledWord);
                        }
                    }
                    word = String.Empty;
                    pos++;
                }
                else if (ch == '\r')
                {
                    if ((i + 1) < textLine.Length && textLine[i + 1] != '\n')  // but not \r\n
                    {
                        line++;
                        pos = 0;
                    }
                }
                else if (ch == '\n')
                {
                    line++;
                    pos = 0;
                }
                else
                {
                    word += ch;
                    pos++;
                }
            }
        }
        private void WriteXmlResults(string fileName, string workingDir,
            BuildLogger logger)
        {
            if (_spellCheckResult == null)
            {
                return;
            }
            IList<BuildMisspelledWord> mispellWords =
                _spellCheckResult.MisspelledWords;
            if (mispellWords == null || mispellWords.Count == 0)
            {
                return;
            }
            int misspellCount = mispellWords.Count;

            string filePrefix = _spellChecking.LogFilePrefix;
            if (String.IsNullOrEmpty(filePrefix))
            {
                filePrefix = "SpellChecking";
            }

            string outputFile = filePrefix + "-" + Path.ChangeExtension(
                fileName, ".xml");

            XmlWriterSettings xmlSettings = new XmlWriterSettings();
            xmlSettings.Encoding = Encoding.UTF8;
            xmlSettings.Indent   = true;

            StringBuilder builder = new StringBuilder();
            using (XmlWriter writer = XmlWriter.Create(
                Path.Combine(workingDir, outputFile), xmlSettings))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("misspelledWords");
                writer.WriteAttributeString("file", fileName);

                for (int i = 0; i < misspellCount; i++)
                {
                    BuildMisspelledWord mispellWord = mispellWords[i];

                    if (mispellWord.IsValid)
                    {
                        builder.Length = 0;
                        IList<string> suggestions = mispellWord.Suggestions;
                        int itemCount = suggestions.Count;
                        for (int j = 0; j < itemCount; j++)
                        {
                            builder.Append(suggestions[j]);
                            if (j != (itemCount - 1))
                            {
                                builder.Append(";");
                            }
                        }

                        writer.WriteStartElement("misspelledWord");
                        writer.WriteAttributeString("word", mispellWord.Word);
                        writer.WriteAttributeString("line", mispellWord.Line.ToString());
                        writer.WriteAttributeString("position", mispellWord.Position.ToString());
                        writer.WriteAttributeString("suggestions", builder.ToString());
                        writer.WriteEndElement();
                    }
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }

            if (logger != null)
            {
                logger.WriteLine(
                    "Misspelled words information written to: " + outputFile,
                    BuildLoggerLevel.Info);
            }
        }