/// <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="databaseElements"></param> public static void ParseFromXml(XmlNode node, IList databaseElements) { if (node != null && databaseElements != null) { foreach (XmlNode databaseNode in node.ChildNodes) { if (databaseNode.NodeType.Equals(XmlNodeType.Element)) { DatabaseElement databaseElement = new DatabaseElement(); databaseElement.Name = GetAttributeValue(databaseNode, NAME, databaseElement.Name); databaseElement.Audit = Boolean.Parse(GetAttributeValue(databaseNode, AUDIT, databaseElement.Audit.ToString())); databaseElement.SingleFile = Boolean.Parse(GetAttributeValue(databaseNode, SCRIPT_SINGLE_FILE, databaseElement.SingleFile.ToString())); databaseElement.Server = GetAttributeValue(databaseNode, SERVER, databaseElement.Server); databaseElement.Database = GetAttributeValue(databaseNode, DATABASE, databaseElement.Database); databaseElement.User = GetAttributeValue(databaseNode, USER, databaseElement.User); databaseElement.Password = GetAttributeValue(databaseNode, PASSWORD, databaseElement.Password); databaseElement.SqlScriptDirectory = GetAttributeValue(databaseNode, SCRIPT_DIRECTORY, databaseElement.SqlScriptDirectory); databaseElement.StoredProcNameFormat = GetAttributeValue(databaseNode, STORED_PROC_NAME_FORMAT, databaseElement.StoredProcNameFormat); databaseElement.GenerateSqlViewScripts = Boolean.Parse(GetAttributeValue(databaseNode, GENERATE_VIEW_SCRIPT, databaseElement.GenerateSqlViewScripts.ToString())); databaseElement.GenerateSqlTableScripts = Boolean.Parse(GetAttributeValue(databaseNode, GENERATE_TABLE_SCRIPT, databaseElement.GenerateSqlTableScripts.ToString())); databaseElement.GenerateInsertStoredProcScript = Boolean.Parse(GetAttributeValue(databaseNode, GENERATE_INSERT_STORED_PROC_SCRIPT, databaseElement.GenerateInsertStoredProcScript.ToString())); databaseElement.GenerateUpdateStoredProcScript = Boolean.Parse(GetAttributeValue(databaseNode, GENERATE_UPDATE_STORED_PROC_SCRIPT, databaseElement.GenerateUpdateStoredProcScript.ToString())); databaseElement.GenerateDeleteStoredProcScript = Boolean.Parse(GetAttributeValue(databaseNode, GENERATE_DELETE_STORED_PROC_SCRIPT, databaseElement.GenerateDeleteStoredProcScript.ToString())); databaseElement.GenerateSelectStoredProcScript = Boolean.Parse(GetAttributeValue(databaseNode, GENERATE_SELECT_STORED_PROC_SCRIPT, databaseElement.GenerateSelectStoredProcScript.ToString())); databaseElement.AllowInsert = Boolean.Parse(GetAttributeValue(databaseNode, ALLOW_INSERT, databaseElement.AllowInsert.ToString())) || databaseElement.GenerateInsertStoredProcScript; databaseElement.AllowUpdate = Boolean.Parse(GetAttributeValue(databaseNode, ALLOW_UPDATE, databaseElement.AllowUpdate.ToString())) || databaseElement.GenerateUpdateStoredProcScript; databaseElement.AllowDelete = Boolean.Parse(GetAttributeValue(databaseNode, ALLOW_DELETE, databaseElement.AllowDelete.ToString())) || databaseElement.GenerateDeleteStoredProcScript; databaseElement.DefaultDirtyRead = Boolean.Parse(GetAttributeValue(databaseNode, DEFAULT_DIRTY_READ, databaseElement.DefaultDirtyRead.ToString())); databaseElement.UpdateChangedOnly = Boolean.Parse(GetAttributeValue(databaseNode, UPDATE_CHANGED_ONLY, databaseElement.UpdateChangedOnly.ToString())) && databaseElement.AllowUpdate; databaseElement.ScriptDropStatement = Boolean.Parse(GetAttributeValue(databaseNode, SCRIPT_DROP_STATEMENT, databaseElement.ScriptDropStatement.ToString())); databaseElement.UseView = Boolean.Parse(GetAttributeValue(databaseNode, USE_VIEW, databaseElement.UseView.ToString())); databaseElement.GenerateProcsForForeignKey = Boolean.Parse(GetAttributeValue(databaseNode, GENERATE_PROCS_FOR_FOREIGN_KEYS, databaseElement.GenerateProcsForForeignKey.ToString())); databaseElement.GenerateOnlyPrimaryDeleteStoredProc = Boolean.Parse(GetAttributeValue(databaseNode, GENERATE_ONLY_PRIMARY_DELETE_STORED_PROC, databaseElement.GenerateOnlyPrimaryDeleteStoredProc.ToString())); databaseElement.AllowUpdateOfPrimaryKey = Boolean.Parse(GetAttributeValue(databaseNode, ALLOW_UPDATE_OF_PRIMARY_KEY, databaseElement.AllowUpdateOfPrimaryKey.ToString())); databaseElement.CommandTimeout = Int32.Parse(GetAttributeValue(databaseNode, COMMAND_TIMEOUT, databaseElement.CommandTimeout.ToString())); databaseElement.ScriptForIndexedViews = Boolean.Parse(GetAttributeValue(databaseNode, SCRIPT_FOR_INDEXED_VIEWS, databaseElement.ScriptForIndexedViews.ToString())); SqlEntityElement.ParseFromXml(GetChildNodeByName(databaseNode, SQLENTITIES), databaseElement.SqlEntities); databaseElements.Add(databaseElement); } } } }
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); }