private void Init(string aColumnName, string aRegEx, string aTrailingRegex, RegexColumnType aColumnType) { ColumnName = aColumnName; RegEx = aRegEx; TrailingRegEx = aTrailingRegex; ColumnType = aColumnType; }
/// <summary> /// Adds a column to the collection of columns from which /// the regular expression will be created /// </summary> /// <param name="columnName">name of the column</param> /// <param name="columnRegEx">regular expression for capturing the value of this column</param> /// <param name="columnType">RegexColumnType of this column</param> public void AddColumn(string columnName, string columnRegEx, RegexColumnType columnType = RegexColumnType.STRING) { string precedingRegEx = columnName.StartsWith("\"") ? "\"" : String.Empty; string trailingRegEx = columnName.EndsWith("\"") ? "\"" : String.Empty; columnName = columnName.Trim('\"'); AddColumn(columnName, columnRegEx, trailingRegEx, precedingRegEx, columnType); }
public RegexColumn(string columnName, string expression, RegexColumnType columnType = RegexColumnType.STRING) { ColumnName = columnName; Expression = expression; ColumnType = columnType; AutoIncrement = false; IsForeignKey = false; IsUnique = false; }
private void Init(string columnName, string regEx, string trailingRegex, string precedingRegex, RegexColumnType columnType) { ColumnName = columnName; AutoIncrement = false; Expression = String.Empty; RegEx = regEx; TrailingRegEx = trailingRegex; PrecedingRegEx = precedingRegex; ColumnType = columnType; IsForeignKey = false; StartValue = 1; Increment = 1; }
/// <summary> /// Adds a column to the collection of columns from which /// the regular expression will be created /// </summary> /// <param name="columnName">name of the column</param> /// <param name="separator">column separator</param> public void AddColumn(string columnName, char separator, RegexColumnType columnType = RegexColumnType.STRING) { if ((columnName.StartsWith("\"")) && (columnName.EndsWith("\""))) { AddColumn(columnName, "[^\"]*", columnType); } else { if (columnName.Contains(":")) { string columnNameOnly = columnName.Substring(0, columnName.IndexOf(':')); int columnLength = Int16.Parse(columnName.Split(':')[1]); AddColumn(columnNameOnly, columnLength, columnType); } else { AddColumn(columnName, "[^" + RegexFormattedOutput(separator) + "\n]*", columnType); } } Separator = separator.ToString(); }
public void AddColumn(string columnName, RegexColumnType columnType, string expression) { Columns.Add(new RegexColumn(columnName, expression, columnType)); }
/// <summary> /// Constructor /// </summary> /// <param name="columnName">name of the column</param> /// <param name="regEx">regular expression for capturing the value of this column</param> /// <param name="trailingRegex">Trailing regular expression for any data not to be captured for this column</param> /// <param name="precedingRegex">Preceding regular expression for any data not to be captured for this column</param> /// <param name="columnType">Type of this column</param> public RegexColumn(string columnName, string regEx, string trailingRegex, string precedingRegex = "", RegexColumnType columnType = RegexColumnType.STRING) { Init(columnName, regEx, trailingRegex, precedingRegex, columnType); }
/// <summary> /// Adds a column to the collection of columns from which /// the regular expression will be created /// </summary> /// <param name="columnName">name of the column</param> /// <param name="columnRegEx">regular expression for capturing the value of this column</param> /// <param name="trailingRegEx">Trailing regular expression for any data not to be captured for this column</param> /// <param name="precedingRegEx">Preceding regular expression for any data not to be captured for this column</param> /// <param name="columnType">RegexColumnType of this column</param> public void AddColumn(string columnName, string columnRegEx, string trailingRegEx, string precedingRegEx, RegexColumnType columnType = RegexColumnType.STRING) { Columns.Add(new RegexColumn(columnName, columnRegEx, trailingRegEx, precedingRegEx, columnType)); }
/// <summary> /// Adds a column to the collection of columns from which /// the regular expression will be created /// </summary> /// <param name="columnName">name of the column</param> /// <param name="length">amount of characters this column has</param> /// <param name="columnType">RegexColumnType of this column</param> public void AddColumn(string columnName, int length, RegexColumnType columnType = RegexColumnType.STRING) { AddColumn(columnName, ".{" + length + "}", columnType); }
/// <summary> /// Adds a column to the collection of columns from which /// the regular expression will be created /// </summary> /// <param name="aColumnName">name of the column</param> /// <param name="aColumnRegEx">regular expression for capturing the value of this column</param> /// <param name="aColumnType">RegexColumnType of this column</param> public void AddColumn(string aColumnName, string aColumnRegEx, RegexColumnType aColumnType) { AddColumn(aColumnName, aColumnRegEx, string.Empty, aColumnType); }
/// <summary> /// Adds a column to the collection of columns from which /// the regular expression will be created /// </summary> /// <param name="aColumnName">name of the column</param> /// <param name="aLength">amount of characters this column has</param> /// <param name="aColumnType">RegexColumnType of this column</param> public void AddColumn(string aColumnName, int aLength, RegexColumnType aColumnType) { AddColumn(aColumnName, ".{" + aLength.ToString() + "}", string.Empty, aColumnType); }
/// <summary> /// Adds a column to the collection of columns from which /// the regular expression will be created /// </summary> /// <param name="aColumnName">name of the column</param> /// <param name="aSeparator">column separator</param> /// <param name="aColumnType">RegexColumnType of this column</param> public void AddColumn(string aColumnName, char aSeparator, RegexColumnType aColumnType) { AddColumn(aColumnName, string.Format("[^{0}]+", aSeparator), string.Empty, aColumnType); Separator = aSeparator.ToString(); }
/// <summary> /// Constructor /// </summary> /// <param name="aColumnName">name of the column</param> /// <param name="aRegEx">regular expression for capturing the value of this column</param> /// <param name="aTrailingRegex">regular expression for any data not te be captured for this column</param> /// <param name="aColumnType">Type of this column</param> public RegexColumn(string aColumnName, string aRegEx, string aTrailingRegex, RegexColumnType aColumnType) { Init(aColumnName, aRegEx, aTrailingRegex, aColumnType); }
/// <summary> /// Adds a column to the collection of columns from which /// the regular expression will be created /// </summary> /// <param name="aColumnName">name of the column</param> /// <param name="aColumnRegEx">regular expression for capturing the value of this column</param> /// <param name="aTrailingRegEx">regular expression for any data not te be captured for this column</param> /// <param name="aColumnType">RegexColumnType of this column</param> public void AddColumn(string aColumnName, string aColumnRegEx, string aTrailingRegEx, RegexColumnType aColumnType) { Columns.Add(new RegexColumn(aColumnName, aColumnRegEx, aTrailingRegEx, aColumnType)); }
private void ParseColumnOrParser(RegexColumnBuilder columnBuilder, XmlNode childNode, string separator = "") { if (childNode.Name.ToUpper() == "IF") { string strCondition = String.Empty; string strTableName = TableName; string strTableStructureType = String.Empty; //Conditional Table level attributes... foreach (XmlAttribute xAttr in childNode.Attributes) { switch (xAttr.Name.ToUpper()) { case "SEPARATOR": separator = xAttr.Value; break; case "CONDITION": strCondition = xAttr.Value; break; case "TABLENAME": strTableName = xAttr.Value; break; case "TABLESTRUCTURETYPE": strTableStructureType = xAttr.Value; break; } } RegexColumnBuilder conditionalRCB = new RegexColumnBuilder(separator); XmlNode tableNode = childNode; if (!String.IsNullOrWhiteSpace(strTableStructureType)) { tableNode = Configuration.GetDataTableNode(strTableStructureType); } foreach (XmlNode subNode in tableNode.ChildNodes) { ParseColumnOrParser(conditionalRCB, subNode, separator); } ConditionalRegexParser crp = new ConditionalRegexParser() { ConditionRegex = new Regex(strCondition), TableName = strTableName, parseRegex = conditionalRCB.CreateRegularExpression(), RegexColumns = conditionalRCB.Columns }; Parsers.Add(crp); } else { string prefix = ""; string suffix = ""; string strCondition = String.Empty; bool hasDoubleQuotes = false; bool bAutoIncrement = false; Int32 intStartValue = 1; Int32 intIncrement = 1; bool bForeignKey = false; bool bPrimaryKey = false; string strExpression = String.Empty; string strDisplayName = childNode.Name; string strDescription = String.Empty; string strDefault = String.Empty; int columnLength = 0; RegexColumnType rct = RegexColumnType.STRING; //Column level attributes... foreach (XmlAttribute xAttr in childNode.Attributes) { switch (xAttr.Name.ToUpper()) { case "SEPARATOR": separator = xAttr.Value; break; case "PREFIX": prefix = xAttr.Value; break; case "SUFFIX": suffix = xAttr.Value; break; case "QUOTES": hasDoubleQuotes = Boolean.Parse(xAttr.Value); break; case "LENGTH": columnLength = Int16.Parse(xAttr.Value); break; case "TYPE": rct = (RegexColumnType)Enum.Parse(typeof(RegexColumnType), xAttr.Value); break; case "CONDITION": strCondition = xAttr.Value; break; case "AUTOINCREMENT": bAutoIncrement = Boolean.Parse(xAttr.Value); break; case "STARTVALUE": case "START": case "SEED": intStartValue = Int32.Parse(xAttr.Value); break; case "INCREMENT": intIncrement = Int32.Parse(xAttr.Value); break; case "EXPRESSION": strExpression = xAttr.Value; break; case "FOREIGNKEY": bForeignKey = Boolean.Parse(xAttr.Value); break; case "UNIQUE": case "PRIMARYKEY": case "PRIMARY": bPrimaryKey = Boolean.Parse(xAttr.Value); break; case "DISPLAYNAME": case "CAPTION": strDisplayName = xAttr.Value; break; case "DESCRIPTION": strDescription = xAttr.Value; break; case "DEFAULT": strDefault = xAttr.Value; break; } } bool bColumnAdded = false; string strColumnName = childNode.Name; if (strColumnName.Trim('_') == String.Empty) { strColumnName = String.Empty; } if (bAutoIncrement) { columnBuilder.AddColumn(strColumnName, bAutoIncrement, intStartValue, intIncrement); bColumnAdded = true; } if (!bColumnAdded && !String.IsNullOrEmpty(strExpression)) { columnBuilder.AddColumn(strColumnName, rct, strExpression); bColumnAdded = true; } if ((!bColumnAdded) && (bForeignKey)) { columnBuilder.AddColumn(strColumnName, bForeignKey); bColumnAdded = true; } if (!bColumnAdded) //This is a regular column with regex... let us add this to the column builder... { if (!String.IsNullOrEmpty(separator)) { if (hasDoubleQuotes) { columnBuilder.AddColumn('\"' + strColumnName + '\"', separator[0], rct); } else { if (childNode.NextSibling == null) { columnBuilder.AddColumn(strColumnName, ".*", rct); } else { columnBuilder.AddColumn(strColumnName, "[^" + columnBuilder.RegexFormattedOutput(separator[0]) + "\\n]*", prefix, suffix, rct); } } } else { if (columnLength > 0) { columnBuilder.AddColumn(strColumnName, columnLength, rct); } else { columnBuilder.AddColumn(strColumnName, ".*", rct); } } RegexColumn addedColumn = columnBuilder.Columns[columnBuilder.Columns.Count - 1]; if (!String.IsNullOrWhiteSpace(strCondition)) { //There is a condition to be matched with the value... let us set it to the last column added... addedColumn.ValueMatchingCondition = strCondition; } if (bPrimaryKey) { addedColumn.IsUnique = bPrimaryKey; } if (strDisplayName != strColumnName) { addedColumn.DisplayName = strDisplayName; } if (!String.IsNullOrEmpty(strDescription)) { addedColumn.Description = strDescription; } if (!String.IsNullOrEmpty(strDefault)) { addedColumn.Default = strDefault; } } } }