/// <summary> /// Imports the specified XML reader. /// </summary> /// <param name="xmlNode">The XML node.</param> /// <param name="includeWindowsUsersAndGroups">if set to <c>true</c> [include windows users and groups].</param> /// <param name="includeDBUsers">if set to <c>true</c> [include DB users].</param> /// <param name="includeAuthorizations">if set to <c>true</c> [include authorizations].</param> /// <param name="mergeOptions">The merge options.</param> public void ImportChildren(XmlNode xmlNode, bool includeWindowsUsersAndGroups, bool includeDBUsers, bool includeAuthorizations, SqlAzManMergeOptions mergeOptions) { //Create Store Groups foreach (XmlNode node in xmlNode.ChildNodes) { if (node.Name == "Attributes") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "Attribute") { if (!this.Attributes.ContainsKey(childNode.Attributes["Key"].Value)) { IAzManAttribute <IAzManStore> newStoreAttribute = this.CreateAttribute(childNode.Attributes["Key"].Value, childNode.Attributes["Value"].Value); } else { this.Attributes[childNode.Attributes["Key"].Value].Update(childNode.Attributes["Key"].Value, childNode.Attributes["Value"].Value); } } } } else if (node.Name == "Attribute") { if (!this.Attributes.ContainsKey(node.Attributes["Key"].Value)) { IAzManAttribute <IAzManStore> newStoreAttribute = this.CreateAttribute(node.Attributes["Key"].Value, node.Attributes["Value"].Value); } else { this.Attributes[node.Attributes["Key"].Value].Update(node.Attributes["Key"].Value, node.Attributes["Value"].Value); } } if (node.Name == "Permissions") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "Managers") { foreach (XmlNode childChildNode in childNode.ChildNodes) { if (childChildNode.Name == "Manager") { this.GrantAccessAsManager(childChildNode.Attributes["SqlUserOrRole"].Value); } } } else if (childNode.Name == "Users") { foreach (XmlNode childChildNode in childNode.ChildNodes) { if (childChildNode.Name == "User") { this.GrantAccessAsUser(childChildNode.Attributes["SqlUserOrRole"].Value); } } } else if (childNode.Name == "Readers") { foreach (XmlNode childChildNode in childNode.ChildNodes) { if (childChildNode.Name == "Reader") { this.GrantAccessAsReader(childChildNode.Attributes["SqlUserOrRole"].Value); } } } } } if (node.Name == "StoreGroups") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "StoreGroup") { GroupType groupType = GroupType.Basic; if (childNode.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString()) { groupType = GroupType.LDapQuery; } IAzManStoreGroup storeGroup = null; string sid = null; if (this.StoreGroups.ContainsKey(childNode.Attributes["Name"].Value)) { storeGroup = this.StoreGroups[childNode.Attributes["Name"].Value]; sid = storeGroup.SID.StringValue; //Change Store Group SID MergeUtilities.changeSid(childNode.OwnerDocument.DocumentElement, childNode.Attributes["Sid"].Value, sid); } else { sid = SqlAzManSID.NewSqlAzManSid().StringValue; storeGroup = this.CreateStoreGroup(new SqlAzManSID(sid), childNode.Attributes["Name"].Value, childNode.Attributes["Description"].Value, childNode.Attributes["LDAPQuery"].Value, groupType); //Change Store Group SID MergeUtilities.changeSid(childNode.OwnerDocument.DocumentElement, childNode.Attributes["Sid"].Value, sid); } //newStoreGroup.ImportChildren(childNode, includeWindowsUsersAndGroups, includeAuthorizations); } } } else if (node.Name == "StoreGroup") { GroupType groupType = GroupType.Basic; if (node.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString()) { groupType = GroupType.LDapQuery; } IAzManStoreGroup storeGroup = null; string sid = null; if (this.StoreGroups.ContainsKey(node.Attributes["Name"].Value)) { storeGroup = this.StoreGroups[node.Attributes["Name"].Value]; sid = storeGroup.SID.StringValue; //Change Store Group SID MergeUtilities.changeSid(node.OwnerDocument.DocumentElement, node.Attributes["Sid"].Value, sid); } else { sid = SqlAzManSID.NewSqlAzManSid().StringValue; storeGroup = this.CreateStoreGroup(new SqlAzManSID(sid), node.Attributes["Name"].Value, node.Attributes["Description"].Value, node.Attributes["LDAPQuery"].Value, groupType); //Change Store Group SID MergeUtilities.changeSid(node.OwnerDocument.DocumentElement, node.Attributes["Sid"].Value, sid); } //newStoreGroup.ImportChildren(node, includeWindowsUsersAndGroups, includeAuthorizations); } } //Create Applications & Store Group Members foreach (XmlNode node in xmlNode.ChildNodes) { System.Windows.Forms.Application.DoEvents(); if (node.Name == "Applications") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "Application") { IAzManApplication newApplication = this.Applications.ContainsKey(childNode.Attributes["Name"].Value) ? this.Applications[childNode.Attributes["Name"].Value] : this.CreateApplication(childNode.Attributes["Name"].Value, childNode.Attributes["Description"].Value); newApplication.ImportChildren(childNode, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions); } } } else if (node.Name == "Application") { IAzManApplication newApplication = this.Applications.ContainsKey(node.Attributes["Name"].Value) ? this.Applications[node.Attributes["Name"].Value] : this.CreateApplication(node.Attributes["Name"].Value, node.Attributes["Description"].Value); newApplication.ImportChildren(node, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions); } else if (node.Name == "StoreGroups") { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == "StoreGroup") { GroupType groupType = GroupType.Basic; if (childNode.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString()) { groupType = GroupType.LDapQuery; } if (groupType == GroupType.Basic) { IAzManStoreGroup newStoreGroup = this.StoreGroups[childNode.Attributes["Name"].Value]; newStoreGroup.ImportChildren(childNode, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions); } } } } else if (node.Name == "StoreGroup") { GroupType groupType = GroupType.Basic; if (node.Attributes["GroupType"].Value == GroupType.LDapQuery.ToString()) { groupType = GroupType.LDapQuery; } if (groupType == GroupType.Basic) { IAzManStoreGroup newStoreGroup = this.StoreGroups[node.Attributes["Name"].Value]; newStoreGroup.ImportChildren(node, includeWindowsUsersAndGroups, includeDBUsers, includeAuthorizations, mergeOptions); } } } this.applications = null; //Force refresh }