/// <summary>
        /// Moves the current element pointer to the next element with the specified tag at the same level.
        /// </summary>
        /// <param name="nextTag">The tag to find.</param>
        /// <returns>True if successful, false otherwise.</returns>
        public bool jumpToNextElement(NSFString nextTag)
        {
            errorStatus = ErrorStatus.NoError;

            if (currentElement == null)
            {
                errorStatus = ErrorStatus.EmptyDocument;
                return(false);
            }

            if (currentElement == rootElement)
            {
                errorStatus = ErrorStatus.EmptyElement;
                return(false);
            }

            NSFXMLElement nextElement = currentElement.getParentElement().getNextElement(currentElement, nextTag);

            if (nextElement == null)
            {
                errorStatus = ErrorStatus.EmptyElement;
                return(false);
            }

            currentElement = nextElement;

            return(true);
        }
        /// <summary>
        /// Deletes the current element.
        /// </summary>
        /// <returns>True if successful, false otherwise.</returns>
        public bool deleteCurrentElement()
        {
            errorStatus = ErrorStatus.NoError;

            if (currentElement == null)
            {
                errorStatus = ErrorStatus.EmptyDocument;
                return(false);
            }

            if (currentElement == rootElement)
            {
                rootElement     = null;
                bookmarkElement = null;
                currentElement  = null;

                return(true);
            }

            if (bookmarkElement == currentElement)
            {
                bookmarkElement = null;
            }

            NSFXMLElement deleteElement = currentElement;

            currentElement = currentElement.getParentElement();
            currentElement.deleteChildElement(deleteElement);

            return(true);
        }
예제 #3
0
        /// <summary>
        /// Parses the element's child elements.
        /// </summary>
        /// <param name="buffer">The string buffer to parse.</param>
        /// <param name="readPosition">The read position to start from.</param>
        /// <returns>True if successful, false otherwise.</returns>
        private bool parseChildElements(NSFString buffer, ref int readPosition)
        {
            while (true)
            {
                if (!skipWhitespace(buffer, ref readPosition))
                {
                    return(false);
                }

                if (buffer.Length < readPosition + 2)
                {
                    return(false);
                }

                // Check for child elements
                if ((buffer[readPosition] == '<') && (buffer[readPosition + 1] != '/'))
                {
                    NSFXMLElement newElement = new NSFXMLElement();

                    if (!newElement.loadBuffer(buffer, ref readPosition))
                    {
                        return(false);
                    }

                    addChildElementBack(newElement);

                    continue;
                }

                return(true);
            }
        }
        /// <summary>
        /// Creates an xml element.
        /// </summary>
        /// <param name="copyElement">The element to copy.</param>
        public NSFXMLElement(NSFXMLElement copyElement)
        {
            Tag = copyElement.Tag;
            Text = copyElement.Text;

            foreach (NSFXMLElement element in copyElement.childElements)
            {
                addChildElementBack(new NSFXMLElement(element));
            }
        }
예제 #5
0
        /// <summary>
        /// Creates an xml element.
        /// </summary>
        /// <param name="copyElement">The element to copy.</param>
        public NSFXMLElement(NSFXMLElement copyElement)
        {
            Tag  = copyElement.Tag;
            Text = copyElement.Text;

            foreach (NSFXMLElement element in copyElement.childElements)
            {
                addChildElementBack(new NSFXMLElement(element));
            }
        }
 /// <summary>
 /// Adds an element to the back of the current element's child elements
 /// </summary>
 /// <param name="childTag">The tag for the element.</param>
 public void addChildElementBack(NSFString childTag)
 {
     if (rootElement == null)
     {
         rootElement     = new NSFXMLElement(childTag);
         currentElement  = rootElement;
         bookmarkElement = rootElement;
     }
     else
     {
         currentElement.addChildElementBack(new NSFXMLElement(childTag));
     }
 }
        /// <summary>
        /// Adds a root element and sets the current element and bookmark element to the root element.
        /// </summary>
        public void addRootElement(NSFString rootTag)
        {
            NSFXMLElement newElement = new NSFXMLElement(rootTag, String.Empty);

            if (rootElement != null)
            {
                newElement.addChildElementFront(rootElement);
            }

            rootElement     = newElement;
            bookmarkElement = rootElement;
            currentElement  = rootElement;
        }
        /// <summary>
        /// Adds an element to the front of the current element's child elements
        /// </summary>
        /// <param name="childElement">The element to add.</param>
        /// <returns>True if successful, false otherwise.</returns>
        public bool addChildElementFront(NSFXMLElement childElement)
        {
            if (rootElement == null)
            {
                rootElement     = childElement;
                currentElement  = rootElement;
                bookmarkElement = rootElement;
                return(true);
            }

            currentElement.addChildElementFront(childElement);
            return(true);
        }
 /// <summary>
 /// Adds an element to the front of the current element's child elements
 /// </summary>
 /// <param name="childTag">The tag for the element.</param>
 /// <param name="childText">The text for the element.</param>
 public void addChildElementFront(NSFString childTag, NSFString childText)
 {
     if (rootElement == null)
     {
         rootElement     = new NSFXMLElement(childTag, childText);
         currentElement  = rootElement;
         bookmarkElement = rootElement;
     }
     else
     {
         currentElement.addChildElementFront(new NSFXMLElement(childTag, childText));
     }
 }
        /// <summary>
        /// Populates the document with xml from specified xml document.
        /// </summary>
        /// <param name="copyDocument">The file to copy.</param>
        public void loadDocument(NSFXMLDocument copyDocument)
        {
            rootElement     = null;
            bookmarkElement = null;
            currentElement  = null;

            if (copyDocument.rootElement != null)
            {
                rootElement     = new NSFXMLElement(copyDocument.rootElement);
                bookmarkElement = rootElement;
                currentElement  = rootElement;
            }
        }
예제 #11
0
        /// <summary>
        /// Gets the next child element after the specified child element.
        /// </summary>
        /// <param name="childElement">The child element before the returned child element.</param>
        /// <returns>The child element, or NULL if none exist.</returns>
        public NSFXMLElement getNextElement(NSFXMLElement childElement)
        {
            bool returnNext = false;

            foreach (NSFXMLElement element in childElements)
            {
                if (returnNext)
                {
                    return(element);
                }

                if (element == childElement)
                {
                    returnNext = true;
                }
            }

            return(null);
        }
        /// <summary>
        /// Adds a trace to the log.
        /// </summary>
        /// <param name="type">The type of the trace.</param>
        /// <param name="tag1">The first tag associated with the trace.</param>
        /// <param name="data1">The data associated with the first tag.</param>
        /// <param name="tag2">The second tag associated with the trace.</param>
        /// <param name="data2">The data associated with the second tag.</param>
        /// <param name="tag3">The third tag associated with the trace.</param>
        /// <param name="data3">The data associated with the third tag.</param>
        public void addTrace(NSFString type, NSFString tag1, NSFString data1, NSFString tag2, NSFString data2, NSFString tag3, NSFString data3)
        {
            // If logging is not enabled then return without action
            if (!enabled)
            {
                return;
            }

            // Lock to prevent events from being added to the queue with timestamps out of order
            lock (traceLogMutex)
            {
                try
                {
                    // Create the new trace element
                    NSFXMLElement trace = new NSFXMLElement(TraceTag);

                    // Add the time
                    trace.addChildElementBack(new NSFXMLElement(TimeTag, NSFTimerThread.PrimaryTimerThread.CurrentTime.ToString()));

                    // Add a trace for the type
                    NSFXMLElement typeTrace = new NSFXMLElement(type);
                    trace.addChildElementBack(typeTrace);

                    // Add the new data under the type element;
                    typeTrace.addChildElementBack(new NSFXMLElement(tag1, data1));

                    if (tag2 != null)
                    {
                        typeTrace.addChildElementBack(new NSFXMLElement(tag2, data2));
                    }
                    if (tag3 != null)
                    {
                        typeTrace.addChildElementBack(new NSFXMLElement(tag3, data3));
                    }

                    eventHandler.queueEvent(traceAddEvent.copy(trace));
                }
                catch
                {
                    // If unable to add a trace, just do nothing, because calling the exception handler may result in an infinite loop
                }
            }
        }
예제 #13
0
        /// <summary>
        /// Gets the next child element after the specified child element, with the specified tag.
        /// </summary>
        /// <param name="childElement">The child element before the returned child element.</param>
        /// <param name="nextTag">The child element tag.</param>
        /// <returns>The child element, or NULL if none exist.</returns>
        public NSFXMLElement getNextElement(NSFXMLElement childElement, NSFString nextTag)
        {
            bool returnNext = false;

            foreach (NSFXMLElement element in childElements)
            {
                if (returnNext)
                {
                    if (element.Tag == nextTag)
                    {
                        return(element);
                    }
                }
                else if (element == childElement)
                {
                    returnNext = true;
                }
            }

            return(null);
        }
        /// <summary>
        /// Adds an xml document to the front of the current element's child elements
        /// </summary>
        /// <param name="document">The document to add.</param>
        /// <returns>True if successful, false otherwise.</returns>
        public bool addChildElementFront(NSFXMLDocument document)
        {
            if (document.rootElement == null)
            {
                errorStatus = ErrorStatus.EmptyElement;
                return(false);
            }

            if (rootElement == null)
            {
                rootElement     = new NSFXMLElement(document.rootElement);
                currentElement  = rootElement;
                bookmarkElement = rootElement;
            }
            else
            {
                currentElement.addChildElementFront(new NSFXMLElement(document.rootElement));
            }

            return(true);
        }
        /// <summary>
        /// Moves the current element pointer to the first child element of the current element.
        /// </summary>
        /// <returns>True if successful, false otherwise.</returns>
        public bool jumpToChildElementFront()
        {
            errorStatus = ErrorStatus.NoError;

            if (currentElement == null)
            {
                errorStatus = ErrorStatus.EmptyDocument;
                return(false);
            }

            NSFXMLElement childElement = currentElement.getChildElementFront();

            if (childElement == null)
            {
                errorStatus = ErrorStatus.EmptyElement;
                return(false);
            }

            currentElement = childElement;

            return(true);
        }
        /// <summary>
        /// Moves the current element pointer to the parent of the current element with the specified tag.
        /// </summary>
        /// <param name="parentTag">The tag to find.</param>
        /// <returns>True if successful, false otherwise.</returns>
        public bool jumpToParentElement(NSFString parentTag)
        {
            errorStatus = ErrorStatus.NoError;

            if (currentElement == null)
            {
                errorStatus = ErrorStatus.EmptyDocument;
                return(false);
            }

            NSFXMLElement parentElement = currentElement.getParentElement(parentTag);

            if (parentElement == null)
            {
                errorStatus = ErrorStatus.EmptyElement;
                return(false);
            }

            currentElement = parentElement;

            return(true);
        }
        /// <summary>
        /// Populates the document with xml formatted text in the specified buffer.
        /// </summary>
        /// <param name="buffer">The buffer to load.</param>
        /// <returns>True if successful, false otherwise.</returns>
        public bool loadBuffer(NSFString buffer)
        {
            errorStatus = ErrorStatus.NoError;

            rootElement     = null;
            bookmarkElement = null;
            currentElement  = null;

            rootElement = new NSFXMLElement();

            if (!rootElement.loadBuffer(buffer))
            {
                rootElement = null;
                errorStatus = ErrorStatus.ParseError;
                return(false);
            }

            bookmarkElement = rootElement;
            currentElement  = rootElement;

            return(true);
        }
 /// <summary>
 /// Adds an element to the back of the child element list.
 /// </summary>
 public void addChildElementBack(NSFXMLElement childElement)
 {
     childElement.parentElement = this;
     childElements.AddLast(childElement);
 }
예제 #19
0
 /// <summary>
 /// Deletes the specified child element.
 /// </summary>
 /// <param name="childElement">The element to delete.</param>
 public void deleteChildElement(NSFXMLElement childElement)
 {
     childElements.Remove(childElement);
 }
예제 #20
0
 /// <summary>
 /// Adds an element to the front of the child element list.
 /// </summary>
 public void addChildElementFront(NSFXMLElement childElement)
 {
     childElement.parentElement = this;
     childElements.AddFirst(childElement);
 }
        /// <summary>
        /// Parses the element's child elements.
        /// </summary>
        /// <param name="buffer">The string buffer to parse.</param>
        /// <param name="readPosition">The read position to start from.</param>
        /// <returns>True if successful, false otherwise.</returns>
        private bool parseChildElements(NSFString buffer, ref int readPosition)
        {
            while (true)
            {
                if (!skipWhitespace(buffer, ref readPosition))
                {
                    return false;
                }

                if (buffer.Length < readPosition + 2)
                {
                    return false;
                }

                // Check for child elements
                if ((buffer[readPosition] == '<') && (buffer[readPosition + 1] != '/'))
                {
                    NSFXMLElement newElement = new NSFXMLElement();

                    if (!newElement.loadBuffer(buffer, ref readPosition))
                    {
                        return false;
                    }

                    addChildElementBack(newElement);

                    continue;
                }

                return true;
            }
        }
        /// <summary>
        /// Gets the next child element after the specified child element, with the specified tag.
        /// </summary>
        /// <param name="childElement">The child element before the returned child element.</param>
        /// <param name="nextTag">The child element tag.</param>
        /// <returns>The child element, or NULL if none exist.</returns>
        public NSFXMLElement getNextElement(NSFXMLElement childElement, NSFString nextTag)
        {
            bool returnNext = false;

            foreach (NSFXMLElement element in childElements)
            {
                if (returnNext)
                {
                    if (element.Tag == nextTag)
                    {
                        return element;
                    }
                }
                else if (element == childElement)
                {
                    returnNext = true;
                }
            }

            return null;
        }
        /// <summary>
        /// Gets the next child element after the specified child element.
        /// </summary>
        /// <param name="childElement">The child element before the returned child element.</param>
        /// <returns>The child element, or NULL if none exist.</returns>
        public NSFXMLElement getNextElement(NSFXMLElement childElement)
        {
            bool returnNext = false;

            foreach (NSFXMLElement element in childElements)
            {
                if (returnNext)
                {
                    return element;
                }

                if (element == childElement)
                {
                    returnNext = true;
                }
            }

            return null;
        }
예제 #24
0
 /// <summary>
 /// Adds an element to the back of the child element list.
 /// </summary>
 public void addChildElementBack(NSFXMLElement childElement)
 {
     childElement.parentElement = this;
     childElements.AddLast(childElement);
 }
 /// <summary>
 /// Adds an element to the front of the child element list.
 /// </summary>
 public void addChildElementFront(NSFXMLElement childElement)
 {
     childElement.parentElement = this;
     childElements.AddFirst(childElement);
 }
        /// <summary>
        /// Adds a trace to the log.
        /// </summary>
        /// <param name="type">The type of the trace.</param>
        /// <param name="tag1">The first tag associated with the trace.</param>
        /// <param name="data1">The data associated with the first tag.</param>
        /// <param name="tag2">The second tag associated with the trace.</param>
        /// <param name="data2">The data associated with the second tag.</param>
        /// <param name="tag3">The third tag associated with the trace.</param>
        /// <param name="data3">The data associated with the third tag.</param>
        public void addTrace(NSFString type, NSFString tag1, NSFString data1, NSFString tag2, NSFString data2, NSFString tag3, NSFString data3)
        {
            // If logging is not enabled then return without action
            if (!enabled)
            {
                return;
            }

            // Lock to prevent events from being added to the queue with timestamps out of order
            lock (traceLogMutex)
            {
                try
                {
                    // Create the new trace element
                    NSFXMLElement trace = new NSFXMLElement(TraceTag);

                    // Add the time
                    trace.addChildElementBack(new NSFXMLElement(TimeTag, NSFTimerThread.PrimaryTimerThread.CurrentTime.ToString()));

                    // Add a trace for the type
                    NSFXMLElement typeTrace = new NSFXMLElement(type);
                    trace.addChildElementBack(typeTrace);

                    // Add the new data under the type element;
                    typeTrace.addChildElementBack(new NSFXMLElement(tag1, data1));

                    if (tag2 != null) typeTrace.addChildElementBack(new NSFXMLElement(tag2, data2));
                    if (tag3 != null) typeTrace.addChildElementBack(new NSFXMLElement(tag3, data3));

                    eventHandler.queueEvent(traceAddEvent.copy(trace));
                }
                catch
                {
                    // If unable to add a trace, just do nothing, because calling the exception handler may result in an infinite loop
                }
            }
        }
 /// <summary>
 /// Deletes the specified child element.
 /// </summary>
 /// <param name="childElement">The element to delete.</param>
 public void deleteChildElement(NSFXMLElement childElement)
 {
     childElements.Remove(childElement);
 }