public static void StartMode(BackgroundWorker worker, RegexTesterPageViewModel viewModel, DoWorkEventArgs args)
        {
            viewModel.PrepareProcess();
            RegexProcessContext context = (RegexProcessContext)args.Argument;
            bool complete = true;

            IRegexProcessStrategy strategy = RegexProcessStrategy[context.OutputMode];

            if (context.CurrentMode == RegexMode.Match)
            {
                complete = strategy.Match(worker, viewModel, context);
            }
            else if (context.CurrentMode == RegexMode.Replace)
            {
                complete = strategy.Replace(worker, viewModel, context);
            }
            else
            {
                complete = strategy.Split(worker, viewModel, context);
            }

            if (!complete)
            {
                args.Cancel = true;
            }
        }
예제 #2
0
        private void RunProcess()
        {
            if (!initialize)
            {
                return;
            }

            string matchPattern = GetInputText(rtbInputRegex);

            #region Check matchPattern

            viewModel.PrepareProcess();

            if (string.IsNullOrEmpty(matchPattern))
            {
                ClearRegexSyntaxError(rtbInputRegex, rtbInputReplace);
                viewModel.CompleteProcess();
                ClearResultData();
                return;
            }

            try
            {
                Regex checkInputRegex = new Regex(matchPattern);
                ClearRegexSyntaxError(rtbInputRegex, rtbInputReplace);
            }
            catch (Exception ex)
            {
                AddRegexSyntaxError(rtbInputRegex, ex.Message);
                viewModel.CompleteProcess();
                ClearResultData();
                return;
            }

            #endregion

            if (worker.IsBusy)
            {
                worker.CancelAsync();
                int timeout = process_is_busy ? 500 : 100;
                System.Threading.Thread.Sleep(timeout);
            }

            RegexProcessContext context = new RegexProcessContext();
            context.MatchRegex          = new Regex(matchPattern, GetRegexOptions());
            context.ReplaceRegexPattern = GetInputText(rtbInputReplace);
            context.CurrentMode         = GetCurrentMode();
            context.InputText           = tbInputText.Text;
            context.OutputMode          = GetOutputMode();

            if (!worker.IsBusy)
            {
                worker.RunWorkerAsync(context);
            }
            else
            {
                if (process_is_busy && viewModel.Autorun)
                {
                    process_is_busy   = false;
                    viewModel.Autorun = false;
                }
                else
                {
                    process_is_busy = true;
                    RunProcess();
                }
            }
        }