コード例 #1
0
ファイル: TSharkFixups.cs プロジェクト: lizhengda/C5SIGMA
        /// <summary>
        /// Applies fixups to the given item parameters.
        /// </summary>
        /// <param name="parentName">Name of the parent item.</param>
        /// <param name="name">'name' attribute of the item to fixup.</param>
        /// <param name="show">'show' attribute of the item to fixup.</param>
        /// <param name="showname">'showname' attribute of the item to fixup.</param>
        /// <param name="value">'value' attribute of the item to fixup.</param>
        /// <returns>True if a fixup was applied, false otherwise.</returns>
        private bool ApplyTemplateFixups(string parentName, ref string name, ref string show, ref string showname, ref string value)
        {
            if (templateFixups.Count == 0)
            {
                return(false);
            }

            string newName  = null;
            string newValue = null;

            IList <KeyValuePair <string, string> > accumulator = null;

            foreach (TemplateFixup fixup in templateFixups)
            {
                bool matched = true;
                matched &= RegexSupport.CheckMatch(fixup.ParentNameRegex, parentName, ref accumulator);
                matched &= RegexSupport.CheckMatch(fixup.NameRegex, name, ref accumulator);
                matched &= RegexSupport.CheckMatch(fixup.ShowRegex, show, ref accumulator);
                matched &= RegexSupport.CheckMatch(fixup.ShownameRegex, showname, ref accumulator);
                matched &= RegexSupport.CheckMatch(fixup.ValueRegex, value, ref accumulator);

                if (matched)
                {
                    accumulator.Add(new KeyValuePair <string, string>("parentName", parentName));
                    accumulator.Add(new KeyValuePair <string, string>("parentNamePrefix", !string.IsNullOrEmpty(parentName) ? string.Concat(parentName, ".") : string.Empty));
                    accumulator.Add(new KeyValuePair <string, string>("name", name));
                    accumulator.Add(new KeyValuePair <string, string>("show", show));
                    accumulator.Add(new KeyValuePair <string, string>("showname", showname));
                    accumulator.Add(new KeyValuePair <string, string>("value", value));

                    string newNewName  = TemplateValue(fixup.NameFormat, accumulator, true);
                    string newNewValue = TemplateValue(fixup.ValueFormat, accumulator, false);

                    // TODO checking?

                    newName  = newNewName;
                    newValue = newNewValue;
                }

                if (accumulator != null)
                {
                    accumulator.Clear();
                }
            }

            if (newName != null || newValue != null)
            {
                name     = newName;
                showname = newName;
                show     = newValue;
                value    = newValue;
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
ファイル: TSharkFixups.cs プロジェクト: lizhengda/C5SIGMA
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="parentNameRegex">Regex to match against the node's parent's 'name' attribute.</param>
 /// <param name="nameRegex">Regex to match against the node's 'name' attribute.</param>
 /// <param name="showRegex">Regex to match against the node's 'show' attribute.</param>
 /// <param name="shownameRegex">Regex to match against the node's 'showname' attribute.</param>
 /// <param name="valueRegex">Regex to match against the node's 'value' attribute.</param>
 /// <param name="nameFormat">Format string used to generate a new node 'name' attribute.</param>
 /// <param name="valueFormat">Format string used to generate new node 'value' attribute.</param>
 public TemplateFixup(string parentNameRegex, string nameRegex, string showRegex, string shownameRegex, string valueRegex, string nameFormat, string valueFormat)
 {
     this.ParentNameRegex = RegexSupport.GetRegex(parentNameRegex);
     this.NameRegex       = RegexSupport.GetRegex(nameRegex);
     this.ShowRegex       = RegexSupport.GetRegex(showRegex);
     this.ShownameRegex   = RegexSupport.GetRegex(shownameRegex);
     this.ValueRegex      = RegexSupport.GetRegex(valueRegex);
     this.NameFormat      = nameFormat;
     this.ValueFormat     = valueFormat;
 }
コード例 #3
0
ファイル: DataFilter.cs プロジェクト: lizhengda/C5SIGMA
        /// <summary>
        /// Filters a column based on its name and the name of the table containing it.
        /// </summary>
        /// <param name="tableName">Table name to filter.</param>
        /// <param name="columnName">Column name to filter.</param>
        /// <returns>The result of the filtering.</returns>
        public DataFilterType FilterColumn(string tableName, string columnName)
        {
            DataFilterType result = DataFilterType.Unknown;

            foreach (ColumnFilterCommand rule in columnFilter)
            {
                if (RegexSupport.CheckMatch(rule.TableNameRegex, tableName) && RegexSupport.CheckMatch(rule.ColumnNameRegex, columnName))
                {
                    result = rule.Type;
                }
            }
            return(result);
        }
コード例 #4
0
ファイル: DataFilter.cs プロジェクト: lizhengda/C5SIGMA
        /// <summary>
        /// Filters a table based on its name.
        /// </summary>
        /// <param name="tableName">Table name to filter.</param>
        /// <returns>The result of the filtering.</returns>
        public DataFilterType FilterTable(string tableName)
        {
            DataFilterType result = DataFilterType.Unknown;

            foreach (TableFilterRule rule in tableFilter)
            {
                if (RegexSupport.CheckMatch(rule.TableNameRegex, tableName))
                {
                    result = rule.Type;
                }
            }
            return(result);
        }
コード例 #5
0
ファイル: DataFilter.cs プロジェクト: lizhengda/C5SIGMA
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="type">Type of rule.</param>
 /// <param name="tableNameRegex">Regular expression to match against table names.</param>
 /// <param name="columnNameRegex">Regular expression to match against column names.</param>
 public ColumnFilterCommand(DataFilterType type, string tableNameRegex, string columnNameRegex)
 {
     this.Type            = type;
     this.TableNameRegex  = RegexSupport.GetRegex(tableNameRegex);
     this.ColumnNameRegex = RegexSupport.GetRegex(columnNameRegex);
 }
コード例 #6
0
ファイル: DataFilter.cs プロジェクト: lizhengda/C5SIGMA
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="type">Type of rule.</param>
 /// <param name="tableNameRegex">Regular expression to match against table names.</param>
 public TableFilterRule(DataFilterType type, string tableNameRegex)
 {
     this.Type           = type;
     this.TableNameRegex = RegexSupport.GetRegex(tableNameRegex);
 }
コード例 #7
0
        public void TestRegex()
        {
            System.Text.RegularExpressions.Regex regex = null;

            regex = RegexSupport.CreateWildcardsRegex(@"Data\Page\*\Grid?");
            //       Wildcards =          @"Data\Page\*\Grid?"
            bool isMatch11 = regex.IsMatch(@"Data\Page\Panel\Grid1");          // true, jinak chyba:

            if (!isMatch11)
            {
                throw new AssertFailedException("Chyba Regex 11");
            }

            bool isMatch12 = regex.IsMatch(@"Data\Page\Mini\Grid1");           // true, jinak chyba:

            if (!isMatch12)
            {
                throw new AssertFailedException("Chyba Regex 12");
            }

            bool isMatch13 = regex.IsMatch(@"Data\Page\Panel\Grid2");          // true, jinak chyba:

            if (!isMatch13)
            {
                throw new AssertFailedException("Chyba Regex 13");
            }

            bool isMatch14 = regex.IsMatch(@"Data\Pag1\Panel\Grid1");          // false, jinak chyba:

            if (isMatch14)
            {
                throw new AssertFailedException("Chyba Regex 14");
            }

            regex = RegexSupport.CreateWildcardsRegex(@"*\Page\*\G*");
            //       Wildcards =          @"*\Page\*\G*"
            bool isMatch21 = regex.IsMatch(@"Gui\Page\\Gcdef1");               // true, jinak chyba:

            if (!isMatch21)
            {
                throw new AssertFailedException("Chyba Regex 21");
            }

            bool isMatch22 = regex.IsMatch(@"Gui\Page12\Aaa\G12");             // false, jinak chyba:

            if (isMatch22)
            {
                throw new AssertFailedException("Chyba Regex 22");
            }

            bool isMatch23 = regex.IsMatch(@"D\Page\25\Gcdef1");               // true, jinak chyba:

            if (!isMatch23)
            {
                throw new AssertFailedException("Chyba Regex 23");
            }

            bool isMatch24 = regex.IsMatch(@"C\Page\\E21");                    // false, jinak chyba:

            if (isMatch24)
            {
                throw new AssertFailedException("Chyba Regex 24");
            }
        }