Ejemplo n.º 1
0
        public void AddCriteria(RegExpCriteriaType criteriaType, string value)
        {
            RegExpCriteriaCollection collection = null;

            switch (criteriaType)
            {
            case RegExpCriteriaType.Exception:
                collection = this.Exceptions;
                break;

            case RegExpCriteriaType.LookAhead:
                collection = this.LookAhead;
                break;

            case RegExpCriteriaType.LookBehind:
                collection = this.LookBehind;
                break;

            case RegExpCriteriaType.NegLookAhead:
                collection = this.NegLookAhead;
                break;

            case RegExpCriteriaType.NegLookBehind:
                collection = this.NegLookBehind;
                break;
            }

            ///////////////////////////////////////////////////////////////////////////////

            if (collection == null)
            {
                return;
            }

            ///////////////////////////////////////////////////////////////////////////////

            var stringComparison = criteriaType == RegExpCriteriaType.Exception ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture;

            if (collection.Items.Any(x => String.Compare(x.Expression, value, stringComparison) == 0))
            {
                return;
            }

            collection.Items.Add(new RegExpCriteria
            {
                Expression = value,
                Enabled    = true
            });
        }
Ejemplo n.º 2
0
        public static RegExpCriteriaCollection FromString(RegExpCriteriaType type, string look)
        {
            var result = new RegExpCriteriaCollection(type);

            if (String.IsNullOrEmpty(look))
            {
                return(result);
            }

            ///////////////////////////////////////////////////////////////////////////////

            try
            {
                if (look.StartsWith("{") || look.StartsWith("["))
                {
                    result = JsonConvert.DeserializeObject <RegExpCriteriaCollection>(look);

                    return(result);
                }
            }
            catch { }

            ///////////////////////////////////////////////////////////////////////////////

            try
            {
                result.Items = look.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries)
                               .Select(x => new RegExpCriteria {
                    Expression = x, Enabled = true
                })
                               .ToList();
            }
            catch { }

            ///////////////////////////////////////////////////////////////////////////////

            return(result);
        }
Ejemplo n.º 3
0
 public RegExpCriteriaCollection(RegExpCriteriaType type)
 {
     this.Type  = type;
     this.Items = new List <RegExpCriteria>();
 }
Ejemplo n.º 4
0
        protected void AppendRegExpCriteria(RegExpMatchResult match, RegExpCriteriaType criteriaType, string strPrefix, string strSuffix)
        {
            try
            {
                string strSelectedText = (string)textBox.Tag;

                if (criteriaType != RegExpCriteriaType.Exception)
                {
                    if (strSelectedText.IndexOf(" ", StringComparison.InvariantCulture) == -1 && strSelectedText.Trim() == strSelectedText)
                    {
                        strSelectedText = strPrefix + @"\b" + Regex.Escape(strSelectedText) + @"\b" + strSuffix;
                    }
                    else
                    {
                        strSelectedText = strPrefix + Regex.Escape(strSelectedText) + strSuffix;
                    }
                }
                else
                {
                    strSelectedText = strPrefix + strSelectedText + strSuffix;
                }

                var rowRegExp = _views.MainForm.datasetMain.ColRegExp.FirstOrDefault(x => x.ID == match.RegExp.ID);
                if (rowRegExp != null)
                {
                    var regExp = RegExpFactory.Create_ColRegExp(rowRegExp, null, false);
                    regExp.AddCriteria(criteriaType, strSelectedText);

                    regExp.SafeSave(rowRegExp, true);

                    //////////////////////////////////////////////////////////////////////////

                    if (this.RefreshHighlights != null)
                    {
                        this.RefreshHighlights(this, EventArgs.Empty);
                    }

                    //////////////////////////////////////////////////////////////////////////

                    if (this.CalcScores != null)
                    {
                        if (_views.AutoCalc > 0)
                        {
                            _nChanges++;
                            if (_nChanges >= _views.AutoCalc)
                            {
                                _nChanges = 0;

                                DialogResult dlgres = MessageBox.Show("Do you wish to calculate scores?", MainForm.AppName, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                if (dlgres == DialogResult.Yes)
                                {
                                    this.CalcScores(this, EventArgs.Empty);
                                }
                            }
                        }
                    }

                    //ClearHighlights();
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }