Esempio n. 1
0
        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>
        /// 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);
                    }
                }
            }
        }
        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 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);
        }
Esempio n. 5
0
        /// <summary>
        /// Second pass parse and validation.
        /// </summary>
        /// <param name="options">Configuration options.</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="entities">List of EntityElement objects defined.</param>
        /// <param name="vd">Validation delegate for error reporting.</param>
        /// <returns>Validated list of report extractions.</returns>
        public static ArrayList ParseFromXml(Configuration options, XmlDocument doc, Hashtable sqltypes, Hashtable types, IList entities, ParserValidationDelegate vd)
        {
            ArrayList   reportExtractions = new ArrayList();
            XmlNodeList elements          = doc.DocumentElement.GetElementsByTagName("reportextraction");

            foreach (XmlNode node in elements)
            {
                if (node.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }
                ReportExtractionElement reportExtraction = new ReportExtractionElement();
                if (node.Attributes[NAME] != null)
                {
                    reportExtraction.Name = node.Attributes[NAME].Value;
                }
                else
                {
                    vd(ParserValidationArgs.NewError("A report extraction must have a name."));
                }
                if (node.Attributes[HINTS] != null)
                {
                    reportExtraction.Hints = (string)(node.Attributes[HINTS].Value);
                }
                if (node.Attributes[HAVING] != null)
                {
                    reportExtraction.Having = (string)(node.Attributes[HAVING].Value);
                }

                reportExtraction.EntityReferences = EntityReferenceElement.ParseFromXml(options, GetChildNodeByName(node, ENTITY_REFERENCES), reportExtraction, types, sqltypes, entities, vd);
                XmlNode computedProperties = GetChildNodeByName(node, COMPUTED_PROPERTIES);
                if (computedProperties != null)
                {
                    reportExtraction.ComputedProperties = PropertyElement.ParseFromXml(computedProperties, entities, reportExtraction, sqltypes, types, false, vd);
                }
                reportExtraction.ValidateFilters(vd);
                reportExtraction.ValidateExpressions(vd);
                reportExtraction.ValidateUniqueNames(vd);
                reportExtraction.ValidateDatabases(vd);
                reportExtractions.Add(reportExtraction);
                reportExtraction.Having = Configuration.PrepareExpression(reportExtraction.Having, reportExtraction, "having attribute in report extraction " + reportExtraction.Name, vd);

                // Make sure finders get prepared expressions!
                reportExtraction.Comparers = ComparerElement.ParseFromXml(node, entities, reportExtraction, sqltypes, types, vd);
                reportExtraction.Finders   = ReportExtractionFinderElement.ParseFromXml(node, entities, reportExtraction, sqltypes, types, vd);
            }
            return(reportExtractions);
        }
Esempio n. 6
0
        public static ArrayList ParseFromXml(Configuration options, XmlDocument doc, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd)
        {
            ArrayList   enums    = new ArrayList();
            XmlNodeList elements = doc.DocumentElement.GetElementsByTagName("enum");

            foreach (XmlNode node in elements)
            {
                if (node.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }
                EnumElement type = new EnumElement();
                type.Name = node.Attributes["name"].Value;
                // TODO: this returns all of the children node's innerText as well
                //type.Description = StringUtil.RemoveTrailingBlankLines(node.InnerText.Trim());
                if (node.Attributes["template"] != null)
                {
                    type.Template = node.Attributes["template"].Value;
                }
                if (node.Attributes["integerbased"] != null)
                {
                    type.IntegerBased = Boolean.Parse(node.Attributes["integerbased"].Value);
                }
                type.Values = EnumValueElement.ParseFromXml(type.Name, options, doc, sqltypes, types, vd);

                // if IsIntegerBased - validate that all values are parsable by Int32
                if (type.IntegerBased)
                {
                    foreach (EnumValueElement v in type.Values)
                    {
                        try {
                            Int32.Parse(v.Code);
                        } catch (Exception) {
                            // parse error - must not be an Int32
                            vd(ParserValidationArgs.NewError("IntegerBased was set for enum " + type.Name + " and code '" + v.Code + "' was not parsable by Int32."));
                        }
                    }
                }

                enums.Add(type);
            }
            return(enums);
        }
Esempio n. 7
0
        /// <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."));
                }
            }
        }
Esempio n. 8
0
        /// <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;
                    }
                }
            }
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        public string GetExpressionSubstitution(string substitutionExpression, string idString, ParserValidationDelegate vd)
        {
            int parm = -1;

            try {
                parm = Int32.Parse(substitutionExpression);
            } catch (Exception) {
            }

            if (parm > -1)
            {
                if (parm >= fields.Count)
                {
                    if (vd != null)
                    {
                        vd(ParserValidationArgs.NewError("Substitution string " + substitutionExpression + " in " + idString + " refers to a parameter number larger that the number of parameters."));
                    }
                    return("");
                }

                String param = "@" + ((PropertyElement)(this.Fields[parm])).GetPropertyName();
                return(param.Replace(".", "_"));
            }
            else
            {
                PropertyElement p = this.container.FindFieldByName(substitutionExpression);
                if (p == null)
                {
                    if (vd != null)
                    {
                        vd(ParserValidationArgs.NewError("Substitution string " + substitutionExpression + " in " + idString + " refers to a property that does not occur in the finder's entity."));
                    }
                    return("");
                }
                else
                {
                    return(GetSqlExpression(p));
                }
            }
        }
Esempio n. 11
0
        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);
        }
        /// <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);
        }
Esempio n. 13
0
        /*
         * /// <summary>
         * /// Replaces embedded property references in the string with sql cocde.
         * /// </summary>
         * /// <param name="withEmbedded">Expression to be replaced.</param>
         * /// <param name="idString">Id to use when reporting errors.</param>
         * /// <param name="vd">Validation delegate for error reporting.</param>
         * /// <returns>String with embedded references replaced.</returns>
         * private string PrepareExpression(string withEmbedded, 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.
         *      string expression = checkExpression.Substring(leftBrace+1, rightBrace - leftBrace - 1);
         *
         *      // Create list of property references seen to check for circular references.
         *      ArrayList repeList = new ArrayList();
         *
         *      string[] parts = expression.Split('.');
         *      string leftPart = "";
         *      string rightPart = "";
         *      if (parts.Length == 1)
         *      {
         *          // Default the left part to this report extraction if not specified.
         *          leftPart = this.Name;
         *          rightPart = parts[0];
         *      }
         *      else if (parts.Length == 2)
         *      {
         *          leftPart = parts[0];
         *          rightPart = parts[1];
         *      }
         *      else
         *      {
         *          if (vd != null)
         *          {
         *              vd(ParserValidationArgs.NewError("The expression " + expression + " in the " + idString + " does not contain exactly one dot(.)."));
         *          }
         *          return "";
         *      }
         *
         *
         *      if (leftPart.ToLower() == this.Name.ToLower())
         *      {
         *          // Refers to a property in this report extraction.
         *          ReportExtractionPropertyElement repe = this.FindComputedFieldByName(rightPart);
         *          if (repe != null)
         *          {
         *              // Refers to a computed property.  Check for circular references.
         *              foreach(ReportExtractionPropertyElement repel in repeList)
         *              {
         *                  if(repel.Name == repe.Name)
         *                  {
         *                      if (vd != null)
         *                      {
         *                          vd(ParserValidationArgs.NewError("The expression " + expression + " in the " + idString + " has a circular reference."));
         *                      }
         *                      return "";
         *                  }
         *              }
         *
         *              // Add in the expansion of this property.e
         *              retVal += "(" + repe.GetSqlExpression() + ")";
         *          }
         *          else
         *          {
         *              EntityReferencePropertyElement pre = this.FindReferenceFieldByName(rightPart);
         *              if (pre != null)
         *              {
         *                  // Refers to a property reference.  Get the expression.
         *                  retVal += pre.GetSqlExpression();
         *              }
         *              else
         *              {
         *                  if (vd != null)
         *                  {
         *                      vd(ParserValidationArgs.NewError("The expression " + expression + " in the " + idString + " refers to a property in the report extraction that does not exist."));
         *                  }
         *                  return "";
         *              }
         *          }
         *      }
         *      else
         *      {
         *          EntityReferenceElement er = FindEntityReferenceByName(leftPart);
         *          if (er == null)
         *          {
         *              if (vd != null)
         *              {
         *                  vd(ParserValidationArgs.NewError("The expression " + expression + " in the " + idString + " refers to an entity that is not an entity reference in the extraction nor the extraction itself."));
         *              }
         *              return "";
         *          }
         *          else
         *          {
         *              // Refers to an entity reference.
         *              EntityReferencePropertyElement pre = er.FindFieldBySqlAlias(rightPart);
         *              if (pre != null)
         *              {
         *                  // Refers to a property reference in the entity.
         *                  retVal += pre.GetSqlExpression();
         *              }
         *              else
         *              {
         *                  PropertyElement p = er.Entity.FindFieldByName(rightPart);
         *                  if (p != null)
         *                  {
         *                      // Refers to a property in the entity referenced that is not in the property referenced.
         *                      retVal += "[" + er.Name + "].[" + p.Column.Name + "]";
         *                  }
         *                  else
         *                  {
         *                      if (vd != null)
         *                      {
         *                          vd(ParserValidationArgs.NewError("The expression " + expression + " in the " + idString + " refers to a property that is not in the referenced entity reference nor it's associated entity."));
         *                      }
         *                      else
         *                      {
         *                          return "";
         *                      }
         *                  }
         *              }
         *          }
         *      }
         *
         *      startPos = rightBrace + 1;
         *  }
         *
         *  return retVal;
         * }*/

        public string GetExpressionSubstitution(string substitutionExpression, string idString, ParserValidationDelegate vd)
        {
            // Create list of property references seen to check for circular references.
            ArrayList repeList = new ArrayList();

            string[] parts     = substitutionExpression.Split('.');
            string   leftPart  = "";
            string   rightPart = "";

            if (parts.Length == 1)
            {
                // Default the left part to this report extraction if not specified.
                leftPart  = this.Name;
                rightPart = parts[0];
            }
            else if (parts.Length == 2)
            {
                leftPart  = parts[0];
                rightPart = parts[1];
            }
            else
            {
                if (vd != null)
                {
                    vd(ParserValidationArgs.NewError("The expression " + substitutionExpression + " in the " + idString + " does not contain exactly one dot(.)."));
                }
                return("");
            }


            if (leftPart.ToLower() == this.Name.ToLower())
            {
                // Refers to a property in this report extraction.
                PropertyElement repe = this.FindComputedFieldByName(rightPart);
                if (repe != null)
                {
                    // Refers to a computed property.  Check for circular references.
                    foreach (PropertyElement repel in repeList)
                    {
                        if (repel.Name == repe.Name)
                        {
                            if (vd != null)
                            {
                                vd(ParserValidationArgs.NewError("The expression " + substitutionExpression + " in the " + idString + " has a circular reference."));
                            }
                            return("");
                        }
                    }

                    // Add in the expansion of this property.e
                    return("(" + repe.GetSqlExpression() + ")");
                }
                else
                {
                    PropertyElement pre = this.FindReferenceFieldByName(rightPart);
                    if (pre != null)
                    {
                        // Refers to a property reference.  Get the expression.
                        return(pre.GetSqlExpression());
                    }
                    else
                    {
                        if (vd != null)
                        {
                            vd(ParserValidationArgs.NewError("The expression " + substitutionExpression + " in the " + idString + " refers to a property in the report extraction that does not exist."));
                        }
                        return("");
                    }
                }
            }
            else
            {
                EntityReferenceElement er = FindEntityReferenceByName(leftPart);
                if (er == null)
                {
                    if (vd != null)
                    {
                        vd(ParserValidationArgs.NewError("The expression " + substitutionExpression + " in the " + idString + " refers to an entity that is not an entity reference in the extraction nor the extraction itself."));
                    }
                    return("");
                }
                else
                {
                    // Refers to an entity reference.
                    PropertyElement pre = er.FindFieldBySqlAlias(rightPart);
                    if (pre != null)
                    {
                        // Refers to a property reference in the entity.
                        return(pre.GetSqlExpression());
                    }
                    else
                    {
                        PropertyElement p = er.Entity.FindFieldByName(rightPart);
                        if (p != null)
                        {
                            // Refers to a property in the entity referenced that is not in the property referenced.
                            return("[" + er.Name + "].[" + p.Column.Name + "]");
                        }
                        else
                        {
                            if (vd != null)
                            {
                                vd(ParserValidationArgs.NewError("The expression " + substitutionExpression + " in the " + idString + " refers to a property that is not in the referenced entity reference nor it's associated entity."));
                            }
                            return("");
                        }
                    }
                }
            }
        }
        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(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);
        }
Esempio n. 16
0
        public static ArrayList ParseFromXml(Configuration options, XmlDocument doc, Hashtable sqltypes, Hashtable types, ArrayList sqlentities, ParserValidationDelegate vd)
        {
            ArrayList entities     = new ArrayList();
            XmlNode   entitiesNode = doc.DocumentElement.Cast <XmlNode>().FirstOrDefault(x => x.Name.ToLowerInvariant() == "entities");

            if (entitiesNode == null)
            {
                return(entities);
            }

            IEnumerable <XmlNode> elements = entitiesNode.ChildNodes.Cast <XmlNode>().Where(x => x.Name.ToLowerInvariant() == "entity");

            foreach (XmlNode node in elements)
            {
                if (node.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }
                EntityElement entity = new EntityElement();
                entity.Name = node.Attributes["name"].Value;
                if (node.Attributes["namespace"] != null)
                {
                    entity.Namespace = node.Attributes["namespace"].Value;
                }
                if (node.Attributes["sqlentity"] != null)
                {
                    SqlEntityElement sqlentity = SqlEntityElement.FindByName(sqlentities, node.Attributes["sqlentity"].Value);
                    if (sqlentity != null)
                    {
                        entity.SqlEntity = (SqlEntityElement)sqlentity.Clone();
                    }
                    else
                    {
                        entity.SqlEntity.Name = node.Attributes["sqlentity"].Value;
                        vd(ParserValidationArgs.NewError("sqlentity (" + entity.SqlEntity.Name + ") specified in entity " + entity.Name + " could not be found as an defined sql entity"));
                    }
                }

                if (node.Attributes["baseentity"] != null)
                {
                    EntityElement baseentity = EntityElement.FindEntityByName(entities, node.Attributes["baseentity"].Value);
                    if (baseentity != null)
                    {
                        entity.BaseEntity = (EntityElement)baseentity.Clone();
                    }
                    else
                    {
                        entity.BaseEntity.Name = node.Attributes["baseentity"].Value;
                        vd(ParserValidationArgs.NewError("baseentity (" + entity.BaseEntity.Name + ") specified in entity " + entity.Name + " could not be found as an defined entity (or is defined after this entity in the config file)"));
                    }
                }

                if (node.Attributes["abstract"] != null)
                {
                    entity.IsAbstract = Boolean.Parse(node.Attributes["abstract"].Value);
                }

                if (node.Attributes["namespace"] != null)
                {
                    entity.HasNamespace = !String.IsNullOrEmpty(node.Attributes["namespace"].Value);
                }

                if (node.Attributes["log"] != null)
                {
                    entity.DoLog = Boolean.Parse(node.Attributes["log"].Value);
                }

                if (node.Attributes["returnwholeobject"] != null)
                {
                    entity.ReturnWholeObject = Boolean.Parse(node.Attributes["returnwholeobject"].Value);
                }

                if (node.Attributes["prepareforinsert"] != null)
                {
                    entity.PrepareForInsert = Boolean.Parse(node.Attributes["prepareforinsert"].Value);
                }

                if (node.Attributes["dependententity"] != null)
                {
                    entity.DependentEntity = Boolean.Parse(node.Attributes["dependententity"].Value);
                }

                if (node.Attributes["jointable"] != null)
                {
                    entity.JoinTable = Boolean.Parse(node.Attributes["jointable"].Value);
                }

                XmlNode descriptionNode = node.SelectSingleNode(DESCRIPTION);
                if (descriptionNode != null)
                {
                    entity.Description = descriptionNode.InnerText.Trim();
                }

                //Adds all attributes including all not defined by element class
                foreach (XmlAttribute attribute in node.Attributes)
                {
                    if (!entity.Attributes.ContainsKey(attribute.Name))
                    {
                        entity.Attributes.Add(attribute.Name, attribute.Value);
                    }
                }

                entity.dependents = ParseDependentsFromXml(node, vd);

                entity.fields    = PropertyElement.ParseFromXml(doc, entities, entity, sqltypes, types, vd);
                entity.finders   = FinderElement.ParseFromXml(doc, node, entities, entity, sqltypes, types, vd);
                entity.comparers = ComparerElement.ParseFromXml(node, entities, entity, sqltypes, types, vd);
                entities.Add(entity);
            }

            StringCollection names = new StringCollection();

            foreach (EntityElement entity in entities)
            {
                if (names.Contains(entity.Name))
                {
                    vd(new ParserValidationArgs(ParserValidationSeverity.ERROR, "duplicate entity definition for " + entity.Name));
                }
                else
                {
                    names.Add(entity.Name);
                }
            }
            return(entities);
        }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
        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);
        }
Esempio n. 19
0
        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;
                        }
                    }
                }
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Validates that names are unique across property references and computed properties.
        /// </summary>
        /// <param name="vd">Validation delegate for error reporting.</param>
        private void ValidateUniqueNames(ParserValidationDelegate vd)
        {
            ArrayList names = new ArrayList();

            foreach (EntityReferenceElement e in EntityReferences)
            {
                foreach (PropertyElement p in e.PropertyReferences)
                {
                    names.Add(p.GetSqlAlias());
                }
            }

            foreach (PropertyElement p in ComputedProperties)
            {
                names.Add(p.Name);
            }

            names.Sort();

            string prevName   = String.Empty;
            int    errorCount = 1;

            for (int i = 0; i < names.Count; i++)
            {
                string name = (string)(names[i]);
                if (name == prevName)
                {
                    errorCount++;
                }
                if (errorCount > 1 && (name != prevName || i >= names.Count - 1))
                {
                    vd(ParserValidationArgs.NewError("The property name " + prevName + " occurs " + errorCount.ToString() + " times in the report extraction " + this.Name));
                    errorCount = 1;
                }

                prevName = name;
            }

            names = new ArrayList();
            foreach (EntityReferenceElement e in EntityReferences)
            {
                names.Add(e.Name);
            }
            names.Sort();
            prevName   = String.Empty;
            errorCount = 1;
            for (int i = 0; i < names.Count; i++)
            {
                string name = (string)(names[i]);
                if (name == prevName)
                {
                    errorCount++;
                }
                if (errorCount > 1 && (name != prevName || i >= names.Count - 1))
                {
                    vd(ParserValidationArgs.NewError("The entity reference name " + prevName + " occurs " + errorCount.ToString() + " times in the report extraction " + this.Name));
                    errorCount = 1;
                }

                prevName = name;
            }
        }
Esempio n. 21
0
        public static ArrayList ParseFromXml(XmlNode root, SqlEntityElement sqlentity, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd)
        {
            ArrayList   indexes  = new ArrayList();
            XmlNodeList elements = null;

            foreach (XmlNode n in root.ChildNodes)
            {
                if (n.Name.Equals("indexes"))
                {
                    elements = n.ChildNodes;
                    break;
                }
            }
            if (elements != null)
            {
                foreach (XmlNode node in elements)
                {
                    if (node.NodeType == XmlNodeType.Comment)
                    {
                        continue;
                    }
                    IndexElement index = new IndexElement();
                    index.Name = node.Attributes["name"].Value;

                    if (node.Attributes["clustered"] != null)
                    {
                        index.Clustered = Boolean.Parse(node.Attributes["clustered"].Value);
                    }
                    if (node.Attributes["unique"] != null)
                    {
                        index.Unique = Boolean.Parse(node.Attributes["unique"].Value);
                    }

                    foreach (XmlNode n in node.ChildNodes)
                    {
                        if (node.NodeType == XmlNodeType.Comment)
                        {
                            continue;
                        }
                        if (n.Name == "include")
                        {
                            foreach (XmlNode includeNode in n.ChildNodes)
                            {
                                ColumnElement includeColumn = sqlentity.FindColumnByName(includeNode.Attributes["name"].Value);
                                if (includeColumn == null)
                                {
                                    vd(ParserValidationArgs.NewError("column specified (" + includeNode.Attributes["name"].Value + ") in index (" + index.Name + ") not found as column."));
                                    includeColumn      = new ColumnElement();
                                    includeColumn.Name = includeNode.Attributes["name"].Value;
                                }
                                index.IncludeColumns.Add(includeColumn);
                            }
                            continue;
                        }
                        ColumnElement column = sqlentity.FindColumnByName(n.Attributes["name"].Value);
                        if (column == null)
                        {
                            vd(ParserValidationArgs.NewError("column specified (" + n.Attributes["name"].Value + ") in index (" + index.Name + ") not found as column."));
                            column      = new ColumnElement();
                            column.Name = n.Attributes["name"].Value;
                        }
                        if (n.Attributes["sortdirection"] != null)
                        {
                            column.SortDirection = n.Attributes["sortdirection"].Value;
                        }
                        index.Columns.Add(column);
                    }
                    indexes.Add(index);
                }
            }
            return(indexes);
        }
Esempio n. 22
0
        public static ArrayList ParseFromXml(XmlNode root, DatabaseElement database, SqlEntityElement sqlentity, Hashtable sqltypes, Hashtable types, ParserValidationDelegate vd)
        {
            ArrayList list = new ArrayList();

            XmlNodeList elements = root.SelectNodes("views/view");

            if (elements != null)
            {
                foreach (XmlNode node in elements)
                {
                    if (node.NodeType == XmlNodeType.Comment)
                    {
                        continue;
                    }
                    ViewElement view = new ViewElement();
                    view.Name = ParseStringAttribute(node, "name", String.Empty);

                    foreach (XmlNode n in node.ChildNodes)
                    {
                        if (node.NodeType == XmlNodeType.Comment)
                        {
                            continue;
                        }
                        ConstraintElement constraint = sqlentity.FindConstraintByName(n.Attributes["name"].Value);
                        if (constraint == null)
                        {
                            vd(ParserValidationArgs.NewError("constraint specified (" + n.Attributes["name"].Value + ") in view (" + view.Name + ") not found."));
                            constraint      = new ConstraintElement();
                            constraint.Name = n.Attributes["name"].Value;
                        }
                        else
                        {
                            if (!constraint.Type.Equals(ConstraintElement.FOREIGN_KEY))
                            {
                                vd(ParserValidationArgs.NewError("View [" + view.Name + "] references a constraint that is not a foreign key constraint: " + constraint.Name));
                            }
                        }
                        constraint.Prefix = ParseStringAttribute(n, "prefix", constraint.ForeignEntity.Name + "_");
                        SqlEntityElement foreignEntity = database.FindSqlEntityByName(constraint.ForeignEntity.Name);

                        // check to see if the foreignEntity is itself
                        if (foreignEntity == null && sqlentity.Name == constraint.ForeignEntity.Name)
                        {
                            foreignEntity = sqlentity;
                        }

                        if (foreignEntity == null)
                        {
                            vd(ParserValidationArgs.NewError("View [" + view.Name + "] references a constraint that references an sql entity that was not defined (or was not defined before this sql entity): " + constraint.ForeignEntity));
                        }
                        else
                        {
                            ArrayList columnsToAdd = new ArrayList();
                            foreach (ColumnElement column in foreignEntity.Columns)
                            {
                                ColumnElement viewColumn = (ColumnElement)column.Clone();
                                if (!constraint.Prefix.Equals(String.Empty))
                                {
                                    viewColumn.Name = constraint.Prefix + viewColumn.Name;
                                }
                                viewColumn.Prefix           = constraint.Prefix;
                                viewColumn.ForeignSqlEntity = constraint.ForeignEntity.Name;
                                viewColumn.ViewColumn       = true;
                                columnsToAdd.Add(viewColumn);
                            }
                            sqlentity.Columns.AddRange(columnsToAdd);
                        }
                        view.Constraints.Add(constraint);
                    }

                    // validation
                    if (view.Name.Equals(String.Empty))
                    {
                        vd(ParserValidationArgs.NewError("View does not have a name: " + Environment.NewLine + node.OuterXml));
                    }

                    list.Add(view);
                }
            }
            return(list);
        }
Esempio n. 23
0
        public static Hashtable ParseFromXml(Configuration options, XmlNode doc, ParserValidationDelegate vd)
        {
            Hashtable   types = new Hashtable();
            XmlNodeList nodes = doc.SelectNodes("DataTierGenerator/types/type");

            foreach (XmlNode node in nodes)
            {
                if (node.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }
                TypeElement type = new TypeElement();

                type.Name         = node.Attributes["name"].Value;
                type.ConcreteType = type.Name;

                if (node.Attributes["concretetype"] != null)
                {
                    type.ConcreteType = node.Attributes["concretetype"].Value;
                }
                if (node.Attributes["namespace"] != null)
                {
                    type.Package = node.Attributes["namespace"].Value;
                }
                if (node.Attributes["newinstanceformat"] != null)
                {
                    type.NewInstanceFormat  = node.Attributes["newinstanceformat"].Value;
                    type.NullInstanceFormat = type.NewInstanceFormat;
                }
                if (node.Attributes["nullinstanceformat"] != null)
                {
                    type.NullInstanceFormat = node.Attributes["nullinstanceformat"].Value;
                }
                if (node.Attributes["converttosqltypeformat"] != null)
                {
                    type.ConvertToSqlTypeFormat = node.Attributes["converttosqltypeformat"].Value;
                }
                if (node.Attributes["convertfromsqltypeformat"] != null)
                {
                    type.ConvertFromSqlTypeFormat = node.Attributes["convertfromsqltypeformat"].Value;
                }
                if (node.Attributes[CONVERT_FOR_COMPARE] != null)
                {
                    type.ConvertForCompare = node.Attributes[CONVERT_FOR_COMPARE].Value;
                }
                if (types.ContainsKey(type.Name))
                {
                    vd(ParserValidationArgs.NewWarning("ignoring duplicate definition of type: " + type.Name));
                }
                else
                {
                    types.Add(type.Name, type);
                }
            }

//	    // add entities as data objects to types if not already defined
//	    elements = doc.DocumentElement.GetElementsByTagName("entity");
//	    foreach (XmlNode node in elements) {
//		if (node.NodeType == XmlNodeType.Comment) {
//		    continue;
//		}
//		if (!types.Contains(node.Attributes["name"].Value + "Data")) {
//		    TypeElement type = new TypeElement();
//		    type.Name = node.Attributes["name"].Value + "Data";
//		    type.ConcreteType = type.Name;
//		    type.Package = options.GetDONameSpace("");
//		    type.NewInstanceFormat = "new " + type.Name + "()";
//		    types.Add(type.Name, type);
//		}
//
//		// TODO: needs review, hacked for Dave
//		// add interfaces - use new x() for empty instance constructor
//		if (!types.Contains("I" + node.Attributes["name"].Value)) {
//		    TypeElement type = new TypeElement();
//		    type.Name = "I" + node.Attributes["name"].Value;
//		    type.ConcreteType = type.Name;
//		    type.Package = options.GetDONameSpace("");
//		    type.NewInstanceFormat = "new " + node.Attributes["name"].Value + "()";
//		    types.Add(type.Name, type);
//		}
//
//		// TODO: needs review, hacked for Dave
//		// add business entities - use new x() for empty instance constructor
//		if (!types.Contains(node.Attributes["name"].Value)) {
//		    TypeElement type = new TypeElement();
//		    type.Name = node.Attributes["name"].Value;
//		    type.ConcreteType = type.Name;
//		    type.Package = options.GetBusinessLogicNameSpace();
//		    type.NewInstanceFormat = "new " + type.Name + "()";
//		    types.Add(type.Name, type);
//		}
//	    }
//
//
//	    // add enums to types if not already defined
//	    elements = doc.DocumentElement.GetElementsByTagName("enum");
//	    foreach (XmlNode node in elements) {
//		if (node.NodeType == XmlNodeType.Comment) {
//		    continue;
//		}
//		if (!types.Contains(node.Attributes["name"].Value)) {
//		    TypeElement type = new TypeElement();
//		    type.Name = node.Attributes["name"].Value;
//		    type.ConcreteType = type.Name;
//		    type.Package = options.GetTypeNameSpace("");
//		    type.ConvertToSqlTypeFormat = "{1}.DBValue";
//		    type.ConvertFromSqlTypeFormat = type.Name + ".GetInstance({2})";
//		    type.NewInstanceFormat = type.Name + ".DEFAULT";
//		    type.NullInstanceFormat = type.Name + ".UNSET";
//		    types.Add(type.Name, type);
//		}
//	    }
//
//	    // see if we want to generate collections for all entities
//	    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 ());
//	    }
//
//	    if (generateAll) {
//		// add collections for all entities as data objects to types if not already defined
//		elements = doc.DocumentElement.GetElementsByTagName ("entity");
//		foreach (XmlNode node in elements) {
//		    if (node.NodeType == XmlNodeType.Comment) {
//			continue;
//		    }
//		    if (!types.Contains (node.Attributes["name"].Value + "List")) {
//			TypeElement type = new TypeElement ();
//			type.Name = node.Attributes["name"].Value + "List";
//			type.ConcreteType = type.Name;
//			type.Package = options.GetDONameSpace ("");
//			type.NewInstanceFormat = type.Name + ".DEFAULT";
//			type.NullInstanceFormat = type.Name + ".UNSET";
//			types.Add (type.Name, type);
//		    }
//		}
//	    } else {
//		// add collections as data objects to types if not already defined
//		elements = doc.DocumentElement.GetElementsByTagName("collection");
//		foreach (XmlNode node in elements) {
//		    if (node.NodeType == XmlNodeType.Comment) {
//			continue;
//		    }
//		    if (!types.Contains(node.Attributes["name"].Value)) {
//			TypeElement type = new TypeElement();
//			type.Name = node.Attributes["name"].Value;
//			type.ConcreteType = type.Name;
//			type.Package = options.GetDONameSpace("");
//			//type.NewInstanceFormat = "new " + type.Name + "()";
//			type.NewInstanceFormat = type.Name + ".DEFAULT";
//			type.NullInstanceFormat = type.Name + ".UNSET";
//			types.Add(type.Name, type);
//		    }
//		}
//	    }

            return(types);
        }