Ejemplo n.º 1
0
        public static string TruncateHtml(string text, int maxWordCount, bool decodeHtmlBeforeParsing)
        {
            if (decodeHtmlBeforeParsing)
            {
                text = HttpUtility.HtmlDecode(text);
            }

            text = "<body>" + text + "</body>";
            int wordsAvailable = maxWordCount;

            XmlDocument xml = new XmlDocument();

            xml.LoadXml("" + text + "");
            XPathNavigator navigator  = xml.CreateNavigator();
            XPathNavigator breakPoint = null;
            string         lastText   = string.Empty;

            // find the text node we need:
            while (navigator.MoveToFollowing(XPathNodeType.Text))
            {
                if (navigator.Value.Trim() != string.Empty)
                {
                    lastText = WordUtil.GetWordCount(navigator.Value.Trim()) > wordsAvailable
                        ? WordUtil.GetSubStringWords(wordsAvailable, navigator.Value.Trim())
                        : navigator.Value;
                }

                wordsAvailable = wordsAvailable - WordUtil.GetWordCount(navigator.Value);

                if (wordsAvailable <= 0)
                {
                    navigator.SetValue(lastText);
                    breakPoint = navigator.Clone();
                    break;
                }
            }

            //first remove text nodes
            while (navigator.MoveToFollowing(XPathNodeType.Text))
            {
                if (navigator.ComparePosition(breakPoint) == XmlNodeOrder.After)
                {
                    navigator.DeleteSelf();
                }
            }

            //// moves to parent, then move the rest
            navigator.MoveTo(breakPoint);
            while (navigator.MoveToFollowing(XPathNodeType.Element))
            {
                if (navigator.ComparePosition(breakPoint) == XmlNodeOrder.After)
                {
                    navigator.DeleteSelf();
                }
            }

            navigator.MoveToRoot();
            return(navigator.InnerXml);
        }
Ejemplo n.º 2
0
 public static void DeleteChildren(this XPathNavigator node)
 {
     while (node.MoveToFirstChild())
     {
         node.DeleteSelf();
     }
     while (node.MoveToFirstAttribute())
     {
         node.DeleteSelf();
     }
 }
Ejemplo n.º 3
0
 public static void RemoveStandardAttributes(XPathNavigator elementNav,
                                             string prefix, string urn)
 {
     if (elementNav != null)
     {
         bool bHasMoved = false;
         if (urn != string.Empty)
         {
             //delete standard atts
             bHasMoved = elementNav.MoveToAttribute(AppHelpers.Calculator.cId, urn);
             if (bHasMoved)
             {
                 elementNav.DeleteSelf();
             }
             bHasMoved = elementNav.MoveToAttribute("Name", urn);
             if (bHasMoved)
             {
                 elementNav.DeleteSelf();
             }
             bHasMoved = elementNav.MoveToAttribute("Label", urn);
             if (bHasMoved)
             {
                 elementNav.DeleteSelf();
             }
             bHasMoved = elementNav.MoveToAttribute("Description", urn);
             if (bHasMoved)
             {
                 elementNav.DeleteSelf();
             }
         }
         else
         {
             //delete id att
             bHasMoved = elementNav.MoveToAttribute(AppHelpers.Calculator.cId, string.Empty);
             if (bHasMoved)
             {
                 elementNav.DeleteSelf();
             }
             //delete name att
             bHasMoved = elementNav.MoveToAttribute("Name", string.Empty);
             if (bHasMoved)
             {
                 elementNav.DeleteSelf();
             }
             //delete label att
             bHasMoved = elementNav.MoveToAttribute("Label", string.Empty);
             if (bHasMoved)
             {
                 elementNav.DeleteSelf();
             }
             //delete description
             bHasMoved = elementNav.MoveToAttribute("Description", string.Empty);
             if (bHasMoved)
             {
                 elementNav.DeleteSelf();
             }
         }
     }
 }
Ejemplo n.º 4
0
 public void DeleteNil(XPathNavigator node)
 {
     if (node.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance"))
     {
         node.DeleteSelf();
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Updates the node replacing inheritdoc node with comments found.
        /// </summary>
        /// <param name="inheritDocNodeNavigator">Navigator for inheritdoc node</param>
        /// <param name="contentNodeNavigator">Navigator for content</param>
        private void UpdateNode(XPathNavigator inheritDocNodeNavigator, XPathNavigator contentNodeNavigator)
        {
            // retrieve the selection filter if specified.
            string selectValue = inheritDocNodeNavigator.GetAttribute("select", string.Empty);

            if (!string.IsNullOrEmpty(selectValue))
            {
                sourceExpression = XPathExpression.Compile(selectValue);
            }

            inheritDocNodeNavigator.MoveToParent();

            if (inheritDocNodeNavigator.LocalName != "comments" && inheritDocNodeNavigator.LocalName != "element")
            {
                sourceExpression = XPathExpression.Compile(inheritDocNodeNavigator.LocalName);
            }
            else
            {
                inheritDocNodeNavigator.MoveTo(this.sourceDocument.CreateNavigator().SelectSingleNode(inheritDocExpression));
            }

            XPathNodeIterator sources = (XPathNodeIterator)contentNodeNavigator.CreateNavigator().Evaluate(sourceExpression);

            inheritDocNodeNavigator.DeleteSelf();

            // append the source nodes to the target node
            foreach (XPathNavigator source in sources)
            {
                inheritDocNodeNavigator.AppendChild(source);
            }
        }
Ejemplo n.º 6
0
        private void InsertFlash(XmlDocument document, string key,
                                 XPathNavigator artLink, MediaTarget target)
        {
            if (_flashTargets == null)
            {
                _flashTargets = new List <MediaTarget>();
            }

            // evaluate the path
            string path = document.CreateNavigator().Evaluate(
                target.OutputXPath).ToString();

            if (target.baseOutputPath != null)
            {
                path = Path.Combine(target.baseOutputPath, path);
            }
            string outputPath = Path.Combine(path, target.Name);

            string targetDirectory = Path.GetDirectoryName(outputPath);

            if (!Directory.Exists(targetDirectory))
            {
                Directory.CreateDirectory(targetDirectory);
            }

            if (File.Exists(target.InputPath))
            {
                if (File.Exists(outputPath))
                {
                    File.SetAttributes(outputPath, FileAttributes.Normal);
                }

                File.Copy(target.InputPath, outputPath, true);
            }
            else
            {
                this.WriteMessage(MessageLevel.Warn, String.Format(
                                      "The file '{0}' for the art target '{1}' was not found.",
                                      target.InputPath, target.Id));
            }

            XmlWriter writer = artLink.InsertAfter();

            _flashTargets.Add(target);

            writer.WriteStartElement("div");   // start - div
            writer.WriteAttributeString("id", target.Id);

            if (!String.IsNullOrEmpty(target.Text))
            {
                writer.WriteStartElement("p");   // start - p
                writer.WriteString(target.Text);
                writer.WriteEndElement();        // end - p
            }

            writer.WriteEndElement();          // end - div
            writer.Close();

            artLink.DeleteSelf();
        }
        /// <summary>Deletes the annotation with the specified <see cref="P:System.Windows.Annotations.Annotation.Id" /> from the store. </summary>
        /// <param name="annotationId">The globally unique identifier (GUID) <see cref="P:System.Windows.Annotations.Annotation.Id" /> property of the annotation to be deleted.</param>
        /// <returns>The annotation that was deleted; otherwise, <see langword="null" /> if an annotation with the specified <paramref name="annotationId" /> was not found in the store.</returns>
        /// <exception cref="T:System.ObjectDisposedException">
        ///         <see cref="Overload:System.Windows.Annotations.Storage.AnnotationStore.Dispose" /> has been called on the store.</exception>
        /// <exception cref="T:System.InvalidOperationException">An I/O <see cref="T:System.IO.Stream" /> has not been set for the store.</exception>
        // Token: 0x0600636E RID: 25454 RVA: 0x001BF4E8 File Offset: 0x001BD6E8
        public override Annotation DeleteAnnotation(Guid annotationId)
        {
            Annotation annotation = null;
            object     syncRoot   = base.SyncRoot;

            lock (syncRoot)
            {
                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.DeleteAnnotationBegin);
                try
                {
                    this.CheckStatus();
                    annotation = this._storeAnnotationsMap.FindAnnotation(annotationId);
                    XPathNavigator annotationNodeForId = this.GetAnnotationNodeForId(annotationId);
                    if (annotationNodeForId != null)
                    {
                        if (annotation == null)
                        {
                            annotation = (Annotation)XmlStreamStore._serializer.Deserialize(annotationNodeForId.ReadSubtree());
                        }
                        annotationNodeForId.DeleteSelf();
                    }
                    this._storeAnnotationsMap.RemoveAnnotation(annotationId);
                }
                finally
                {
                    EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.DeleteAnnotationEnd);
                }
            }
            if (annotation != null)
            {
                this.OnStoreContentChanged(new StoreContentChangedEventArgs(StoreContentAction.Deleted, annotation));
            }
            return(annotation);
        }
        private void OnOptionsItem(string keyword, XPathNavigator navigator)
        {
            //<!-- Whether to include protected sealed members -->
            //<protectedSealed expose="false" />
            //<!-- Whether to include "no-PIA" COM types, aka types marked
            //     with TypeIdentifierAttribute and CompilerGeneratedAttribute -->
            //<noPIA expose="false" />

            string sandcastleDir = _context.SandcastleDirectory;

            XmlWriter writer = navigator.InsertAfter();

            // For the extension method addin...
            writer.WriteComment(" Whether to include protected sealed members ");
            writer.WriteStartElement("protectedSealed");   // start: protectedSealed
            writer.WriteAttributeString("expose", "true");
            writer.WriteEndElement();                      // end: protectedSealed

            // For the XAML attached members addin...
            writer.WriteComment(
                " Whether to include \"no-PIA\" COM types, aka types marked with TypeIdentifierAttribute and CompilerGeneratedAttribute ");
            writer.WriteStartElement("noPIA");   // start: noPIA
            writer.WriteAttributeString("expose", "false");
            writer.WriteEndElement();            // end: noPIA

            writer.Close();
            navigator.DeleteSelf();
        }
Ejemplo n.º 9
0
        private void Sell_Clicked(object sender, EventArgs e)
        {
            Button btn = ((Button)sender);
            string id  = btn.Name.Replace(_acceptButtonPrefix, String.Empty);

            Control       ctrl = pnlNotifications.Controls.Find(_numericPrefix + id, true)[0];
            NumericUpDown num  = ((NumericUpDown)ctrl);

            XmlDocument xDoc = new XmlDocument();

            xDoc.Load(Global.NotificationXml);

            XPathNavigator xNotifNav = xDoc.CreateNavigator().SelectSingleNode(String.Format("Notifications/RequestSell[@ID='{0}']", id));

            CharacterUpdate.RemoveItemFromCharacter(xNotifNav.SelectSingleNode("@Item").Value, id, xNotifNav.SelectSingleNode("@Character").Value);
            CharacterUpdate.AddItemToCharacter(null, "Cash", null, xNotifNav.SelectSingleNode("@Character").Value, Convert.ToInt32(num.Value));

            xNotifNav.DeleteSelf();

            while (Global.IsFileLocked(Global.NotificationXml))
            {
                Thread.Sleep(1000);
            }
            FileStream lvFS = new FileStream(Global.NotificationXml, FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite);

            xDoc.Save(lvFS);
            lvFS.Close();
        }
        public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string contentType)
        {
            var sr           = new StreamReader(stream);
            var wireResponse = sr.ReadToEnd();

            // Fix for Xml external entity injection violation in fortify report
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.DtdProcessing = DtdProcessing.Prohibit;
            settings.XmlResolver   = null;

            XmlDocument doc    = new XmlDocument();
            XmlReader   reader = XmlReader.Create(new StringReader(wireResponse), settings);

            doc.Load(reader);
            //We need to get rid of the security header because it is not signed by the web service.
            //The whole reason for the custom Encoder is to do this. the client rejected the unsigned header.
            //Our WCF client is set up to allow the absence of a security header but if the header exists then it must be signed.
            //Hopefully the namespace will not change. Maybe it should be put in a config.
            XPathNavigator n = doc.CreateNavigator();

            if (n.MoveToFollowing("Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"))
            {
                n.DeleteSelf();
            }
            reader = XmlReader.Create(new StringReader(doc.InnerXml), settings);
            return(Message.CreateMessage(reader, maxSizeOfHeaders, MessageVersion.Soap11));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// This specifies the conceptual topic keywords metadata.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        protected void OnMetadataKeywordsItem(string keyword, XPathNavigator navigator)
        {
            BuildContext context = this.Context;

            BuildGroupContext groupContext = context.GroupContexts[_group.Id];

            if (groupContext == null)
            {
                throw new BuildException(
                          "The group context is not provided, and it is required by the build system.");
            }

            //<copy base=".\XmlComp" file="concat($key,'.cmp.xml')"
            //      source="/metadata/topic[@id=$key]/*" target="/document/metadata" />
            XmlWriter xmlWriter = navigator.InsertAfter();

            // For now, lets simply write the default...
            xmlWriter.WriteStartElement("copy");
            xmlWriter.WriteAttributeString("base", String.Format(
                                               @".\{0}", groupContext["$DdueXmlCompDir"]));
            xmlWriter.WriteAttributeString("file", @"concat($key,'.cmp.xml')");
            xmlWriter.WriteAttributeString("source", @"/metadata/topic[@id=$key]/*");
            xmlWriter.WriteAttributeString("target", @"/document/metadata");
            xmlWriter.WriteEndElement();

            xmlWriter.Close();
            navigator.DeleteSelf();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// This specifies the token items used by the conceptual topics.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        protected void OnTokensReplacedItem(string keyword, XPathNavigator navigator)
        {
            if (_group == null)
            {
                throw new BuildException(
                          "There is not build group to provide the media/arts contents.");
            }

            bool replaceTokens = true;

            ConceptualPreTransConfiguration preTrans = _engineSettings.PreTrans;

            if (preTrans != null && preTrans.ResolveTokens)
            {
                replaceTokens = false;
            }

            if (replaceTokens)
            {
                XmlWriter xmlWriter = navigator.InsertAfter();

                // <replace elements="/*//ddue:token[text()!='autoOutline']" item="string(.)" />
                xmlWriter.WriteStartElement("replace");
                xmlWriter.WriteAttributeString("elements", @"/*//ddue:token[text()!='autoOutline']");
                xmlWriter.WriteAttributeString("item", "string(.)");
                xmlWriter.WriteEndElement();

                xmlWriter.Close();
            }

            navigator.DeleteSelf();
        }
        /// <summary>
        /// Updates the node replacing inheritdoc node with comments found.
        /// </summary>
        /// <param name="inheritDocNodeNavigator">Navigator for inheritdoc node</param>
        /// <param name="contentNodeNavigator">Navigator for content</param>
        private void UpdateNode(XPathNavigator inheritDocNodeNavigator, XPathNavigator contentNodeNavigator)
        {
            // retrieve the selection filter if specified.
            string selectValue = inheritDocNodeNavigator.GetAttribute("select", String.Empty);

            if (!String.IsNullOrEmpty(selectValue))
            {
                this.WriteMessage(MessageLevel.Info, "Filter: " + selectValue);
                sourceExpression = XPathExpression.Compile(selectValue);
            }

            inheritDocNodeNavigator.MoveToParent();

            bool isInnerText = false;

            if (inheritDocNodeNavigator.LocalName != "comments" &&
                inheritDocNodeNavigator.LocalName != "element")
            {
                sourceExpression = XPathExpression.Compile(inheritDocNodeNavigator.LocalName);

                isInnerText = true;
            }
            else
            {
                inheritDocNodeNavigator.MoveTo(
                    this.sourceDocument.CreateNavigator().SelectSingleNode(inheritDocExpression));
            }

            XPathNodeIterator sources =
                (XPathNodeIterator)contentNodeNavigator.CreateNavigator().Evaluate(sourceExpression);

            if (isInnerText && sources.Count == 1)
            {
                //inheritDocNodeNavigator.DeleteSelf();
                inheritDocNodeNavigator.MoveTo(
                    this.sourceDocument.CreateNavigator().SelectSingleNode(inheritDocExpression));

                // append the source nodes to the target node
                foreach (XPathNavigator source in sources)
                {
                    inheritDocNodeNavigator.ReplaceSelf(source.InnerXml);
                }
            }
            else
            {
                inheritDocNodeNavigator.DeleteSelf();

                // append the source nodes to the target node
                foreach (XPathNavigator source in sources)
                {
                    XPathNodeIterator childIterator = inheritDocNodeNavigator.SelectChildren(
                        source.Name, String.Empty);
                    if (childIterator.Count == 0)
                    {
                        inheritDocNodeNavigator.AppendChild(source);
                    }
                }
            }
        }
Ejemplo n.º 14
0
        public IXPathNavigable AddRunSettings(IXPathNavigable runSettingDocument,
                                              IRunSettingsConfigurationInfo configurationInfo, ILogger logger)
        {
            XPathNavigator runSettingsNavigator = runSettingDocument.CreateNavigator();

            Debug.Assert(runSettingsNavigator != null, "userRunSettingsNavigator == null!");
            if (!runSettingsNavigator.MoveToChild(Constants.RunSettingsName, ""))
            {
                logger.Log(MessageLevel.Warning, "RunSettingsDocument does not contain a RunSettings node! Canceling settings merging...");
                return(runSettingsNavigator);
            }

            var settingsContainer = new RunSettingsContainer();

            settingsContainer.SolutionSettings = new RunSettings();

            if (CopyToUnsetValues(runSettingsNavigator, settingsContainer))
            {
                runSettingsNavigator.DeleteSelf(); // this node is to be replaced by the final run settings
            }

            string solutionRunSettingsFile = GetSolutionSettingsXmlFile();

            try
            {
                if (File.Exists(solutionRunSettingsFile))
                {
                    var            solutionRunSettingsDocument  = new XPathDocument(solutionRunSettingsFile);
                    XPathNavigator solutionRunSettingsNavigator = solutionRunSettingsDocument.CreateNavigator();
                    if (solutionRunSettingsNavigator.MoveToChild(Constants.RunSettingsName, ""))
                    {
                        CopyToUnsetValues(solutionRunSettingsNavigator, settingsContainer);
                    }
                    else
                    {
                        logger.Log(MessageLevel.Warning, $"Solution test settings file found at '{solutionRunSettingsFile}', but does not contain {Constants.RunSettingsName} node");
                    }
                }
            }
            catch (Exception e)
            {
                logger.Log(MessageLevel.Warning,
                           $"Solution test settings file could not be parsed, check file: {solutionRunSettingsFile}{Environment.NewLine}Exception: {e}");
            }

            foreach (var projectSettings in settingsContainer.ProjectSettings)
            {
                projectSettings.GetUnsetValuesFrom(settingsContainer.SolutionSettings);
            }

            GetValuesFromGlobalSettings(settingsContainer);

            runSettingsNavigator.MoveToChild(Constants.RunSettingsName, "");
            runSettingsNavigator.AppendChild(settingsContainer.ToXml().CreateNavigator());

            runSettingsNavigator.MoveToRoot();
            return(runSettingsNavigator);
        }
        private void ApplyXsd(XPathNavigator documentNavigator, string key)
        {
            if (!_isIndexEnabled)
            {
                return;
            }

            XPathNodeIterator iterator = documentNavigator.Select(_xsdLinksSelector);

            if (iterator == null || iterator.Count == 0)
            {
                return;
            }
            XPathNavigator[] navigators =
                BuildComponentUtilities.ConvertNodeIteratorToArray(iterator);

            string topicType = _indexContent.TopicType;
            int    itemCount = navigators.Length;

            for (int i = 0; i < itemCount; i++)
            {
                XPathNavigator navigator = navigators[i];

                string linkUri = navigator.Value;
                if (!String.IsNullOrEmpty(linkUri))
                {
                    IndexItem item = _indexContent[linkUri];

                    if (item == null)
                    {
                        this.WriteMessage(MessageLevel.Warn, String.Format(
                                              "Link value for '{0}' in '{1}' not found",
                                              linkUri, key));
                    }
                    else
                    {
                        XmlWriter writer = navigator.InsertAfter();
                        writer.WriteStartElement("link", IndexResolver.MamlNamespace);
                        writer.WriteAttributeString("href", IndexResolver.XLinkNamespace, item.Id);
                        if (!String.IsNullOrEmpty(topicType))
                        {
                            writer.WriteAttributeString("topicType_id", topicType);
                        }
                        writer.WriteString(item.LinkTitle);
                        writer.WriteEndElement();

                        writer.Close();
                    }
                }
                else
                {
                    this.WriteMessage(MessageLevel.Warn, String.Format(
                                          "A link value in '{0}' is not specified.", key));
                }
                navigator.DeleteSelf();
            }
        }
Ejemplo n.º 16
0
        protected void OnSyntaxGeneratorsItem(string keyword, XPathNavigator navigator)
        {
            XmlWriter xmlWriter = navigator.InsertAfter();

            this.WriteSyntaxGenerators(xmlWriter, _group.SyntaxUsage);

            xmlWriter.Close();
            navigator.DeleteSelf();
        }
Ejemplo n.º 17
0
 static void RemoveAttr(XPathNavigator node, string attr)
 {
     node = node.Clone();
     if (!node.MoveToAttribute(attr, string.Empty))
     {
         return;
     }
     node.DeleteSelf();
 }
        private void OnAttributeFilterItem(string keyword, XPathNavigator navigator)
        {
            ReferenceRootFilter attributeFilters = _group.Content.AttributeFilters;

            // If there is customization of the attribute filters, we use it...
            if (attributeFilters != null && attributeFilters.Count != 0)
            {
                XmlWriter writer = navigator.InsertAfter();

                //<attributeFilter expose="true">
                //  <namespace name="System.Diagnostics" expose="false">
                //    <type name="ConditionalAttribute" expose="true" />
                //  </namespace>
                //  <namespace name="System.Xml.Serialization" expose="false" />
                //</attributeFilter>
                writer.WriteStartElement("attributeFilter");
                writer.WriteAttributeString("expose", "true");

                int itemNamespaces = attributeFilters.Count;
                for (int i = 0; i < itemNamespaces; i++)
                {
                    ReferenceNamespaceFilter namespaceFilter = attributeFilters[i];
                    if (namespaceFilter == null)
                    {
                        continue;
                    }
                    namespaceFilter.WriteXml(writer);
                }

                writer.WriteEndElement();

                writer.Close();
            }
            else  //...otherwise, we put in the default atttribute filters...
            {
                // Write the defaults...
                if (String.IsNullOrEmpty(_defaultAttrFile) == false &&
                    File.Exists(_defaultAttrFile))
                {
                    XmlReaderSettings settings = new XmlReaderSettings();
                    settings.IgnoreWhitespace = true;
                    settings.IgnoreComments   = false;
                    settings.CloseInput       = true;

                    using (XmlReader xmlReader = XmlReader.Create(
                               _defaultAttrFile, settings))
                    {
                        if (xmlReader.IsStartElement("attributeFilter"))
                        {
                            navigator.InsertAfter(xmlReader);
                        }
                    }
                }
            }

            navigator.DeleteSelf();
        }
Ejemplo n.º 19
0
        internal static void RemoveChildNode(XPathNavigator parentNavigator, string nodeXPath, string childName)
        {
            var childNodeNavigator = parentNavigator.SelectSingleNode(nodeXPath);

            if (childNodeNavigator != null)
            {
                parentNavigator.MoveToChild(childName, string.Empty);
                parentNavigator.DeleteSelf();
            }
        }
        /// <summary>
        /// Deletes the specified node and logs the message.
        /// </summary>
        /// <param name="inheritDocNodeNavigator">navigator for inheritdoc node</param>
        /// <param name="key">Id of the topic specified</param>
        public void DeleteNode(XPathNavigator inheritDocNodeNavigator, string key)
        {
            if (_messageWriter != null)
            {
                _messageWriter.Write(this.GetType(), MessageLevel.Info, String.Format(
                                         CultureInfo.InvariantCulture, "Comments are not found for topic:{0}", key));
            }

            inheritDocNodeNavigator.DeleteSelf();
        }
Ejemplo n.º 21
0
        private void ChangeMachineConfig(string machineConfig)
        {
            MachineConfigXmlDocument doc = new MachineConfigXmlDocument(machineConfig);

            if (doc.Exists == false)
            {
                return;
            }

            //System.Windows.Forms.MessageBox.Show(
            //    "Changing " + doc.machineConfigFilename, "ChangeMachineConfig");

            doc.Load();               // load machine.config as XML document

            // locate the "DbProviderFactories" element
            XPathNavigator navigator = doc.CreateNavigator(dbProviderFactoriesPath);

            if (navigator == null)
            {
                //System.Windows.Forms.MessageBox.Show(
                //    "Could not locate \"DbProviderFactories\" element!!",
                //    "ChangeMachineConfig");
                return;                  // something is very wrong if we can't find the DB Providers
            }

            // locate the old <add name="Ingres Data Provider" ... />
            XPathNavigator providerNavigator =
                FindChildElement(navigator, ingresProviderSearchKeys);

            if (providerNavigator != null)
            {
                //System.Windows.Forms.MessageBox.Show(
                //    "DeletingSelf the old <add name=\"Ingres Data Provider\"...",
                //    "ChangeMachineConfig");
                ingresProviderElementOld = providerNavigator.OuterXml;
                providerNavigator.DeleteSelf();                  // if found, delete the old entry
            }
            else
            {
                //System.Windows.Forms.MessageBox.Show(
                //    "Could not locate the old <add name=\"Ingres Data Provider\"...",
                //    "ChangeMachineConfig");
            }

            // create the <add name="Ingres Data Provider" invariant="Ingres.Client" ...
            if (ingresProviderElementNew != null)
            {
                //System.Windows.Forms.MessageBox.Show(
                //    "Creating the new <add name=\"Ingres Data Provider\"...",
                //    "ChangeMachineConfig");
                navigator.AppendChild(ingresProviderElementNew);
            }

            doc.Save();              // save the machine.config
        }
Ejemplo n.º 22
0
 public static void RemoveAllAttributes(XPathNavigator toNav)
 {
     if (toNav.HasAttributes)
     {
         while (toNav.MoveToFirstAttribute())
         {
             toNav.DeleteSelf();
         }
         //will move to parent when last att is deleted
     }
 }
Ejemplo n.º 23
0
 public static void DeleteAttribute(string attName, ref XPathNavigator selectedElementNav)
 {
     if (selectedElementNav.HasAttributes)
     {
         bool bHasMoved = selectedElementNav.MoveToAttribute(attName, string.Empty);
         if (bHasMoved == true)
         {
             //if successful, repositions on parent
             selectedElementNav.DeleteSelf();
         }
     }
 }
Ejemplo n.º 24
0
 private static void DeleteChildrenNodes(XPathNavigator oElementNav,
                                         ref bool hasDeletions)
 {
     if (oElementNav.HasChildren)
     {
         oElementNav.MoveToFirstChild();
         oElementNav.DeleteSelf();
         hasDeletions = true;
         //recurse to delete remaining children
         DeleteChildrenNodes(oElementNav, ref hasDeletions);
     }
 }
Ejemplo n.º 25
0
        private void xoadata()
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(@"D:\source\Phuc\Phuc\bin\Debug\Sinhvien.xml");
            XPathNavigator nav      = doc.CreateNavigator();
            XPathNavigator sinhvien = nav.SelectSingleNode("Sinhvien/sinhvien[@xID='" + Idtxt.Text + "']");

            sinhvien.DeleteSelf();
            doc.Save(@"D:\source\Phuc\Phuc\bin\Debug\Sinhvien.xml");
            loaddata();
        }
Ejemplo n.º 26
0
        private void xoadata()
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(@"E:\WFC#\Tam\Tam\bin\Debug\Sinhvien.xml");
            XPathNavigator nav      = doc.CreateNavigator();
            XPathNavigator sinhvien = nav.SelectSingleNode("Sinhvien/sinhvien[@xID='" + textBox5.Text + "']");

            sinhvien.DeleteSelf();
            doc.Save(@"E:\WFC#\Tam\Tam\bin\Debug\Sinhvien.xml");
            loaddata();
        }
Ejemplo n.º 27
0
        public void DeleteSelfAttribute()
        {
            // bug #376210.
            XmlDocument document = new XmlDocument();

            document.LoadXml("<test><node date='2000-12-23'>z</node></test>");
            XPathNavigator navigator   = document.CreateNavigator();
            XPathNavigator nodeElement = navigator.SelectSingleNode("//node");

            nodeElement.MoveToAttribute("date", String.Empty);
            nodeElement.DeleteSelf();
            Assert.AreEqual("<test><node>z</node></test>", document.OuterXml);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Delete student for Xml document
        /// </summary>
        /// <param name="id">id of student</param>
        public static void XDelete(string id)
        {
            string path = @"C:\Users\Anh Sky\source\repos\WindowsFormsApp1\WindowsFormsApp1\Data.xml";

            XmlDocument editDoc = new XmlDocument();

            editDoc.Load(path);
            XPathNavigator editNav = editDoc.CreateNavigator();
            XPathNavigator student = editNav.SelectSingleNode($"students/student[id='{id}']");

            student.DeleteSelf();
            editDoc.Save(path);
        }
        private void OnAddinsItem(string keyword, XPathNavigator navigator)
        {
            //...
            //<addins>
            //  <addin type="Microsoft.Ddue.Tools.XamlAttachedMembersAddIn"
            //       assembly="MRefBuilder.exe" />
            //</addins>

            XmlWriter writer = navigator.InsertAfter();

            writer.WriteStartElement("addins");  // start: addins

            if (!String.IsNullOrEmpty(_assistComponents) &&
                File.Exists(_assistComponents))
            {
                // For the extension method addin...
                writer.WriteStartElement("addin");   // start: addin
                writer.WriteAttributeString("type", "Microsoft.Ddue.Tools.ExtensionMethodAddIn");
                writer.WriteAttributeString("assembly", _assistComponents);
                writer.WriteEndElement();            // end: addin

                // For the XAML attached members addin...
                writer.WriteStartElement("addin");   // start: addin
                writer.WriteAttributeString("type", "Microsoft.Ddue.Tools.XamlAttachedMembersAddIn");
                writer.WriteAttributeString("assembly", _assistComponents);
                writer.WriteEndElement();            // end: addin
            }
            else
            {
                string sandcastleDir = _context.SandcastleDirectory;

                // For the extension method addin...
                writer.WriteStartElement("addin");   // start: addin
                writer.WriteAttributeString("type", "Microsoft.Ddue.Tools.ExtensionMethodAddIn");
                writer.WriteAttributeString("assembly", Path.Combine(sandcastleDir,
                                                                     @"ProductionTools\MRefBuilder.exe"));
                writer.WriteEndElement();            // end: addin

                // For the XAML attached members addin...
                writer.WriteStartElement("addin");   // start: addin
                writer.WriteAttributeString("type", "Microsoft.Ddue.Tools.XamlAttachedMembersAddIn");
                writer.WriteAttributeString("assembly", Path.Combine(sandcastleDir,
                                                                     @"ProductionTools\MRefBuilder.exe"));
                writer.WriteEndElement();            // end: addin
            }

            writer.WriteEndElement();            // end: addins

            writer.Close();
            navigator.DeleteSelf();
        }
Ejemplo n.º 30
0
        /// <summary>
        /// This specifies the main conceptual XSL transform file and related information.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        protected void OnTransformsItem(string keyword, XPathNavigator navigator)
        {
            string transform = _style.GetTransform(BuildEngineType.Reference);

            if (String.IsNullOrEmpty(transform))
            {
                throw new BuildException("A document transformer is required.");
            }

            //<transform file="%DXROOT%\Presentation\Vs2005\transforms\main_conceptual.xsl">
            //<argument key="metadata" value="true" />
            //<argument key="languages">
            //    <language label="VisualBasic" name="VisualBasic" style="vb" />
            //    <language label="CSharp" name="CSharp" style="cs" />
            //    <language label="ManagedCPlusPlus" name="ManagedCPlusPlus" style="cpp" />
            //    <language label="JSharp" name="JSharp" style="cs" />
            //    <language label="JScript" name="JScript" style="cs" />
            //</argument>
            //<argument key="RTMReleaseDate" value="June 2007" />
            //</transform>
            XmlWriter xmlWriter = navigator.InsertAfter();

            // For now, lets simply write the default...
            xmlWriter.WriteStartElement("transform");   // start - transform
            xmlWriter.WriteAttributeString("file", transform);

            xmlWriter.WriteStartElement("argument");    // start - argument/metadata
            xmlWriter.WriteAttributeString("key", "metadata");
            xmlWriter.WriteAttributeString("value", "true");
            xmlWriter.WriteEndElement();                // end - argument/metadata

            xmlWriter.WriteStartElement("argument");    // start - argument/languages
            xmlWriter.WriteAttributeString("key", "languages");

            WriteSyntaxTypes(xmlWriter, _group.SyntaxUsage);

            xmlWriter.WriteEndElement();                // end - argument/languages

            if (_settings.ShowUpdatedDate)
            {
                xmlWriter.WriteStartElement("argument");    // start - argument/RTMReleaseDate
                xmlWriter.WriteAttributeString("key", "RTMReleaseDate");
                xmlWriter.WriteAttributeString("value", DateTime.Now.ToString());
                xmlWriter.WriteEndElement();                // end - argument/RTMReleaseDate
            }

            xmlWriter.WriteEndElement();                // end - transform

            xmlWriter.Close();
            navigator.DeleteSelf();
        }