public abstract WriteChars ( char buffer, int index, int count ) : void | ||
buffer | char | |
index | int | |
count | int | |
Résultat | void |
void IXmlSerializable.WriteXml(System.Xml.XmlWriter writer) { // This is the chunking code. // ASP.NET buffering must be turned off for this to work. int bufferSize = 4096; char[] songBytes = new char[bufferSize]; FileStream inFile = File.Open(this.filePath, FileMode.Open, FileAccess.Read); long length = inFile.Length; // Write the file name. writer.WriteElementString("fileName", ns, Path.GetFileNameWithoutExtension(this.filePath)); // Write the size. writer.WriteElementString("size", ns, length.ToString()); // Write the song bytes. writer.WriteStartElement("song", ns); StreamReader sr = new StreamReader(inFile, true); int readLen = sr.Read(songBytes, 0, bufferSize); while (readLen > 0) { writer.WriteStartElement("chunk", ns); writer.WriteChars(songBytes, 0, readLen); writer.WriteEndElement(); writer.Flush(); readLen = sr.Read(songBytes, 0, bufferSize); } writer.WriteEndElement(); inFile.Close(); }
internal void Replay(XmlWriter writer) { if (_singleStringValue != null) { writer.WriteString(_singleStringValue); return; } BufferChunk bufChunk; for (int i = _firstItem; i <= _lastItem; i++) { Item item = _items[i]; switch (item.type) { case ItemType.EntityRef: writer.WriteEntityRef((string)item.data); break; case ItemType.CharEntity: writer.WriteCharEntity((char)item.data); break; case ItemType.SurrogateCharEntity: char[] chars = (char[])item.data; writer.WriteSurrogateCharEntity(chars[0], chars[1]); break; case ItemType.Whitespace: writer.WriteWhitespace((string)item.data); break; case ItemType.String: writer.WriteString((string)item.data); break; case ItemType.StringChars: bufChunk = (BufferChunk)item.data; writer.WriteChars(bufChunk.buffer, bufChunk.index, bufChunk.count); break; case ItemType.Raw: writer.WriteRaw((string)item.data); break; case ItemType.RawChars: bufChunk = (BufferChunk)item.data; writer.WriteChars(bufChunk.buffer, bufChunk.index, bufChunk.count); break; case ItemType.ValueString: writer.WriteValue((string)item.data); break; default: Debug.Fail("Unexpected ItemType value."); break; } } }
// ------------------------------------------------------------- // // Private Methods // // ------------------------------------------------------------- #region Private Methods // ............................................................. // // Serialization // // ............................................................. /// <summary> /// This function serializes text segment formed by rangeStart and rangeEnd to valid xml using xmlWriter. /// </summary> /// <SecurityNote> /// To mask the security exception from XamlWriter.Save in partial trust case, /// this function checks if the current call stack has the all clipboard permission. /// </SecurityNote> private static void WriteXamlTextSegment(XmlWriter xmlWriter, ITextPointer rangeStart, ITextPointer rangeEnd, XamlTypeMapper xamlTypeMapper, ref int elementLevel, WpfPayload wpfPayload, bool ignoreWriteHyperlinkEnd, List<int> ignoreList, bool preserveTextElements) { // Special case for pure text selection - we need a Run wrapper for it. if (elementLevel == EmptyDocumentDepth && typeof(Run).IsAssignableFrom(rangeStart.ParentType)) { elementLevel++; xmlWriter.WriteStartElement(typeof(Run).Name); } // Create text navigator for reading the range's content ITextPointer textReader = rangeStart.CreatePointer(); // Exclude last opening tag from serialization - we don't need to create extra element // is cases when we have whole paragraphs/cells selected. // NOTE: We do this slightly differently than in TextRangeEdit.AdjustRangeEnd, where we use normalization for adjusted position. // In this case normalized position does not work, because we need to keep information about crossed paragraph boundary. while (rangeEnd.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart) { rangeEnd = rangeEnd.GetNextContextPosition(LogicalDirection.Backward); } // Write the range internal contents while (textReader.CompareTo(rangeEnd) < 0) { TextPointerContext runType = textReader.GetPointerContext(LogicalDirection.Forward); switch (runType) { case TextPointerContext.ElementStart: TextElement nextElement = (TextElement)textReader.GetAdjacentElement(LogicalDirection.Forward); if (nextElement is Hyperlink) { // Don't write Hyperlink start element if Hyperlink is invalid // in case of having a UiElement except Image or stated the range end // position before the end position of the Hyperlink. if (IsHyperlinkInvalid(textReader, rangeEnd)) { ignoreWriteHyperlinkEnd = true; textReader.MoveToNextContextPosition(LogicalDirection.Forward); continue; } } else if (nextElement != null) { // TextElementEditingBehaviorAttribute att = (TextElementEditingBehaviorAttribute)Attribute.GetCustomAttribute(nextElement.GetType(), typeof(TextElementEditingBehaviorAttribute)); if (att != null && !att.IsTypographicOnly) { if (IsPartialNonTypographic(textReader, rangeEnd)) { // Add pointer to ignore list ITextPointer ptr = textReader.CreatePointer(); ptr.MoveToElementEdge(ElementEdge.BeforeEnd); ignoreList.Add(ptr.Offset); textReader.MoveToNextContextPosition(LogicalDirection.Forward); continue; } } } elementLevel++; textReader.MoveToNextContextPosition(LogicalDirection.Forward); WriteStartXamlElement(/*range:*/null, textReader, xmlWriter, xamlTypeMapper, /*reduceElement:*/wpfPayload == null, preserveTextElements); break; case TextPointerContext.ElementEnd: // Don't write Hyperlink end element if Hyperlink include the invalid // in case of having a UiElement except Image or stated the range end // before the end position of the Hyperlink or Hyperlink opening tag is // skipped from WriteOpeningTags by selecting of the partial of Hyperlink. if (ignoreWriteHyperlinkEnd && (textReader.GetAdjacentElement(LogicalDirection.Forward) is Hyperlink)) { // Reset the flag to keep walk up the next Hyperlink tag ignoreWriteHyperlinkEnd = false; textReader.MoveToNextContextPosition(LogicalDirection.Forward); continue; } // Check the ignore list ITextPointer endPointer = textReader.CreatePointer(); endPointer.MoveToElementEdge(ElementEdge.BeforeEnd); // if (ignoreList.Contains(endPointer.Offset)) { ignoreList.Remove(endPointer.Offset); textReader.MoveToNextContextPosition(LogicalDirection.Forward); continue; } elementLevel--; if (TextSchema.IsBreak(textReader.ParentType)) { // For LineBreak, etc. use empty element syntax xmlWriter.WriteEndElement(); } else { // // For all other textelements use explicit closing tag. xmlWriter.WriteFullEndElement(); } textReader.MoveToNextContextPosition(LogicalDirection.Forward); break; case TextPointerContext.Text: int textLength = textReader.GetTextRunLength(LogicalDirection.Forward); char[] text = new Char[textLength]; textLength = TextPointerBase.GetTextWithLimit(textReader, LogicalDirection.Forward, text, 0, textLength, rangeEnd); // XmlWriter will throw an ArgumentException if text contains // any invalid surrogates, so strip them out now. textLength = StripInvalidSurrogateChars(text, textLength); xmlWriter.WriteChars(text, 0, textLength); textReader.MoveToNextContextPosition(LogicalDirection.Forward); break; case TextPointerContext.EmbeddedElement: object embeddedObject = textReader.GetAdjacentElement(LogicalDirection.Forward); textReader.MoveToNextContextPosition(LogicalDirection.Forward); WriteEmbeddedObject(embeddedObject, xmlWriter, wpfPayload); break; default: Invariant.Assert(false, "unexpected value of runType"); textReader.MoveToNextContextPosition(LogicalDirection.Forward); break; } } }
private void InvokeMethod(XmlWriter w, string methodName) { byte[] buffer = new byte[10]; switch (methodName) { case "WriteStartDocument": w.WriteStartDocument(); break; case "WriteStartElement": w.WriteStartElement("root"); break; case "WriteEndElement": w.WriteEndElement(); break; case "WriteStartAttribute": w.WriteStartAttribute("attr"); break; case "WriteEndAttribute": w.WriteEndAttribute(); break; case "WriteCData": w.WriteCData("test"); break; case "WriteComment": w.WriteComment("test"); break; case "WritePI": w.WriteProcessingInstruction("name", "test"); break; case "WriteEntityRef": w.WriteEntityRef("e"); break; case "WriteCharEntity": w.WriteCharEntity('c'); break; case "WriteSurrogateCharEntity": w.WriteSurrogateCharEntity('\uDC00', '\uDBFF'); break; case "WriteWhitespace": w.WriteWhitespace(" "); break; case "WriteString": w.WriteString("foo"); break; case "WriteChars": char[] charArray = new char[] { 'a', 'b', 'c', 'd' }; w.WriteChars(charArray, 0, 3); break; case "WriteRaw": w.WriteRaw("<foo>bar</foo>"); break; case "WriteBase64": w.WriteBase64(buffer, 0, 9); break; case "WriteBinHex": w.WriteBinHex(buffer, 0, 9); break; case "LookupPrefix": string str = w.LookupPrefix("foo"); break; case "WriteNmToken": w.WriteNmToken("foo"); break; case "WriteName": w.WriteName("foo"); break; case "WriteQualifiedName": w.WriteQualifiedName("foo", "bar"); break; case "WriteValue": w.WriteValue(Int32.MaxValue); break; case "WriteAttributes": XmlReader xr1 = ReaderHelper.Create(new StringReader("<root attr='test'/>")); xr1.Read(); w.WriteAttributes(xr1, false); break; case "WriteNodeReader": XmlReader xr2 = ReaderHelper.Create(new StringReader("<root/>")); xr2.Read(); w.WriteNode(xr2, false); break; case "Flush": w.Flush(); break; default: CError.Equals(false, "Unexpected param in testcase: {0}", methodName); break; } }
public override void WriteChars(char[] buffer, int index, int count) { _writer.WriteChars(buffer, index, count); }
public override void WriteChars(char [] buffer, int index, int count) { CheckState(); w.WriteChars(buffer, index, count); }
public override void WriteChars(char[] buffer, int index, int count) { CheckAsync(); coreWriter.WriteChars(buffer, index, count); }
public override void WriteChars(char [] buffer, int index, int count) { writer.WriteChars(buffer, index, count); state = WriteState.Content; }
/// <summary> /// WriteSimpleElement /// </summary> /// <param name="xmlw"></param> /// <param name="name"></param> /// <param name="value"></param> protected void WriteSimpleElement(XmlWriter xmlw, string name, string value) { if (value == null) { return; } xmlw.WriteStartElement(name); xmlw.WriteChars(value.ToCharArray(), 0, value.ToCharArray().Length); xmlw.WriteEndElement(); }
public virtual void WriteXml(System.Xml.XmlWriter writer) { writer.WriteChars(CommonUtilities.XmlCharacterArray, 0, CommonUtilities.XmlCharacterArray.Length); }
internal void Replay(XmlWriter writer) { if (this.singleStringValue != null) { writer.WriteString(this.singleStringValue); } else { for (int i = this.firstItem; i <= this.lastItem; i++) { BufferChunk chunk; Item item = this.items[i]; switch (item.type) { case ItemType.EntityRef: writer.WriteEntityRef((string) item.data); break; case ItemType.CharEntity: writer.WriteCharEntity((char) item.data); break; case ItemType.SurrogateCharEntity: { char[] data = (char[]) item.data; writer.WriteSurrogateCharEntity(data[0], data[1]); break; } case ItemType.Whitespace: writer.WriteWhitespace((string) item.data); break; case ItemType.String: writer.WriteString((string) item.data); break; case ItemType.StringChars: chunk = (BufferChunk) item.data; writer.WriteChars(chunk.buffer, chunk.index, chunk.count); break; case ItemType.Raw: writer.WriteRaw((string) item.data); break; case ItemType.RawChars: chunk = (BufferChunk) item.data; writer.WriteChars(chunk.buffer, chunk.index, chunk.count); break; case ItemType.ValueString: writer.WriteValue((string) item.data); break; } } } }