/// <summary> /// Adds references for all properties if * name is found. /// </summary> /// <param name="vd"></param> private void ProcessAsteriskName(ParserValidationDelegate vd) { ArrayList asteriskNames = new ArrayList(); foreach (PropertyElement p in propertyReferences) { if (p.Name == "*") { asteriskNames.Add(p); } } if (asteriskNames.Count > 1) { vd(ParserValidationArgs.NewError("More than one name of asterisk(*) was specified for Entity Reference " + this.Name + " in " + this.ReportExtraction.Name + ".")); } if (asteriskNames.Count > 0) { foreach (PropertyElement p in asteriskNames) { propertyReferences.Remove(p); } PropertyElement allReference = (PropertyElement)asteriskNames[0]; if (allReference.GroupFunction != String.Empty && allReference.GroupFunction.ToLower() != PropertyElement.GROUP_FUNCTION_MIN && allReference.GroupFunction.ToLower() != PropertyElement.GROUP_FUNCTION_MAX) { vd(ParserValidationArgs.NewError("The property with name of * may only have group functions of min or max. Error in entity refeence " + this.Name + " in report extraction " + this.ReportExtraction.Name + ".")); } foreach (PropertyElement p in this.Entity.Fields) { bool found = false; foreach (PropertyElement pr in this.PropertyReferences) { if (pr.Name == p.Name) { found = true; break; } } if (!found) { PropertyElement entityReferencePropertyElement = new PropertyElement(); entityReferencePropertyElement.GroupFunction = allReference.GroupFunction; entityReferencePropertyElement.Name = p.Name; entityReferencePropertyElement.AccessModifier = p.AccessModifier; entityReferencePropertyElement.Column = (ColumnElement)(p.Column.Clone()); entityReferencePropertyElement.ConcreteType = p.ConcreteType; entityReferencePropertyElement.ConvertFromSqlTypeFormat = p.ConvertFromSqlTypeFormat; entityReferencePropertyElement.Type = p.Type; this.PropertyReferences.Add(entityReferencePropertyElement); } } } }
/// <summary> /// Validates the filters on the entity reference elements refer to embedded properties correctly. /// </summary> /// <param name="vd">Validation delegate for error reporting.</param> private void ValidateFilters(ParserValidationDelegate vd) { foreach (EntityReferenceElement e in EntityReferences) { e.Filter = Configuration.PrepareExpression(e.Filter, this, "filter for entity reference " + e.Name + " in report extraction " + this.Name, vd); } }
public static Hashtable ParseFromXml(XmlDocument doc, ParserValidationDelegate vd) { Hashtable sqltypes = new Hashtable(); XmlNodeList elements = doc.DocumentElement.GetElementsByTagName("sqltype"); foreach (XmlNode node in elements) { if (node.NodeType == XmlNodeType.Comment) { continue; } SqlTypeElement sqltype = new SqlTypeElement(); sqltype.Name = node.Attributes["name"].Value; sqltype.SqlDbType = sqltype.Name.Substring(0, 1).ToUpper() + sqltype.Name.Substring(1); if (node.Attributes["type"] != null) { sqltype.Type = node.Attributes["type"].Value; } if (node.Attributes["length"] != null) { sqltype.Length = Int32.Parse(node.Attributes["length"].Value); } if (node.Attributes["scale"] != null) { sqltype.Scale = Int32.Parse(node.Attributes["scale"].Value); } if (node.Attributes["precision"] != null) { sqltype.Precision = Int32.Parse(node.Attributes["precision"].Value); } if (node.Attributes["readermethodformat"] != null) { sqltype.ReaderMethodFormat = node.Attributes["readermethodformat"].Value; } if (node.Attributes["sqldbtype"] != null) { sqltype.SqlDbType = node.Attributes["sqldbtype"].Value; } if (node.Attributes["dbtype"] != null) { sqltype.DbType = node.Attributes["dbtype"].Value; } if (node.Attributes["declarationformat"] != null) { sqltype.DeclarationFormat = node.Attributes["declarationformat"].Value; } if (sqltypes.ContainsKey(sqltype.Name)) { vd(ParserValidationArgs.NewWarning("Ignoring duplicate definition of sqltype: " + sqltype.Name)); } else { sqltypes.Add(sqltype.Name, sqltype); } } return(sqltypes); }
public static ArrayList ParseFromXml(Configuration options, XmlNode node, ParserValidationDelegate vd) { ArrayList elements = new ArrayList(); XmlNodeList excludes = node.SelectNodes("excludes/exclude"); foreach (XmlNode exclude in excludes) { if (exclude.NodeType == XmlNodeType.Comment) { continue; } ExcludeElement element = new ExcludeElement(); element.Name = GetAttributeValue(exclude, NAME, element.Name); elements.Add(element); } return(elements); }
public static ArrayList ParseFromXml(Configuration options, XmlNode root, ParserValidationDelegate vd) { ArrayList elements = new ArrayList(); XmlNodeList nodes = root.SelectNodes("parameters/parameter"); foreach (XmlNode node in nodes) { if (node.NodeType == XmlNodeType.Comment) { continue; } ParameterElement element = new ParameterElement(); element.Name = GetAttributeValue(node, NAME, element.Name); element.Value = GetAttributeValue(node, VALUE, element.Value); elements.Add(element); } return(elements); }
public static ArrayList ParseFromXml(Configuration options, XmlNode root, ParserValidationDelegate vd) { ArrayList elements = new ArrayList(); XmlNodeList nodes = root.SelectNodes("tools/tool"); foreach (XmlNode node in nodes) { if (node.NodeType == XmlNodeType.Comment) { continue; } ToolElement element = new ToolElement(); element.Name = GetAttributeValue(node, NAME, element.Name); element.Class = GetAttributeValue(node, CLASS, element.Class); elements.Add(element); } return(elements); }
/// <summary> /// Validates that the expressions for the computed properties refer to embedded properties correctly. /// Also sets up the SQL Alias's /// </summary> /// <param name="vd">Validation delegate for error reporting.</param> private void ValidateExpressions(ParserValidationDelegate vd) { foreach (PropertyElement p in ComputedProperties) { p.Column.Name = p.Name; if (p.Expression == String.Empty) { vd(ParserValidationArgs.NewError("The computed property " + p.Name + " in report extraction " + this.Name + " has no expression.")); } else { p.Expression = Configuration.PrepareExpression(p.Expression, this, "expression for property " + p.Name + " in report extraction " + this.Name, vd); } if (p.Column.SqlType.Name == String.Empty) { vd(ParserValidationArgs.NewError("The computed property " + p.Name + " in report extraction " + this.Name + " has no sql type defined.")); } } }
/// <summary> /// Validates that the report extraction does not cross database boundaries. /// </summary> /// <param name="vd">Validation delegate for error reporting.</param> private void ValidateDatabases(ParserValidationDelegate vd) { string firstKey = String.Empty; foreach (EntityReferenceElement e in EntityReferences) { if (e.Entity.SqlEntity.Name != String.Empty) { if (firstKey == String.Empty) { firstKey = e.Entity.SqlEntity.Key; } else if (e.Entity.SqlEntity.Name != String.Empty && e.Entity.SqlEntity.Key != firstKey) { vd(ParserValidationArgs.NewError("All entity references in the report extraction" + this.Name + " must refer to entities whose sql entities all have the same key.")); break; } } } }
public static ArrayList ParseFromXml(Configuration options, XmlNode root, ParserValidationDelegate vd) { ArrayList list = new ArrayList(); foreach (XmlNode node in root.ChildNodes) { if (node.Name.Equals("argument")) { ArgumentElement arg = new ArgumentElement(); arg.Name = node.Attributes["name"].Value; arg.Value = node.Attributes["value"].Value; if (!node.InnerText.Equals(String.Empty)) { arg.Description = node.InnerText; } list.Add(arg); } } return(list); }
public static ArrayList ParseFromXml(Configuration options, XmlNode root, ParserValidationDelegate vd) { ArrayList list = new ArrayList(); XmlNodeList nodes = root.SelectNodes("tasks/task"); foreach (XmlNode node in nodes) { if (node.NodeType == XmlNodeType.Comment) { continue; } TaskElement task = new TaskElement(); task.Name = node.Attributes["name"].Value; task.Element = node.Attributes["element"].Value; task.Template = node.Attributes["template"].Value; task.Directory = node.Attributes["directory"].Value; task.FileNameFormat = node.Attributes["filenameformat"].Value; if (node.Attributes[BACKUP_DIRECTORY] != null) { task.BackupDirectory = node.Attributes["backupdirectory"].Value; } else { task.BackupDirectory = task.Directory; } if (!node.InnerText.Equals(String.Empty)) { task.Description = node.InnerText; } task.Includes = IncludeElement.ParseFromXml(options, node, vd); task.Excludes = ExcludeElement.ParseFromXml(options, node, vd); task.Parameters = ParameterElement.ParseFromXml(options, node, vd); task.Writer = GetAttributeValue(node, WRITER, task.Writer); task.Styler = GetAttributeValue(node, STYLER, task.Styler); TypeElement.ParseFromXml(node, task.Types); list.Add(task); } return(list); }
private void CreateEntityElementAssociations(ParserValidationDelegate vd) { foreach (EntityElement entity in entities) { //Fields which are entities. foreach (PropertyElement property in entity.Fields) { if (property.Entity.Name.Length > 0) { EntityElement e = EntityElement.FindEntityByName(entities, property.Entity.Name); if (e != null) { property.Entity = e; } else { vd(ParserValidationArgs.NewError("Property (" + property.Name + ") specifies an entity " + property.Entity.Name + " that could not be found as an defined entity")); } } } //Dependant entities. ArrayList dependents = new ArrayList(); foreach (EntityElement dependent in entity.Dependents) { EntityElement e = EntityElement.FindEntityByName(entities, dependent.Name); if (e != null) { dependents.Add(e); } else { vd(ParserValidationArgs.NewError("Entity (" + entity.Name + ") specifies a dependent entity " + dependent.Name + " that could not be found as an defined entity")); } } entity.Dependents = dependents; } }
private void CreateSqlElementAssociations(ParserValidationDelegate vd) { // find and assign the foreign entity and EnumElement now that they are parsed foreach (DatabaseElement database in databases) { foreach (SqlEntityElement sqlEntity in database.SqlEntities) { foreach (ConstraintElement constraint in sqlEntity.Constraints) { if (constraint.ForeignEntity.Name.Length > 0) { SqlEntityElement entity = SqlEntityElement.FindByName(DatabaseElement.GetAllSqlEntities(databases), constraint.ForeignEntity.Name); if (entity != null) { constraint.ForeignEntity = (SqlEntityElement)entity.Clone(); } else { vd(ParserValidationArgs.NewError("ForeignEntity (" + constraint.ForeignEntity.Name + ") specified in constraint " + constraint.Name + " could not be found as an defined entity")); } } if (constraint.CheckEnum.Name.Length > 0) { EnumElement entity = EnumElement.FindByName(enumtypes as ArrayList, constraint.CheckEnum.Name); if (entity != null) { constraint.CheckEnum = (EnumElement)entity.Clone(); } else { vd(ParserValidationArgs.NewError("CheckEnum (" + constraint.CheckEnum.Name + ") specified in constraint " + constraint.Name + " could not be found as an defined entity")); } } } } } }
private static ArrayList ParseDependentsFromXml(XmlNode node, ParserValidationDelegate vd) { ArrayList returnList = new ArrayList(); XmlNode dependentsNode = node.ChildNodes.Cast <XmlNode>() .FirstOrDefault(x => x.Name.ToLowerInvariant() == "dependents"); if (dependentsNode != null) { IEnumerable <string> children = from x in dependentsNode.ChildNodes.Cast <XmlNode>() where x.Name.ToLowerInvariant() == "entity" select x.Attributes["name"].Value; foreach (string name in children) { EntityElement element = new EntityElement { Name = name }; returnList.Add(element); } } return(returnList); }
public static ArrayList ParseFromXml(XmlNode root, IList entities, IPropertyContainer container, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd) { ArrayList comparers = new ArrayList(); XmlNode comparerNode = GetChildNodeByName(root, COMPARERS); if (comparerNode != null) { foreach (XmlNode node in comparerNode.ChildNodes) { if (node.NodeType == XmlNodeType.Comment) { continue; } ComparerElement comparer = new ComparerElement(); if (node.Attributes["name"] == null) { vd(ParserValidationArgs.NewError("ComparerElement in " + container.Name + " has no name attribute.")); continue; } comparer.Name = node.Attributes["name"].Value; comparer.Fields = PropertyElement.ParseFromXml(GetChildNodeByName(node, PROPERTIES), new ArrayList(), container, sqltypes, types, true, vd); comparers.Add(comparer); } } return(comparers); }
/// <summary> /// Second pass parsing and validation. /// </summary> /// <param name="options">Configuration options</param> /// <param name="reportExtractionNode">Node contaiing the entity references.</param> /// <param name="reportExtraction">ReportExtraction element to contain the parsed entity references.</param> /// <param name="types">List of .Net types defined.</param> /// <param name="entities">List of entities defined.</param> /// <param name="vd">Validation delegate for error reporting.</param> /// <returns>List of entity references parsed.</returns> public static ArrayList ParseFromXml(Configuration options, XmlNode reportExtractionNode, ReportExtractionElement reportExtraction, Hashtable types, Hashtable sqltypes, IList entities, ParserValidationDelegate vd) { ArrayList entityReferences = new ArrayList(); foreach (XmlNode node in reportExtractionNode.ChildNodes) { if (node.NodeType == XmlNodeType.Comment) { continue; } EntityReferenceElement entityReference = new EntityReferenceElement(reportExtraction); if (entityReference.Name != null) { entityReference.Name = node.Attributes[NAME].Value; } else { vd(ParserValidationArgs.NewError("Entity reference specified in report extraction " + reportExtraction.Name + " with no name.")); } if (node.Attributes[ENTITY] != null) { EntityElement ee = EntityElement.FindEntityByName(entities, node.Attributes[ENTITY].Value); if (ee != null) { entityReference.Entity = ee; if (entityReference.Entity.SqlEntity.Name == String.Empty) { vd(ParserValidationArgs.NewError("Entity Reference " + entityReference.Name + " refers to entity " + node.Attributes[ENTITY].Value + " which does not have an associated SQL entity.")); } } else { vd(ParserValidationArgs.NewError("Entity Reference " + entityReference.Name + " refers to entity " + node.Attributes[ENTITY].Value + " which does not exist.")); } } else { vd(ParserValidationArgs.NewError("Entity Reference " + node.Attributes[NAME].Value + " has no entity attribute.")); } if (node.Attributes[ALIAS_PREFIX] != null) { entityReference.aliasPrefix = node.Attributes[ALIAS_PREFIX].Value; } if (node.Attributes[HINTS] != null) { entityReference.Hints = node.Attributes[HINTS].Value; } if (node.Attributes[FILTER] != null) { entityReference.Filter = node.Attributes[FILTER].Value; } if (node.Attributes[JOIN_MODIFIER] != null) { entityReference.JoinModifier = node.Attributes[JOIN_MODIFIER].Value; if (entityReference.JoinModifier.ToUpper() != JOIN_LEFT && entityReference.JoinModifier.ToUpper() != JOIN_RIGHT && entityReference.JoinModifier.ToUpper() != JOIN_FULL) { vd(ParserValidationArgs.NewError("Entity Reference " + node.Attributes[NAME].Value + " has join modifier other than left, right or full.")); } } entityReference.ReportExtraction = reportExtraction; // Note we pass entityReference.Entity because the fields refer to fields in the entity. entityReference.propertyReferences = PropertyElement.ParseFromXml(GetChildNodeByName(node, PROPERTY_REFERENCES), entities, entityReference.Entity, sqltypes, types, true, vd); entityReference.ProcessAsteriskName(vd); entityReference.AdjustSqlAlias(); entityReferences.Add(entityReference); } return(entityReferences); }
public static ArrayList ParseFromXml(String name, Configuration options, XmlDocument doc, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd) { ArrayList values = new ArrayList(); XmlNodeList elements = doc.DocumentElement.GetElementsByTagName("enum"); foreach (XmlNode element in elements) { if (element.Attributes["name"].Value.Equals(name) && element.HasChildNodes) { foreach (XmlNode node in element.ChildNodes) { if (node.Name.Equals("value")) { EnumValueElement value = new EnumValueElement(); if (node.Attributes["name"] == null || node.Attributes["code"] == null) { throw new ApplicationException("Enum " + name + " must have name and code properties for each value element"); } value.Name = node.Attributes["name"].Value; value.Code = node.Attributes["code"].Value; if (!node.InnerText.Equals(String.Empty)) { value.Description = node.InnerText; } values.Add(value); } } } } return(values); }
/// <summary> /// Parses for real on second pass. /// </summary> /// <param name="options">Configuration class with optinos</param> /// <param name="doc">Document being parsed.</param> /// <param name="sqltypes">List of sql types defined</param> /// <param name="types">List of .Net types defined</param> /// <param name="vd">Validation delegate for error reporting</param> /// <param name="collectableClasses">List of classes that are valid to have collections created.</param> /// <param name="autoGenerateClasses">List of classes that should have collections generated if generateall is specified.</param> /// <returns>List of collection elements created</returns> public static ArrayList ParseFromXml(Configuration options, XmlDocument doc, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd, IList collectableClasses, IList autoGenerateClasses, ArrayList entities) { // see if we want to generate collections for all classes. XmlNodeList collectionElement = doc.DocumentElement.GetElementsByTagName("collections"); XmlNode collectionNode = collectionElement[0]; Boolean generateAll = false; if (collectionNode.Attributes["generateall"] != null) { generateAll = Boolean.Parse(collectionNode.Attributes["generateall"].Value.ToString()); } // Add all collectable classses if chosen. ArrayList list = new ArrayList(); if (generateAll) { foreach (ICollectable collectableClass in autoGenerateClasses) { CollectionElement collection = new CollectionElement(); collection.Name = collectableClass.Name + "List"; collection.Type.Name = collectableClass.Name + "Data"; collection.Description = "Auto-generated collection for " + collectableClass.Name + "Data type."; collection.CollectedClass = collectableClass; list.Add(collection); } } // Now add explicitly mentioned elements. Note we add explicit elements // as well as we might have lists of enums here. XmlNodeList elements = doc.DocumentElement.GetElementsByTagName("collection"); foreach (XmlNode node in elements) { if (node.NodeType == XmlNodeType.Comment) { continue; } CollectionElement collection = new CollectionElement(); collection.Name = node.Attributes["name"].Value; collection.Type.Name = node.Attributes["type"].Value; if (node.Attributes["template"] != null) { collection.Template = node.Attributes["template"].Value; } // TODO: this is a hack - need to specify entity as an attribute so that "Data" does not have to be assumed // and so that an error can be reported if it does not exist foreach (ICollectable collectableClass in collectableClasses) { if (collection.Type.Name.Equals(collectableClass.Name + "Data")) { collection.CollectedClass = collectableClass; } } // TODO: how can this be modified for "reportexcations" foreach (EntityElement entity in entities) { if (collection.Type.Name.Equals(entity.Name + "Data")) { collection.Entity = entity; } } collection.Description = node.InnerText; list.Add(collection); } return(list); }
public static ArrayList ParseFromXml(XmlNode propertiesNode, IList entities, IPropertyContainer entity, Hashtable sqltypes, Hashtable types, bool isReference, ParserValidationDelegate vd) { ArrayList fields = new ArrayList(); if (propertiesNode != null) { foreach (XmlNode node in propertiesNode.ChildNodes) { if (node.NodeType == XmlNodeType.Comment) { continue; } PropertyElement field = BuildElement(node, types, sqltypes, entity, isReference, vd); //Adds all attributes including all non defined by element class foreach (XmlAttribute attribute in node.Attributes) { if (!field.Attributes.ContainsKey(attribute.Name)) { field.Attributes.Add(attribute.Name, attribute.Value); } } fields.Add(field); // Add in any subfields... if (field.Entity.Name.Length > 0 && !field.UseEntityDao) { String subEntityName = node.Attributes["entity"].Value; EntityElement subentity = EntityElement.FindEntityByName((ArrayList)entities, subEntityName); // check to see if subentity is self if (subentity == null && entity.Name == subEntityName) { subentity = (EntityElement)entity; } if (subentity != null) { // Only entity elements have entity atttribute SqlEntityElement sqlEntity = ((EntityElement)entity).SqlEntity; String prefix = subentity.Name + "_"; if (node.Attributes["prefix"] != null) { prefix = node.Attributes["prefix"].Value; } foreach (PropertyElement f in subentity.Fields) { PropertyElement subfield = (PropertyElement)f.Clone(); subfield.Name = field.Name + "." + subfield.Name; // if field has sql column defined if (!f.Column.Name.Equals(String.Empty)) { ColumnElement column = sqlEntity.FindColumnByName(prefix + subfield.Column.Name); if (column != null) { subfield.Column = (ColumnElement)column.Clone(); } else { vd(ParserValidationArgs.NewError("column (" + prefix + subfield.Column.Name + ") specified for property (" + subfield.Name + ") on entity (" + entity.Name + ") was not found in sql entity (" + sqlEntity.Name + ")")); } } fields.Add(subfield); } } else { vd(ParserValidationArgs.NewError("Entity " + entity.Name + " referenced another entity that was not defined (or defined below this one): " + node.Attributes["entity"].Value)); } } } } return(fields); }
public static PropertyElement BuildElement(XmlNode node, Hashtable types, Hashtable sqltypes, IPropertyContainer entity, bool isReference, ParserValidationDelegate vd) { PropertyElement field = new PropertyElement(); if (node.Attributes["name"] != null) { field.Name = node.Attributes["name"].Value; } else { vd(ParserValidationArgs.NewError("Property in " + entity.Name + " has no name.")); } if (isReference && field.Name != "*") { PropertyElement refProperty = entity.FindFieldByName(field.Name); if (refProperty == null) { vd(ParserValidationArgs.NewError("Property " + field.Name + " in " + entity.Name + " refers to a property that does not exist.")); } else { field = (PropertyElement)(refProperty.Clone()); } } if (node.Attributes["column"] != null) { if (node.Attributes["column"].Value.Equals("*")) { field.Column.Name = field.Name; } else { field.Column.Name = node.Attributes["column"].Value; } // Column only occurs on entity eement. SqlEntityElement sqlEntity = ((EntityElement)entity).SqlEntity; ColumnElement column = sqlEntity.FindColumnByName(field.Column.Name); if (column != null) { field.Column = (ColumnElement)column.Clone(); if (types.Contains(field.Column.SqlType.Type)) { field.Type = (TypeElement)((TypeElement)types[field.Column.SqlType.Type]).Clone(); } else { vd(ParserValidationArgs.NewError("Type " + field.Column.SqlType.Type + " was not defined [property=" + field.name + "]")); } } else { vd(ParserValidationArgs.NewError("column (" + field.Column.Name + ") specified for property (" + field.Name + ") on entity (" + entity.Name + ") was not found in sql entity (" + sqlEntity.Name + ")")); } } field.Description = node.InnerText.Trim(); if (node.Attributes["accessmodifier"] != null) { field.AccessModifier = node.Attributes["accessmodifier"].Value; } // the concrete type is the *real* type, type can be the same or can be in interface or coersable type if (node.Attributes["type"] != null) { String type = node.Attributes[TYPE].Value; String concreteType = type; if (node.Attributes[CONCRETE_TYPE] != null) { concreteType = node.Attributes[CONCRETE_TYPE].Value; } // if the data type is defined, default it as the property and left be overridden if (types.Contains(concreteType)) { field.Type = (TypeElement)((TypeElement)types[concreteType]).Clone(); field.Type.Name = type; } else { vd(ParserValidationArgs.NewError("Type " + concreteType + " was not defined for property " + field.Name + " in " + entity.Name + ".")); } String dataObjectTypeName = concreteType + "Data"; if (types.Contains(dataObjectTypeName)) { field.DataObjectType = (TypeElement)((TypeElement)types[dataObjectTypeName]).Clone(); } else { field.DataObjectType = field.Type; } } if (node.Attributes["convertfromsqltypeformat"] != null) { field.Type.ConvertFromSqlTypeFormat = node.Attributes["convertfromsqltypeformat"].Value; } if (node.Attributes["converttosqltypeformat"] != null) { field.Type.ConvertToSqlTypeFormat = node.Attributes["converttosqltypeformat"].Value; } if (node.Attributes[PARAMETER_NAME] != null) { field.ParameterName = node.Attributes[PARAMETER_NAME].Value; } if (node.Attributes[EXPRESSION] != null) { field.Expression = node.Attributes[EXPRESSION].Value; } if (node.Attributes[GROUP_FUNCTION] != null) { field.GroupFunction = node.Attributes[GROUP_FUNCTION].Value; if (field.GroupFunction.ToLower() != GROUP_FUNCTION_SUM && field.GroupFunction.ToLower() != GROUP_FUNCTION_MIN && field.GroupFunction.ToLower() != GROUP_FUNCTION_MAX && field.GroupFunction.ToLower() != GROUP_FUNCTION_AVG && field.GroupFunction.ToLower() != GROUP_FUNCTION_STDEV && field.GroupFunction.ToLower() != GROUP_FUNCTION_STDEVP && field.GroupFunction.ToLower() != GROUP_FUNCTION_VAR && field.GroupFunction.ToLower() != GROUP_FUNCTION_VARP) { vd(ParserValidationArgs.NewError("Invalid group function specified for entity reference property " + field.Name + " in " + entity.Name)); } } if (node.Attributes[GROUP_BY] != null) { field.GroupBy = Boolean.Parse(node.Attributes[GROUP_BY].Value); } if (node.Attributes[SQL_TYPE] != null) { field.Column.SqlType.Name = node.Attributes[SQL_TYPE].Value; if (sqltypes.ContainsKey(field.Column.SqlType.Name)) { field.Column.SqlType = (SqlTypeElement)((SqlTypeElement)sqltypes[field.Column.SqlType.Name]).Clone(); } else { vd(ParserValidationArgs.NewError("SqlType " + field.Column.SqlType.Name + " was not defined in " + entity.Name + " for property " + field.Name + ".")); } } if (node.Attributes[ALIAS] != null) { field.Alias = node.Attributes[ALIAS].Value; } field.container = entity; if (node.Attributes["readable"] != null) { field.Readable = Boolean.Parse(node.Attributes["readable"].Value); } if (node.Attributes["writable"] != null) { field.Writable = Boolean.Parse(node.Attributes["writable"].Value); } if (node.Attributes["derived"] != null) { field.Derived = Boolean.Parse(node.Attributes["derived"].Value); } if (node.Attributes["encrypted"] != null) { field.Encrypted = Boolean.Parse(node.Attributes["encrypted"].Value); } if (node.Attributes["log"] != null) { field.DoLog = Boolean.Parse(node.Attributes["log"].Value); } if (node.Attributes["returnasidentity"] != null) { field.ReturnAsIdentity = Boolean.Parse(node.Attributes["returnasidentity"].Value); } if (node.Attributes[DIRECTION] == null) { field.Direction = ASCENDING; } else if (node.Attributes["direction"].Value != ASCENDING && node.Attributes["direction"].Value != DESCENDING) { vd(ParserValidationArgs.NewError("Comparer in entity " + entity.Name + " has direction value other than 'ascending' or 'descending'")); } else { field.Direction = node.Attributes[DIRECTION].Value; } if (node.Attributes[CONVERT_FOR_COMPARE] != null) { field.Type.ConvertForCompare = node.Attributes[CONVERT_FOR_COMPARE].Value; } if (node.Attributes[USE_ENTITY_DAO] != null) { field.UseEntityDao = Boolean.Parse(node.Attributes[USE_ENTITY_DAO].Value); } if (node.Attributes["entity"] != null) { field.Entity.Name = node.Attributes["entity"].Value; } if (node.Attributes["prefix"] != null) { field.Prefix = node.Attributes["prefix"].Value; } else { field.Prefix = field.Entity.Name + "_"; } return(field); }
public static ArrayList ParseFromXml(XmlDocument doc, IList entities, EntityElement entity, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd) { return(ParseFromXml(doc, entities, entity, sqltypes, types, false, vd)); }
public static ArrayList ParseFromXml(XmlDocument doc, IList entities, EntityElement entity, Hashtable sqltypes, Hashtable types, bool isReference, ParserValidationDelegate vd) { XmlNodeList elements = doc.DocumentElement.GetElementsByTagName("entity"); foreach (XmlNode element in elements) { String name = element.Attributes["name"].Value; String sqlEntity = (element.Attributes["sqlentity"] == null) ? String.Empty : element.Attributes["sqlentity"].Value; // if ((sqlEntity.Equals(entity.SqlEntity.Name) || (entity.SqlEntity.Name.Length == 0 && name == entity.Name)) && element.HasChildNodes) { if (name.Equals(entity.Name) && element.HasChildNodes) { // look for a properties element, if one does not exist, assume that everything under the entity is a property (for backward compatablility) XmlNode propertiesNode = element; Boolean hasProperties = false; foreach (XmlNode node in element.ChildNodes) { if (node.Name.Equals("properties")) { propertiesNode = node; hasProperties = true; } } if (!hasProperties) { vd(ParserValidationArgs.NewError("<property> elements on entity (" + entity.Name + ") should be defined within a <properties> element.")); } return(ParseFromXml(propertiesNode, entities, entity, sqltypes, types, isReference, vd)); } } return(new ArrayList()); }
public static ArrayList ParseFromXml(Configuration options, XmlDocument doc, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd) { DatabaseElement defaults = new DatabaseElement(); XmlNodeList elements = doc.DocumentElement.GetElementsByTagName("databases"); if (elements.Count < 1) { vd(ParserValidationArgs.NewError("No databases tags found. You must have at least one databases tag.")); } else { SqlEntityElement.ParseNodeAttributes(elements[0], defaults); } // loop through each 'database' tag in the xml file (ex: file=dtg-databases.xml) ArrayList list = new ArrayList(); elements = doc.DocumentElement.GetElementsByTagName("database"); foreach (XmlNode node in elements) { if (node.NodeType == XmlNodeType.Comment) { continue; } DatabaseElement database = new DatabaseElement(defaults); SqlEntityElement.ParseNodeAttributes(node, database); if (node.Attributes["key"] != null) { database.Key = node.Attributes["key"].Value; } database.SqlEntities = SqlEntityElement.ParseFromXml(database, GetSqlEntitiesNode(node), sqltypes, types, vd); list.Add(database); } return(list); }
public static ArrayList ParseFromXml(XmlNode root, SqlEntityElement sqlentity, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd) { ArrayList columns = new ArrayList(); XmlNodeList elements = null; foreach (XmlNode n in root.ChildNodes) { if (n.Name.Equals("columns")) { elements = n.ChildNodes; break; } } if (elements != null) { foreach (XmlNode node in elements) { if (node.NodeType == XmlNodeType.Comment) { continue; } if (node.Name.Equals("column")) { ColumnElement column = new ColumnElement(); column.Name = GetAttributeValue(node, NAME, String.Empty); if (column.Name.Equals(String.Empty)) { vd(ParserValidationArgs.NewError("SqlEntity " + sqlentity.Name + " has a column that a name was not specified or was blank")); } column.Description = node.InnerText.Trim(); if (node.Attributes["sqltype"] != null) { column.SqlType.Name = node.Attributes["sqltype"].Value; if (sqltypes.ContainsKey(column.SqlType.Name)) { column.SqlType = (SqlTypeElement)((SqlTypeElement)sqltypes[column.SqlType.Name]).Clone(); } else { vd(ParserValidationArgs.NewError("SqlType " + column.SqlType.Name + " was not defined [column=" + sqlentity.Name + "." + column.Name + "]")); } } if (node.Attributes["required"] != null) { column.Required = Boolean.Parse(node.Attributes["required"].Value); } if (node.Attributes["identity"] != null) { column.Identity = Boolean.Parse(node.Attributes["identity"].Value); } if (node.Attributes["rowguidcol"] != null) { column.RowGuidCol = Boolean.Parse(node.Attributes["rowguidcol"].Value); } if (node.Attributes["viewcolumn"] != null) { column.ViewColumn = Boolean.Parse(node.Attributes["viewcolumn"].Value); } if (node.Attributes["increment"] != null) { column.Increment = Int32.Parse(node.Attributes["increment"].Value); } if (node.Attributes["seed"] != null) { column.Seed = Int32.Parse(node.Attributes["seed"].Value); } if (node.Attributes["default"] != null) { column.Default = node.Attributes["default"].Value; } if (node.Attributes["formula"] != null) { column.Formula = node.Attributes["formula"].Value; } if (node.Attributes["length"] != null) { column.SqlType.Length = Int32.Parse(node.Attributes["length"].Value); } if (node.Attributes["scale"] != null) { column.SqlType.Scale = Int32.Parse(node.Attributes["scale"].Value); } if (node.Attributes["precision"] != null) { column.SqlType.Precision = Int32.Parse(node.Attributes["precision"].Value); } if (node.Attributes["expression"] != null) { column.Expression = node.Attributes["expression"].Value; } if (node.Attributes["obsolete"] != null) { column.Obsolete = Boolean.Parse(node.Attributes[OBSOLETE].Value); } if (node.Attributes["retainnonnullvalue"] != null) { column.RetainNonNullValue = Boolean.Parse(node.Attributes["retainnonnullvalue"].Value); } if (node.Attributes[COLLATE] != null) { column.Collate = node.Attributes[COLLATE].Value; } //Adds all attributes including all non defined by element class foreach (XmlAttribute attribute in node.Attributes) { if (!column.Attributes.ContainsKey(attribute.Name)) { column.Attributes.Add(attribute.Name, attribute.Value); } } column.Description = node.InnerText.Trim(); columns.Add(column); } } } return(columns); }
public static ArrayList ParseFromXml(XmlNode root, IList entities, IPropertyContainer entity, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd) { ArrayList finders = new ArrayList(); XmlNodeList elements = null; foreach (XmlNode n in root.ChildNodes) { if (n.Name.Equals("finders")) { elements = n.ChildNodes; break; } } if (elements != null) { foreach (XmlNode node in elements) { if (node.NodeType == XmlNodeType.Comment) { continue; } ReportExtractionFinderElement finder = new ReportExtractionFinderElement(); finder.Name = node.Attributes["name"].Value; finder.Fields = PropertyElement.ParseFromXml(GetChildNodeByName(node, PROPERTIES), entities, entity, sqltypes, types, true, vd); BuildElement(node, entity, finder, vd); finders.Add(finder); } } return(finders); }
public void Parse(String filename) { FileInfo file = new FileInfo(filename); if (!file.Exists) { throw new FileNotFoundException("Could not load config file", filename); } isValid = true; ValidateSchema(filename); doc = new XmlDocument(); Stream filestream = XIncludeReader.GetStream(filename); doc.Load(filestream); filestream.Close(); if (doc == null) { throw new InvalidOperationException("Could not parse xml document: " + filename); } // event handler for all of the ParseFromXml methods ParserValidationDelegate vd = new ParserValidationDelegate(ParserValidationEventHandler); XmlNode root = doc.DocumentElement["config"]; if (root != null) { this.options = new Configuration(root, vd); } else { this.options = new Configuration(); } sqltypes = SqlTypeElement.ParseFromXml(doc, vd); types = TypeElement.ParseFromXml(options, doc, vd); // parse generate/task information so that type registration will happen before other types are loaded generator = GeneratorElement.ParseFromXml(options, doc, vd); TaskElement.RegisterTypes(doc, options, generator.Tasks, types); // see if we want to generate collections for all entities XmlNodeList collectionElement = doc.DocumentElement.GetElementsByTagName("collections"); XmlNode collectionNode = collectionElement[0]; if (collectionNode.Attributes["generateall"] == null) { options.GenerateAllCollections = false; } else { options.GenerateAllCollections = Boolean.Parse(collectionNode.Attributes["generateall"].Value.ToString()); } // if the root directory is not specified, make it the directory the config file is loaded from if (options.RootDirectory.Equals(String.Empty)) { options.RootDirectory = file.DirectoryName + "\\"; } if (!options.RootDirectory.EndsWith("\\")) { options.RootDirectory += "\\"; } enumtypes = EnumElement.ParseFromXml(options, doc, sqltypes, types, vd); databases = DatabaseElement.ParseFromXml(options, doc, sqltypes, types, vd); entities = EntityElement.ParseFromXml(options, doc, sqltypes, types, DatabaseElement.GetAllSqlEntities(databases), vd); messages = MessageElement.ParseFromXml(options, doc, sqltypes, types, DatabaseElement.GetAllSqlEntities(databases), vd); reportExtractions = ReportExtractionElement.ParseFromXml(options, doc, sqltypes, types, entities, vd); ArrayList collectableClasses = new ArrayList(); ArrayList autoGenerateClasses = new ArrayList(); collectableClasses.AddRange(entities); collectableClasses.AddRange(reportExtractions); autoGenerateClasses.AddRange(entities); autoGenerateClasses.AddRange(reportExtractions); collections = CollectionElement.ParseFromXml(options, doc, sqltypes, types, vd, collectableClasses, autoGenerateClasses, (ArrayList)entities); CreateSqlElementAssociations(vd); CreateEntityElementAssociations(vd); Validate(vd); }
public static string PrepareExpression(string withEmbedded, IExpressionContainer container, string idString, ParserValidationDelegate vd) { string checkExpression = withEmbedded; string retVal = String.Empty; int leftBrace = 0; int startPos = 0; for (leftBrace = checkExpression.IndexOf("{", startPos); startPos >= 0; leftBrace = checkExpression.IndexOf("{", startPos)) { if (leftBrace == -1) { // No more strings to replace. retVal += checkExpression.Substring(startPos, checkExpression.Length - startPos); break; } else { // Concatenate portion of string without embedded references. retVal += checkExpression.Substring(startPos, leftBrace - startPos); } int rightBrace = checkExpression.IndexOf("}", leftBrace); if (rightBrace == -1) { if (vd != null) { vd(ParserValidationArgs.NewError("The " + idString + " has a left brace({} with no corresonding right brace(}}")); } return(""); } // Isolate the property reference and concatenate it's expansion. string expressionReference = checkExpression.Substring(leftBrace + 1, rightBrace - leftBrace - 1); retVal += container.GetExpressionSubstitution(expressionReference, idString, vd); // On to the next reference. startPos = rightBrace + 1; } return(retVal); }
public Configuration(XmlNode root, ParserValidationDelegate vd) { if (root.HasChildNodes) { for (Int32 i = 0; i < root.ChildNodes.Count; i++) { XmlNode node = root.ChildNodes[i]; if (node.Name.Equals("setting")) { switch (node.Attributes["name"].Value.ToLower()) { case "rootnamespace": this.rootNameSpace = node.Attributes["value"].Value; break; case "rootdirectory": this.rootDirectory = node.Attributes["value"].Value; break; case "typesclassdirectory": this.typesClassDirectory = node.Attributes["value"].Value; break; case "daoclassdirectory": this.daoClassDirectory = node.Attributes["value"].Value; break; case "doclassdirectory": this.doClassDirectory = node.Attributes["value"].Value; break; case "collectionclassdirectory": this.collectionClassDirectory = node.Attributes["value"].Value; break; case "generatedataobjectclasses": this.generateDataObjectClasses = Boolean.Parse(node.Attributes["value"].Value); break; case "dataobjectbaseclass": this.dataObjectBaseClass = node.Attributes["value"].Value; break; case "daobaseclass": this.daoBaseClass = node.Attributes["value"].Value; break; case "enumbaseclass": this.enumBaseClass = node.Attributes["value"].Value; break; case "testclassdirectory": this.testClassDirectory = node.Attributes["value"].Value; break; default: vd(ParserValidationArgs.NewWarning("Unrecognized configuration option: " + node.Attributes["name"].Value + " = " + node.Attributes["value"].Value)); break; } } } } }
public static ArrayList ParseFromXml(DatabaseElement database, XmlNode databaseNode, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd) { ArrayList sqlentities = new ArrayList(); //databaseNode.ChildNodes corresponds to each <sqlentity> entry in the databases xml file(s) (such as dtg-databases.xml) foreach (XmlNode node in databaseNode.ChildNodes) { if (node.Name.Equals("sqlentity")) { SqlEntityElement sqlentity = new SqlEntityElement(database); ParseNodeAttributes(node, sqlentity); sqlentity.View = "vw" + sqlentity.Name; if (node.Attributes["view"] != null) { sqlentity.View = node.Attributes["view"].Value; } if (node.Attributes["audit"] != null) { sqlentity.Audit = Boolean.Parse(node.Attributes["audit"].Value); } //Adds all attributes including all not defined by element class foreach (XmlAttribute attribute in node.Attributes) { if (!sqlentity.Attributes.ContainsKey(attribute.Name)) { sqlentity.Attributes.Add(attribute.Name, attribute.Value); } } sqlentity.Columns = ColumnElement.ParseFromXml(node, sqlentity, sqltypes, types, vd); sqlentity.Constraints = ConstraintElement.ParseFromXml(node, sqlentity, sqltypes, types, vd); sqlentity.Indexes = IndexElement.ParseFromXml(node, sqlentity, sqltypes, types, vd); // TODO: this is a hack as many things need to be restructured. the Elements all need to be parsed first, then // relationships and links need to be created. Otherwise, the config file becomes order dependent. DatabaseElement d = new DatabaseElement(); d.SqlEntities = sqlentities; sqlentity.Views = ViewElement.ParseFromXml(node, d, sqlentity, sqltypes, types, vd); sqlentities.Add(sqlentity); } } StringCollection names = new StringCollection(); foreach (SqlEntityElement sqlentity in sqlentities) { if (names.Contains(sqlentity.Name)) { vd(new ParserValidationArgs(ParserValidationSeverity.ERROR, "duplicate sqlentity definition for " + sqlentity.Name)); } else { names.Add(sqlentity.Name); } } return(sqlentities); }
/// <summary> /// Post-parse validations /// </summary> /// <param name="vd"></param> protected void Validate(ParserValidationDelegate vd) { //TODO: walk through collection to make sure that cross relations are correct. foreach (DatabaseElement database in databases) { foreach (SqlEntityElement sqlentity in database.SqlEntities) { if (sqlentity.GetPrimaryKeyColumns().Count == 0 && (sqlentity.AllowDelete || sqlentity.AllowInsert || sqlentity.AllowUpdate)) { vd(ParserValidationArgs.NewWarning("SqlEntity " + sqlentity.Name + " does not have any primary key columns defined.")); } if (!sqlentity.HasUpdatableColumns() && sqlentity.GenerateUpdateStoredProcScript) { vd(ParserValidationArgs.NewWarning("SqlEntity " + sqlentity.Name + " does not have any editable columns and does not have generateupdatestoredprocscript=\"false\" specified.")); } } } // make sure that all columns are represented in entities foreach (EntityElement entity in entities) { if (entity.SqlEntity.Name.Length > 0) { foreach (ColumnElement column in entity.SqlEntity.Columns) { if (!column.Obsolete && EntityElement.FindAnyFieldByColumnName(entities, column.Name) == null && !entity.HasEntityMappedColumn(column)) { vd(ParserValidationArgs.NewWarning("could not find property representing column " + column.Name + " in entity " + entity.Name + ".")); } } } foreach (PropertyElement property in entity.Fields) { // make sure that obsolete columns are not mapped to properties if (property.Column.Obsolete && property.Column.Name.Length > 0) { vd(ParserValidationArgs.NewWarning("property " + property.Name + " in entity " + entity.Name + " is mapped to column " + property.Column.Name + " which is obsolete.")); } // have property descriptions "inherit" from a column if they are not populated if (property.Column.Description.Length > 0 && property.Description.Length == 0) { property.Description = property.Column.Description; } } } // make sure that enum values are unique foreach (EnumElement enumtype in enumtypes) { Hashtable values = new Hashtable(); foreach (EnumValueElement value in enumtype.Values) { if (values.Contains(value.Code)) { vd(ParserValidationArgs.NewError("Enum " + enumtype.Name + " has the code '" + value.Code + "' specified more than once.")); } else { values.Add(value.Code, value.Code); } } } // find and assign types to collections if available (the TypeElement is needed for templates that need to add namespaces) foreach (CollectionElement collection in Collections) { if (types.Contains(collection.Type.Name)) { collection.Type = (TypeElement)types[collection.Type.Name]; } } foreach (TaskElement task in generator.Tasks) { IWriter w = GetWriter(task.Writer); if (w == null) { vd(ParserValidationArgs.NewError("Task specified writer '" + task.Writer + "' that was not defined.")); } // check to make sure the styler exists if it is specified (optional) if (task.Styler.Length > 0) { IStyler s = GetStyler(task.Styler); if (s == null) { vd(ParserValidationArgs.NewError("Task specified styler '" + task.Styler + "' that was not defined.")); } } } }
public static ArrayList ParseFromXml(XmlNode root, SqlEntityElement sqlentity, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd) { ArrayList constraints = new ArrayList(); XmlNodeList elements = null; foreach (XmlNode n in root.ChildNodes) { if (n.Name.Equals("constraints")) { elements = n.ChildNodes; break; } } if (elements != null) { foreach (XmlNode node in elements) { if (node.NodeType == XmlNodeType.Comment) { continue; } ConstraintElement constraint = new ConstraintElement(); constraint.Name = node.Attributes["name"].Value; constraint.Type = node.Attributes["type"].Value; if (node.Attributes["clustered"] != null) { constraint.Clustered = Boolean.Parse(node.Attributes["clustered"].Value); } if (node.Attributes["foreignentity"] != null) { constraint.ForeignEntity.Name = node.Attributes["foreignentity"].Value; } if (node.Attributes["checkclause"] != null) { constraint.CheckClause = node.Attributes["checkclause"].Value; } if (node.Attributes["checkenum"] != null) { constraint.CheckEnum.Name = node.Attributes["checkenum"].Value; } foreach (XmlNode n in node.ChildNodes) { if (n.NodeType == XmlNodeType.Comment) { continue; } ColumnElement column = sqlentity.FindColumnByName(n.Attributes["name"].Value); if (column == null) { vd(ParserValidationArgs.NewError("column specified (" + n.Attributes["name"].Value + ") in constraint (" + constraint.Name + ") not found as column.")); column = new ColumnElement(); column.Name = n.Attributes["name"].Value; } if (n.Attributes["foreigncolumn"] != null) { column.ForeignColumn = n.Attributes["foreigncolumn"].Value; } constraint.Columns.Add(column); } constraints.Add(constraint); } } return(constraints); }