Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parse only method. Parses and adds all entities found in the given node and adds them to the given
        /// list.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="sqlEntityElements"></param>
        public static void ParseFromXml(XmlNode node, IList sqlEntityElements)
        {
            if (node != null && sqlEntityElements != null)
            {
                foreach (XmlNode sqlEntityNode in node.ChildNodes)
                {
                    if (sqlEntityNode.NodeType.Equals(XmlNodeType.Element))
                    {
                        SqlEntityElement sqlEntityElement = new SqlEntityElement();

                        sqlEntityElement.Name                           = GetAttributeValue(sqlEntityNode, NAME, sqlEntityElement.Name);
                        sqlEntityElement.View                           = GetAttributeValue(sqlEntityNode, VIEW, sqlEntityElement.View);
                        sqlEntityElement.SingleFile                     = Boolean.Parse(GetAttributeValue(sqlEntityNode, SCRIPT_SINGLE_FILE, sqlEntityElement.SingleFile.ToString()));
                        sqlEntityElement.Server                         = GetAttributeValue(sqlEntityNode, SERVER, sqlEntityElement.Server);
                        sqlEntityElement.Database                       = GetAttributeValue(sqlEntityNode, DATABASE, sqlEntityElement.Database);
                        sqlEntityElement.User                           = GetAttributeValue(sqlEntityNode, USER, sqlEntityElement.User);
                        sqlEntityElement.Password                       = GetAttributeValue(sqlEntityNode, PASSWORD, sqlEntityElement.Password);
                        sqlEntityElement.SqlScriptDirectory             = GetAttributeValue(sqlEntityNode, SCRIPT_DIRECTORY, sqlEntityElement.SqlScriptDirectory);
                        sqlEntityElement.StoredProcNameFormat           = GetAttributeValue(sqlEntityNode, STORED_PROC_NAME_FORMAT, sqlEntityElement.StoredProcNameFormat);
                        sqlEntityElement.GenerateSqlViewScripts         = Boolean.Parse(GetAttributeValue(sqlEntityNode, GENERATE_VIEW_SCRIPT, sqlEntityElement.GenerateSqlViewScripts.ToString()));
                        sqlEntityElement.GenerateSqlTableScripts        = Boolean.Parse(GetAttributeValue(sqlEntityNode, GENERATE_TABLE_SCRIPT, sqlEntityElement.GenerateSqlTableScripts.ToString()));
                        sqlEntityElement.GenerateInsertStoredProcScript = Boolean.Parse(GetAttributeValue(sqlEntityNode, GENERATE_INSERT_STORED_PROC_SCRIPT, sqlEntityElement.GenerateInsertStoredProcScript.ToString()));
                        sqlEntityElement.GenerateUpdateStoredProcScript = Boolean.Parse(GetAttributeValue(sqlEntityNode, GENERATE_UPDATE_STORED_PROC_SCRIPT, sqlEntityElement.GenerateUpdateStoredProcScript.ToString()));
                        sqlEntityElement.GenerateDeleteStoredProcScript = Boolean.Parse(GetAttributeValue(sqlEntityNode, GENERATE_DELETE_STORED_PROC_SCRIPT, sqlEntityElement.GenerateDeleteStoredProcScript.ToString()));
                        sqlEntityElement.GenerateSelectStoredProcScript = Boolean.Parse(GetAttributeValue(sqlEntityNode, GENERATE_SELECT_STORED_PROC_SCRIPT, sqlEntityElement.GenerateSelectStoredProcScript.ToString()));
                        sqlEntityElement.AllowInsert                    = Boolean.Parse(GetAttributeValue(sqlEntityNode, ALLOW_INSERT, sqlEntityElement.AllowInsert.ToString())) ||
                                                                          sqlEntityElement.GenerateInsertStoredProcScript;
                        sqlEntityElement.AllowUpdate = Boolean.Parse(GetAttributeValue(sqlEntityNode, ALLOW_UPDATE, sqlEntityElement.AllowUpdate.ToString())) ||
                                                       sqlEntityElement.GenerateUpdateStoredProcScript;
                        sqlEntityElement.AllowDelete = Boolean.Parse(GetAttributeValue(sqlEntityNode, ALLOW_DELETE, sqlEntityElement.AllowDelete.ToString())) ||
                                                       sqlEntityElement.GenerateDeleteStoredProcScript;
                        sqlEntityElement.DefaultDirtyRead  = Boolean.Parse(GetAttributeValue(sqlEntityNode, DEFAULT_DIRTY_READ, sqlEntityElement.DefaultDirtyRead.ToString()));
                        sqlEntityElement.UpdateChangedOnly = Boolean.Parse(GetAttributeValue(sqlEntityNode, UPDATE_CHANGED_ONLY, sqlEntityElement.UpdateChangedOnly.ToString())) &&
                                                             sqlEntityElement.AllowUpdate;
                        sqlEntityElement.ScriptDropStatement                 = Boolean.Parse(GetAttributeValue(sqlEntityNode, SCRIPT_DROP_STATEMENT, sqlEntityElement.ScriptDropStatement.ToString()));
                        sqlEntityElement.UseView                             = Boolean.Parse(GetAttributeValue(sqlEntityNode, USE_VIEW, sqlEntityElement.UseView.ToString()));
                        sqlEntityElement.GenerateProcsForForeignKey          = Boolean.Parse(GetAttributeValue(sqlEntityNode, GENERATE_PROCS_FOR_FOREIGN_KEYS, sqlEntityElement.GenerateProcsForForeignKey.ToString()));
                        sqlEntityElement.GenerateOnlyPrimaryDeleteStoredProc = Boolean.Parse(GetAttributeValue(sqlEntityNode, GENERATE_ONLY_PRIMARY_DELETE_STORED_PROC, sqlEntityElement.GenerateOnlyPrimaryDeleteStoredProc.ToString()));
                        sqlEntityElement.AllowUpdateOfPrimaryKey             = Boolean.Parse(GetAttributeValue(sqlEntityNode, ALLOW_UPDATE_OF_PRIMARY_KEY, sqlEntityElement.AllowUpdateOfPrimaryKey.ToString()));
                        sqlEntityElement.CommandTimeout                      = Int32.Parse(GetAttributeValue(sqlEntityNode, COMMAND_TIMEOUT, sqlEntityElement.CommandTimeout.ToString()));
                        sqlEntityElement.ScriptForIndexedViews               = Boolean.Parse(GetAttributeValue(sqlEntityNode, SCRIPT_FOR_INDEXED_VIEWS, sqlEntityElement.ScriptForIndexedViews.ToString()));

                        ColumnElement.ParseFromXml(GetChildNodeByName(sqlEntityNode, COLUMNS), sqlEntityElement.Columns);
                        ConstraintElement.ParseFromXml(GetChildNodeByName(sqlEntityNode, CONSTRAINTS), sqlEntityElement.Constraints);
                        IndexElement.ParseFromXml(GetChildNodeByName(sqlEntityNode, INDEXES), sqlEntityElement.Indexes);
                        ViewElement.ParseFromXml(GetChildNodeByName(sqlEntityNode, VIEWS), sqlEntityElement.Views);

                        sqlEntityElements.Add(sqlEntityElement);
                    }
                }
            }
        }