public void AnalyzeBlock(
			Block block,
			int blockVersion)
        {
            // Grab the information about the block.
            string text;
            var originalMispelledWords = new TextSpanCollection();

            using (block.AcquireBlockLock(RequestLock.Read))
            {
                // If we are stale, then break out.
                if (block.IsStale(blockVersion))
                {
                    return;
                }

                // Grab the information from the block. We need the text and
                // alow the current spelling areas.
                text = block.Text;

                originalMispelledWords.AddRange(
                    block.TextSpans.Where(span => span.Controller == this));
            }

            // Split the word and perform spell-checking.
            var misspelledWords = new List<TextSpan>();
            IList<TextSpan> words = Splitter.SplitAndNormalize(text);
            IEnumerable<TextSpan> misspelledSpans =
                words.Where(span => !IsCorrect(span.GetText(text)));

            foreach (TextSpan span in misspelledSpans)
            {
                // We aren't correct, so add it to the list.
                span.Controller = this;

                misspelledWords.Add(span);
            }

            // Look to see if we have any change from the original spelling
            // errors and this one. This will only happen if the count is
            // identical and every one in the original list is in the new list.
            if (originalMispelledWords.Count == misspelledWords.Count)
            {
                bool isMatch = originalMispelledWords.All(misspelledWords.Contains);

                if (isMatch)
                {
                    // There are no new changes, so we don't have anything to
                    // update.
                    return;
                }
            }

            // Inside a write lock, we need to make modifications to the block's list.
            using (block.AcquireBlockLock(RequestLock.Write))
            {
                // Check one last time to see if the block is stale.
                if (block.IsStale(blockVersion))
                {
                    return;
                }

                // Make the changes to the block's contents.
                block.TextSpans.Remove(this);
                block.TextSpans.AddRange(misspelledWords);

                // Raise that we changed the spelling on the block.
                block.RaiseTextSpansChanged();
            }
        }
Пример #2
0
        public void AnalyzeBlock(
            Block block,
            int blockVersion)
        {
            // Grab the information about the block.
            string text;
            var    originalMispelledWords = new TextSpanCollection();

            using (block.AcquireBlockLock(RequestLock.Read))
            {
                // If we are stale, then break out.
                if (block.IsStale(blockVersion))
                {
                    return;
                }

                // Grab the information from the block. We need the text and
                // alow the current spelling areas.
                text = block.Text;

                originalMispelledWords.AddRange(
                    block.TextSpans.Where(span => span.Controller == this));
            }

            // Split the word and perform spell-checking.
            var misspelledWords                    = new List <TextSpan>();
            IList <TextSpan>       words           = Splitter.SplitAndNormalize(text);
            IEnumerable <TextSpan> misspelledSpans =
                words.Where(span => !IsCorrect(span.GetText(text)));

            foreach (TextSpan span in misspelledSpans)
            {
                // We aren't correct, so add it to the list.
                span.Controller = this;

                misspelledWords.Add(span);
            }

            // Look to see if we have any change from the original spelling
            // errors and this one. This will only happen if the count is
            // identical and every one in the original list is in the new list.
            if (originalMispelledWords.Count == misspelledWords.Count)
            {
                bool isMatch = originalMispelledWords.All(misspelledWords.Contains);

                if (isMatch)
                {
                    // There are no new changes, so we don't have anything to
                    // update.
                    return;
                }
            }

            // Inside a write lock, we need to make modifications to the block's list.
            using (block.AcquireBlockLock(RequestLock.Write))
            {
                // Check one last time to see if the block is stale.
                if (block.IsStale(blockVersion))
                {
                    return;
                }

                // Make the changes to the block's contents.
                block.TextSpans.Remove(this);
                block.TextSpans.AddRange(misspelledWords);

                // Raise that we changed the spelling on the block.
                block.RaiseTextSpansChanged();
            }
        }