/// <summary> /// Write a XukAble element to a XUK file representing the <see cref="XukAble"/> instance /// </summary> /// <param name="destination">The destination <see cref="XmlWriter"/></param> /// <param name="baseUri"> /// The base <see cref="Uri"/> used to make written <see cref="Uri"/>s relative, /// if <c>null</c> absolute <see cref="Uri"/>s are written /// </param> /// <param name="handler">The handler for progress</param> public virtual void XukOut(XmlWriter destination, Uri baseUri, IProgressHandler handler) { if (destination == null) { throw new exception.MethodParameterIsNullException( "Can not XukOut to a null XmlWriter"); } if (handler != null) { if (handler.NotifyProgress()) { string msg = String.Format("XukOut cancelled at {0}", ToString()); throw new exception.ProgressCancelledException(msg); } } try { if (MissingTypeOriginalXukedName != null) { if (MissingTypeOriginalXukedName.NamespaceUri == XukAble.XUK_NS) { destination.WriteStartElement(MissingTypeOriginalXukedName.LocalName.z(PrettyFormat), MissingTypeOriginalXukedName.NamespaceUri); } else { string prefix = getXukNamespacePrefix(MissingTypeOriginalXukedName.NamespaceUri); destination.WriteStartElement(prefix, MissingTypeOriginalXukedName.LocalName.z(PrettyFormat), MissingTypeOriginalXukedName.NamespaceUri); } } else { if (GetXukNamespace() == XukAble.XUK_NS) { destination.WriteStartElement(GetXukName(), XukAble.XUK_NS); } else { string prefix = getXukNamespacePrefix(GetXukNamespace()); destination.WriteStartElement(prefix, GetXukName(), GetXukNamespace()); } } XukOutAttributes(destination, baseUri); XukOutChildren(destination, baseUri, handler); destination.WriteEndElement(); } catch (exception.ProgressCancelledException) { throw; } catch (exception.XukException) { #if DEBUG Debugger.Break(); #endif throw; } catch (Exception e) { #if DEBUG Debugger.Break(); #endif throw new exception.XukException( String.Format("An exception occured during XukOut of XukAble: {0}", e.Message), e); } }
/// <summary> /// The implementation of XUKIn is expected to read and remove all tags /// up to and including the closing tag matching the element the reader was at when passed to it. /// The call is expected to be forwarded to any owned element, in effect making it a recursive read of the XUK file /// </summary> /// <param name="source">The XmlReader to read from</param> /// <param name="handler">The handler for progress</param> public virtual void XukIn(XmlReader source, IProgressHandler handler) { if (source == null) { throw new exception.MethodParameterIsNullException("Can not XukIn from an null source XmlReader"); } if (source.NodeType != XmlNodeType.Element) { throw new exception.XukException("Can not read XukAble from a non-element node"); } if (handler != null) { if (handler.NotifyProgress()) { string msg = String.Format("XukIn cancelled at element {0}:{1}", GetXukName(), GetXukNamespace()); throw new exception.ProgressCancelledException(msg); } } try { Clear(); XukInAttributes(source); if (!source.IsEmptyElement) { while (source.Read()) { if (source.NodeType == XmlNodeType.Element) { XukInChild(source, handler); } else if (source.NodeType == XmlNodeType.Text) { XukInChild(source, handler); break; } else if (source.NodeType == XmlNodeType.EndElement) { break; } if (source.EOF) { throw new exception.XukException("Unexpectedly reached EOF"); } } } } catch (exception.ProgressCancelledException) { throw; } catch (exception.XukException) { #if DEBUG Debugger.Break(); #endif throw; } catch (Exception e) { #if DEBUG Debugger.Break(); #endif throw new exception.XukException( String.Format("An exception occured during XukIn of XukAble: {0}", e.Message), e); } }