/// <summary> /// Procesa la ubicacion del nodo actual /// </summary> /// <param name="xpath">Xpath</param> /// <param name="herencia">Posicion donde se hace la herencia</param> /// <param name="valorReferencia">Nombre de la etiqueta de referencia</param> /// <param name="tipoEtiqueta">Tipo de etiqueta que se esta procesando</param> private void ProcessUbications(string xpath, InheritancePosition herencia, string valorReferencia, ConfigTagType tipoEtiqueta) { // Se obtiene el nodo base XmlNode nodoOrigen = _xmlConfigBase.SelectSingleNode(xpath); XmlNode nodoTemp = _xmlConfigBase.CreateNode(XmlNodeType.Element, _tmpValue, ""); nodoTemp.InnerXml = nodoOrigen.OuterXml; #region Xpath Referencia string strXpathRef = string.Empty; // Se realiza este proceso si se configura la etiqueta AntesDe o DespuesDe ya que se requiere hacer la consulta // para acomodar la etiqueta if (tipoEtiqueta == ConfigTagType.Section) { strXpathRef = string.Format("section[@id='{0}']", valorReferencia); } else if (tipoEtiqueta == ConfigTagType.Element) { strXpathRef = string.Format("element[@id='{0}']", valorReferencia); } #endregion if (herencia == InheritancePosition.Before) { XmlNode nodoReferencia = nodoOrigen.ParentNode.SelectSingleNode(strXpathRef); if (nodoReferencia != null) { nodoOrigen.ParentNode.InsertBefore(nodoTemp.FirstChild, nodoReferencia); nodoOrigen.ParentNode.RemoveChild(nodoOrigen); } } else if (herencia == InheritancePosition.After) { XmlNode nodoReferencia = nodoOrigen.ParentNode.SelectSingleNode(strXpathRef); if (nodoReferencia != null) { nodoOrigen.ParentNode.InsertAfter(nodoTemp.FirstChild, nodoReferencia); nodoOrigen.ParentNode.RemoveChild(nodoOrigen); } } }
/// <summary> /// Procesa el nodo hijo actual para agregarlo en la configuracion base y en caso de ser necesario reemplazar el de la base /// </summary> /// <param name="xpath">Xpath</param> /// <param name="nChildNode">Nodo de la configuracion hija</param> /// <param name="herencia">Posicion donde se hace la herencia</param> /// <param name="valorReferencia">Nombre de la etiqueta de referencia</param> /// <param name="tipoEtiqueta">Tipo de etiqueta que se esta procesando</param> private void ProcessNode(string xpath, XmlNode nChildNode, InheritancePosition herencia, string valorReferencia, ConfigTagType tipoEtiqueta) { #region Duplicate Node XmlNode nodoOrigen = _xmlConfigBase.SelectSingleNode(xpath); XmlNode nodoTemp = _xmlConfigBase.CreateNode(XmlNodeType.Element, _tmpValue, ""); nodoTemp.InnerXml = nChildNode.OuterXml; #endregion #region Xpath Referencia string strXpathRef = string.Empty; // Se realiza este proceso si se configura la etiqueta AntesDe o DespuesDe ya que se requiere hacer la consulta // para acomodar la etiqueta if (tipoEtiqueta == ConfigTagType.Section) { strXpathRef = string.Format("section[@id='{0}']", valorReferencia); } else if (tipoEtiqueta == ConfigTagType.Element) { strXpathRef = string.Format("element[@id='{0}']", valorReferencia); } #endregion #region Proceso si ya existe if (nodoOrigen != null) { // Si existe se sobreescribe if (herencia == InheritancePosition.NotApply) { nodoOrigen.ParentNode.InsertAfter(nodoTemp.FirstChild, nodoOrigen); } else if (herencia == InheritancePosition.Before) { XmlNode nodoReferencia = nodoOrigen.ParentNode.SelectSingleNode(strXpathRef); if (nodoReferencia == null) { nodoOrigen.ParentNode.InsertAfter(nodoTemp.FirstChild, nodoOrigen); } else { nodoOrigen.ParentNode.InsertBefore(nodoTemp.FirstChild, nodoReferencia); } } else if (herencia == InheritancePosition.After) { XmlNode nodoReferencia = nodoOrigen.ParentNode.SelectSingleNode(strXpathRef); if (nodoReferencia == null) { nodoOrigen.ParentNode.InsertAfter(nodoTemp.FirstChild, nodoOrigen); } else { nodoOrigen.ParentNode.InsertAfter(nodoTemp.FirstChild, nodoReferencia); } } nodoOrigen.ParentNode.RemoveChild(nodoOrigen); } #endregion #region Proceso si no existe else { // Se procesa el xpath para quedar ubicado en la etiqueta padre de la que se va a agregar xpath = xpath.ReverseString(); xpath = xpath.GetSafeSubstring(xpath.IndexOf('/') + 1).ReverseString(); nodoOrigen = _xmlConfigBase.SelectSingleNode(xpath); if (herencia == InheritancePosition.NotApply) { nodoOrigen.AppendChild(nodoTemp.FirstChild); } else if (herencia == InheritancePosition.Before) { XmlNode nodoReferencia = nodoOrigen.SelectSingleNode(strXpathRef); if (nodoReferencia == null) { nodoOrigen.AppendChild(nodoTemp.FirstChild); } else { nodoOrigen.InsertBefore(nodoTemp.FirstChild, nodoReferencia); } } else if (herencia == InheritancePosition.After) { XmlNode nodoReferencia = nodoOrigen.SelectSingleNode(strXpathRef); if (nodoReferencia == null) { nodoOrigen.AppendChild(nodoTemp.FirstChild); } else { nodoOrigen.InsertAfter(nodoTemp.FirstChild, nodoReferencia); } } } #endregion }