/// <summary> /// Writes the specified start tag and associates it with the given namespace and prefix. /// Inherited from <c>XmlTextWriter</c>, see <see cref="XmlTextWriter.WriteStartElement"/> /// Overridden to detect <c>exsl:document</c> element start tag. /// </summary> /// <param name="prefix">The namespace prefix of the element.</param> /// <param name="localName">The local name of the element.</param> /// <param name="ns">The namespace URI to associate with the element. If this namespace /// is already in scope and has an associated prefix then the writer will automatically write that prefix also. </param> /// <exception cref="InvalidOperationException">The writer is closed.</exception> public override void WriteStartElement(string prefix, string localName, string ns) { CheckContentStart(); //Is it exsl:document redirecting instruction? if (localName == "html") { int procent = (int)((float)pageCounter++ / (float)this.numberOfPages * 100); // Console.writeLine(procent); } if (ns == RedirectNamespace && localName == RedirectElementName) { //Lazy stack of states if (states == null) { states = new Stack(); } //If we are redirecting already - push the current state into the stack if (redirectState == RedirectState.Redirecting) { states.Push(state); } //Initialize new state state = new OutputState(); redirectState = RedirectState.WritingRedirectElementAttrs; } else { if (redirectState == RedirectState.Redirecting) { if (state.Method == OutputMethod.Text) { state.Depth++; return; } //Write doctype before the first element if (state.Depth == 0 && state.SystemDoctype != null) { if (prefix != String.Empty) { state.XmlWriter.WriteDocType(prefix + ":" + localName, state.PublicDoctype, state.SystemDoctype, null); } else { state.XmlWriter.WriteDocType(localName, state.PublicDoctype, state.SystemDoctype, null); } } state.XmlWriter.Formatting = Formatting.None; state.XmlWriter.WriteStartElement(prefix, localName, ns); state.Depth++; } else { base.WriteStartElement(prefix, localName, ns); } } }
public IEnumerable <CustomRedirect> GetByState(RedirectState state) { var sqlCommand = $@"SELECT {AllFields} FROM {RedirectsTable} WHERE State = @state"; return(ExecuteQuery(() => CreateCommand( sqlCommand, CreateIntParameter("state", (int)state)))); }
/// <summary> /// Writes the specified start tag and associates it with the given namespace and prefix. /// Inherited from <c>XmlTextWriter</c>, see <see cref="XmlTextWriter.WriteStartElement"/> /// Overridden to detect <c>exsl:document</c> element start tag. /// </summary> /// <param name="prefix">The namespace prefix of the element.</param> /// <param name="localName">The local name of the element.</param> /// <param name="ns">The namespace URI to associate with the element. If this namespace /// is already in scope and has an associated prefix then the writer will automatically write that prefix also. </param> /// <exception cref="InvalidOperationException">The writer is closed.</exception> public override void WriteStartElement(string prefix, string localName, string ns) { CheckContentStart(); //Is it exsl:document redirecting instruction? if (ns == RedirectNamespace && localName == RedirectElementName) { //Lazy stack of states if (states == null) { states = new Stack(); } //If we are redirecting already - push the current state into the stack if (redirectState == RedirectState.Redirecting) { states.Push(state); } //Initialize new state state = new OutputState(); redirectState = RedirectState.WritingRedirectElementAttrs; } else { if (redirectState == RedirectState.Redirecting) { if (state.Method == OutputMethod.Text) { state.Depth++; return; } //Write doctype before the first element if (state.Depth == 0 && state.SystemDoctype != null) { if (prefix != string.Empty) { state.XmlWriter.WriteDocType(prefix + ":" + localName, state.PublicDoctype, state.SystemDoctype, null); } else { state.XmlWriter.WriteDocType(localName, state.PublicDoctype, state.SystemDoctype, null); } } state.XmlWriter.WriteStartElement(prefix, localName, ns); state.Depth++; } else { base.WriteStartElement(prefix, localName, ns); } } }
/// <summary> /// Finishes output redirecting - closes current writer /// and pops previous state. /// </summary> internal void FinishRedirecting() { state.CloseWriter(); //Pop previous state if it exists if (states.Count != 0) { state = (OutputState)states.Pop(); redirectState = RedirectState.Redirecting; } else { state = null; redirectState = RedirectState.Relaying; } }
private void CheckContentStart() { if (_redirectState == RedirectState.WritingRedirectElementAttrs) { //Check required href attribute if (_state.Href == null) { throw new ArgumentNullException("", @"'href' attribute of exsl:document element must be specified."); } //Are we writing to this URI already? if (_states.Cast <OutputState>().Any(nestedState => nestedState.Href == _state.Href)) { throw new ArgumentException("Cannot write to " + _state.Href + " two documents simultaneously."); } _state.InitWriter(_outResolver); _redirectState = RedirectState.Redirecting; } }
/// <summary> /// Closes the previous <c>WriteStartAttribute</c> call. /// Inherited from <c>XmlTextWriter</c>, see <see cref="XmlTextWriter.WriteEndAttribute"/> /// Overridden to redirect the output. /// </summary> public override void WriteEndAttribute() { if (redirectState == RedirectState.WritingRedirectElementAttrValue) { redirectState = RedirectState.WritingRedirectElementAttrs; } else if (redirectState == RedirectState.Redirecting) { if (state.Method == OutputMethod.Text) { return; } state.XmlWriter.WriteEndAttribute(); } else { base.WriteEndAttribute(); } }
/// <summary> /// Writes the start of an attribute. /// Inherited from <c>XmlTextWriter</c>, see <see cref="XmlTextWriter.WriteStartAttribute"/> /// Overridden to detect <c>exsl:document</c> attribute names and to redirect /// the output. /// </summary> /// <param name="prefix">Namespace prefix of the attribute.</param> /// <param name="localName">Local name of the attribute.</param> /// <param name="ns">Namespace URI of the attribute.</param> /// <exception cref="ArgumentException"><c>localName</c>c> is either a null reference or <c>String.Empty</c>.</exception> public override void WriteStartAttribute(string prefix, string localName, string ns) { if (redirectState == RedirectState.WritingRedirectElementAttrs) { redirectState = RedirectState.WritingRedirectElementAttrValue; currentAttributeName = localName; } else if (redirectState == RedirectState.Redirecting) { if (state.Method == OutputMethod.Text) { return; } state.XmlWriter.WriteStartAttribute(prefix, localName, ns); } else { base.WriteStartAttribute(prefix, localName, ns); } }
/// <summary> /// Checks possible start of <c><exsl:document></c> element content. /// </summary> /// <remarks> /// When <c><exsl:document></c> element start tag is detected, the beginning of the /// element's content might be detected as any next character data (not attribute /// value though), element start tag, processing instruction or comment. /// </remarks> /// <exception cref="ArgumentNullException">Thrown when <c>href</c> attribute is absent.</exception> /// <exception cref="ArgumentException">Thrown when a document, specified by <c>href</c> attribute is /// opened alreary. Two nested <c><exsl:document></c></exception> elements cannot specify the same /// output URI in their <c>href</c> attributes. private void CheckContentStart() { if (redirectState == RedirectState.WritingRedirectElementAttrs) { //Check required href attribute if (state.Href == null) { throw new ArgumentNullException("'href' attribute of exsl:document element must be specified."); } //Are we writing to this URI already? foreach (OutputState nestedState in states) { if (nestedState.Href == state.Href) { throw new ArgumentException("Cannot write to " + state.Href + " two documents simultaneously."); } } state.InitWriter(); redirectState = RedirectState.Redirecting; } }
public override void WriteStartAttribute(string prefix, string localName, string ns) { switch (_redirectState) { case RedirectState.WritingRedirectElementAttrs: _redirectState = RedirectState.WritingRedirectElementAttrValue; _currentAttributeName = localName; break; case RedirectState.Redirecting: if (_state.Method == OutputMethod.Text) { return; } _state.XmlWriter.WriteStartAttribute(prefix, localName, ns); break; default: base.WriteStartAttribute(prefix, localName, ns); break; } }
/// <summary> /// Closes the previous <c>WriteStartAttribute</c> call. /// Inherited from <c>XmlTextWriter</c>, see <see cref="XmlTextWriter.WriteEndAttribute"/> /// Overridden to redirect the output. /// </summary> public override void WriteEndAttribute() { if (redirectState == RedirectState.WritingRedirectElementAttrValue) redirectState = RedirectState.WritingRedirectElementAttrs; else if (redirectState == RedirectState.Redirecting) { if (state.Method == OutputMethod.Text) return; state.XmlWriter.WriteEndAttribute(); } else base.WriteEndAttribute(); }
/// <summary> /// Writes the start of an attribute. /// Inherited from <c>XmlTextWriter</c>, see <see cref="XmlTextWriter.WriteStartAttribute"/> /// Overridden to detect <c>exsl:document</c> attribute names and to redirect /// the output. /// </summary> /// <param name="prefix">Namespace prefix of the attribute.</param> /// <param name="localName">Local name of the attribute.</param> /// <param name="ns">Namespace URI of the attribute.</param> /// <exception cref="ArgumentException"><c>localName</c>c> is either a null reference or <c>String.Empty</c>.</exception> public override void WriteStartAttribute(string prefix, string localName, string ns) { if (redirectState == RedirectState.WritingRedirectElementAttrs) { redirectState = RedirectState.WritingRedirectElementAttrValue; currentAttributeName = localName; } else if (redirectState == RedirectState.Redirecting) { if (state.Method == OutputMethod.Text) return; state.XmlWriter.WriteStartAttribute(prefix, localName, ns); } else base.WriteStartAttribute(prefix, localName, ns); }
/// <summary> /// Writes the specified start tag and associates it with the given namespace and prefix. /// Inherited from <c>XmlTextWriter</c>, see <see cref="XmlTextWriter.WriteStartElement"/> /// Overridden to detect <c>exsl:document</c> element start tag. /// </summary> /// <param name="prefix">The namespace prefix of the element.</param> /// <param name="localName">The local name of the element.</param> /// <param name="ns">The namespace URI to associate with the element. If this namespace /// is already in scope and has an associated prefix then the writer will automatically write that prefix also. </param> /// <exception cref="InvalidOperationException">The writer is closed.</exception> public override void WriteStartElement(string prefix, string localName, string ns) { CheckContentStart(); //Is it exsl:document redirecting instruction? if (ns == RedirectNamespace && localName == RedirectElementName) { //Lazy stack of states if (states == null) states = new Stack(); //If we are redirecting already - push the current state into the stack if (redirectState == RedirectState.Redirecting) states.Push(state); //Initialize new state state = new OutputState(); redirectState = RedirectState.WritingRedirectElementAttrs; } else { if (redirectState == RedirectState.Redirecting) { if (state.Method == OutputMethod.Text) { state.Depth++; return; } //Write doctype before the first element if (state.Depth == 0 && state.SystemDoctype != null) if (prefix != String.Empty) state.XmlWriter.WriteDocType(prefix+":"+localName, state.PublicDoctype,state.SystemDoctype, null); else state.XmlWriter.WriteDocType(localName, state.PublicDoctype,state.SystemDoctype, null); state.XmlWriter.WriteStartElement(prefix, localName, ns); state.Depth++; } else base.WriteStartElement(prefix, localName, ns); } }
/// <summary> /// Checks possible start of <c><exsl:document></c> element content. /// </summary> /// <remarks> /// When <c><exsl:document></c> element start tag is detected, the beginning of the /// element's content might be detected as any next character data (not attribute /// value though), element start tag, processing instruction or comment. /// </remarks> /// <exception cref="ArgumentNullException">Thrown when <c>href</c> attribute is absent.</exception> /// <exception cref="ArgumentException">Thrown when a document, specified by <c>href</c> attribute is /// opened alreary. Two nested <c><exsl:document></c></exception> elements cannot specify the same /// output URI in their <c>href</c> attributes. private void CheckContentStart() { if (redirectState == RedirectState.WritingRedirectElementAttrs) { //Check required href attribute if (state.Href == null) throw new ArgumentNullException("'href' attribute of exsl:document element must be specified."); //Are we writing to this URI already? foreach (OutputState nestedState in states) if (nestedState.Href == state.Href) throw new ArgumentException("Cannot write to " + state.Href + " two documents simultaneously."); state.InitWriter(); redirectState = RedirectState.Redirecting; } }
public IEnumerable <CustomRedirect> GetByState(RedirectState state) { return(Store.Items <CustomRedirect>() .OrderBy(cr => cr.OldUrl) .Where(s => s.State.Equals((int)state))); }