private StructureDomain ParseDomain(string name, string line, int lineNumber) { StructureDomain result = new StructureDomain(name); this.itemMap.Add(name.ToLower(), result); line = StringUtil.RemoveFirstAndLast(line); string[] aliases = this.PopAliases(ref line, lineNumber); if (aliases != null) { foreach (string alias in aliases) { result.Aliases.Add(alias); this.itemMap.Add(alias.ToLower(), result); } } string[] tokens = line.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string token in tokens) { string[] words = token.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); string key = words[0].Trim().ToLower(); string value = words.Length == 1 ? string.Empty : words[1].Trim(); if (key.Equals("type")) { if (string.IsNullOrEmpty(value)) { throw new Exception(string.Format("You must define a data type at line {0}", lineNumber)); } string typeName = this.PopParenthesis(ref value); result.DataTypeStr = typeName; result.DataType = this.CalculateDataType(typeName, lineNumber); value = value.Trim(); result.DataTypeDecimals = 0; result.DataTypeLength = 0; if (!string.IsNullOrEmpty(value)) { string[] lengths = value.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); result.DataTypeLength = Convert.ToInt32(lengths[0].Trim()); if (lengths.Length > 1) { result.DataTypeDecimals = Convert.ToInt32(lengths[1].Trim()); } } } else if (key.Equals("identity")) { if (string.IsNullOrEmpty(value)) { result.IsIdentity = true; } else { result.IsIdentity = value.ToLower().Equals("true"); } } } return(result); }
public StructureTree Parse() { StructureTree result = new StructureTree(); string[] lines = StringUtil.SplitLines(this.SourceText); for (int i = 0; i < lines.Length; i++) { StructureItem item = this.ParseLine(lines[i], i); if (item != null) { result.AddItem(item); } } // All lines loaded, structure items mapped, let's resolve references foreach (StructureEntity entity in result.Entities) { foreach (StructureProperty property in entity.Properties) { if ((!property.IsTyped) && (!string.IsNullOrEmpty(property.ReferenceName))) { property.ReferenceItem = this.itemMap[property.ReferenceName.ToLower()]; if (property.ReferenceItem is StructureDomain) { StructureDomain domain = property.ReferenceItem as StructureDomain; property.DataTypeStr = domain.DataTypeStr; property.DataType = domain.DataType; property.DataTypeLength = domain.DataTypeLength; property.DataTypeDecimals = domain.DataTypeDecimals; if (domain.IsIdentity) { property.IsIdentity = true; property.IsPrimaryKey = true; property.IsNullable = false; } } else { } } } } return(result); }
private StructureDomain ParseDomain(string name, string line, int lineNumber) { StructureDomain result = new StructureDomain(name); this.itemMap.Add(name.ToLower(), result); line = StringUtil.RemoveFirstAndLast(line); string[] aliases = this.PopAliases(ref line, lineNumber); if (aliases != null) { foreach (string alias in aliases) { result.Aliases.Add(alias); this.itemMap.Add(alias.ToLower(), result); } } string[] tokens = line.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string token in tokens) { string[] words = token.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); string key = words[0].Trim().ToLower(); string value = words.Length == 1 ? string.Empty : words[1].Trim(); if (key.Equals("type")) { if (string.IsNullOrEmpty(value)) { throw new Exception(string.Format("You must define a data type at line {0}", lineNumber)); } string typeName = this.PopParenthesis(ref value); result.DataTypeStr = typeName; result.DataType = this.CalculateDataType(typeName, lineNumber); value = value.Trim(); result.DataTypeDecimals = 0; result.DataTypeLength = 0; if (!string.IsNullOrEmpty(value)) { string[] lengths = value.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); result.DataTypeLength = Convert.ToInt32(lengths[0].Trim()); if (lengths.Length > 1) { result.DataTypeDecimals = Convert.ToInt32(lengths[1].Trim()); } } } else if (key.Equals("identity")) { if (string.IsNullOrEmpty(value)) { result.IsIdentity = true; } else { result.IsIdentity = value.ToLower().Equals("true"); } } } return result; }