コード例 #1
0
ファイル: Cleaner.cs プロジェクト: WillOmae/MySermons
            public static void ConvertOldFormat1(string existingRtf, RichTextBoxEx rtb)
            {
                var textMatches1 = Regex.Matches(existingRtf, @"\d?[a-zA-Z]{1,3}\.\d{1,3}\.\d{1,3}-\d?[a-zA-Z]{1,3}\.\d{1,3}\.\d{1,3}");
                var textMatches2 = Regex.Matches(existingRtf, @"\d?[a-zA-Z]{1,3}\.\d{1,3}\.\d{1,3}");

                int arraySize = textMatches1.Count + textMatches2.Count;

                Match[] matches = new Match[arraySize];

                textMatches1.CopyTo(matches, 0);
                textMatches2.CopyTo(matches, textMatches1.Count);

                if (matches.Length > 0)
                {
                    foreach (Match match in matches)
                    {
                        string             oldVerseText = match.Value.Trim();
                        XMLBible.BCVSTRUCT start, end;
                        start = new XMLBible.BCVSTRUCT();
                        end   = new XMLBible.BCVSTRUCT();
                        XMLBible.ParseForBCVStructs(oldVerseText, ref start, ref end);



                        if (!string.IsNullOrEmpty(start.Book) &&
                            XMLBible.ConfirmBookNameExists(start.Book) &&
                            int.Parse(start.Chapter) <= XMLBible.ChapterCount(start.Book) &&
                            int.Parse(start.Verse) <= XMLBible.VerseCount(start.Book, start.Chapter))
                        {
                            string newVerseText = string.Empty;
                            if (string.IsNullOrEmpty(end.Book))
                            {
                                newVerseText = XMLBible.GetBookName_abbr(start.Book) + " " + start.Chapter + ":" + start.Verse;
                            }
                            else
                            {
                                if (XMLBible.ConfirmBookNameExists(end.Book) &&
                                    int.Parse(end.Chapter) <= XMLBible.ChapterCount(end.Book) &&
                                    int.Parse(end.Verse) <= XMLBible.VerseCount(end.Book, end.Chapter))
                                {
                                    if (start.Verse == "1" && end.Verse == XMLBible.VerseCount(end.Book, end.Chapter).ToString())
                                    {
                                        newVerseText = XMLBible.GetBookName_short(start.Book) + " " + start.Chapter;
                                    }
                                    else
                                    {
                                        newVerseText = XMLBible.GetBookName_abbr(start.Book) + " " + start.Chapter + ":" + start.Verse + "-" + end.Verse;
                                    }
                                }
                            }
                            if (!string.IsNullOrEmpty(newVerseText))
                            {
                                d_ReplaceOldVerseText myDelegate = new d_ReplaceOldVerseText(InvokeReplaceOldVerseText);
                                rtb.Invoke(myDelegate, oldVerseText, newVerseText, rtb);
                            }
                        }
                    }
                }
            }
コード例 #2
0
ファイル: Cleaner.cs プロジェクト: WillOmae/MySermons
            public static void RemoveVerseHiddenText(string existingRtf, RichTextBoxEx rtb)
            {
                d_DeleteText myDelegate;

                var textMatches = Regex.Matches(existingRtf, @"\\v(.*?)\\v0");

                if (textMatches.Count > 0)
                {
                    foreach (Match match in textMatches)
                    {
                        myDelegate = new d_DeleteText(InvokeRemoveText);
                        rtb.Invoke(myDelegate, match.Value, rtb);
                    }
                }
            }
コード例 #3
0
        /// <summary>
        /// When the form is shown, verse links are detected and updated in the text box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FormShown(object sender, EventArgs e)
        {
            textBox.Rtf = RTF;

            string rtf = textBox.Rtf;

            LoadingForm      loadingForm = new LoadingForm();
            BackgroundWorker bw          = new BackgroundWorker()
            {
                WorkerReportsProgress      = true,
                WorkerSupportsCancellation = true
            };

            bw.DoWork += delegate
            {
                Cleaner.VerseHiddenText.RemoveVerseHiddenText(rtf, textBox);
                Cleaner.BCVVerses.ConvertOldFormat1(rtf, textBox);
                d_GetText delegateGetTextBoxText = new d_GetText(InvokeGetText);
                string    text = (string)textBox.Invoke(delegateGetTextBoxText);

                var textMatches1 = Regex.Matches(text, @"\d?[ ]?[a-zA-Z]+[ ]?\d{1,3}[ ]?:[ ]?\d{1,3}[ ]?-[ ]?\d{1,3}");
                var textMatches2 = Regex.Matches(text, @"\d?[ ]?[a-zA-Z]+[ ]?\d{1,3}[ ]?:[ ]?\d{1,3}");
                var textMatches5 = Regex.Matches(text, @"\d?[ ]?[a-zA-Z]+[ ]?\d{1,3}");

                int     arraySize = textMatches1.Count + textMatches2.Count + textMatches5.Count;
                Match[] matches   = new Match[arraySize];
                textMatches1.CopyTo(matches, 0);
                textMatches2.CopyTo(matches, textMatches1.Count);
                textMatches5.CopyTo(matches, textMatches1.Count + textMatches2.Count);

                if (matches.Length > 0)
                {
                    foreach (Match match in matches)
                    {
                        string matchText       = match.Value.Trim();
                        var    booknameMatches = Regex.Match(matchText, @"^\d? ?[a-zA-Z]*");
                        if (booknameMatches.Success)
                        {
                            if (XMLBible.ConfirmBookNameExists(booknameMatches.Value))
                            {
                                d_InsertLink myDelegate = new d_InsertLink(InsertLink_TextMethod);
                                textBox.Invoke(myDelegate, matchText);
                            }
                        }
                    }
                }
            };
            bw.RunWorkerCompleted += delegate
            {
                BackToStart();
                loadingForm.Close();
            };
            loadingForm.FormClosing += delegate
            {
                if (bw != null && bw.IsBusy)
                {
                    bw.CancelAsync();
                }
            };

            bw.RunWorkerAsync();
            loadingForm.ShowDialog();
        }