protected override DictionaryWord Read() { if (BaseReader.EndOfStream) return null; var line = BaseReader.ReadLine(); var columns = line.Split(' '); return new DictionaryWord { Id = int.Parse(columns[0]), Word = columns[1], Meanings = columns .Skip(2) .Select(x => { var values = x.Split(':'); return new DictionaryMeaning { Id = int.Parse(values[0]), Meaning = values[1], PartOfSpeech = SynsetHelper.GetPos(values[1]), Encounters = int.Parse(values[2]) }; }) .ToMeaningDictionary() }; }
public override bool Read() { var read = base.Read(); switch (base.NodeType) { case XmlNodeType.Element: _nsManager.PushScope(); for (var go = BaseReader.MoveToFirstAttribute(); go; go = BaseReader.MoveToNextAttribute()) { if (BaseReader.NamespaceURI != _xmlNsNamespace) { continue; } var prefix = GetNamespacePrefix(); // Only push if it's not already defined. if (_nsManager.LookupNamespace(prefix) == null) { _nsManager.AddNamespace(prefix, Value); } } if (BaseReader.HasAttributes) { BaseReader.MoveToElement(); } break; case XmlNodeType.EndElement: _nsManager.PopScope(); break; } return(read); }
public static BaseReader GetReader(string file) { BaseReader reader = null; var ext = Path.GetExtension(file).ToUpperInvariant(); switch (ext) { case ".DBC": reader = new DBCReader(file); break; case ".DB2": reader = new DB2Reader(file); break; case ".ADB": reader = new ADBReader(file); break; case ".WDB": reader = new WDBReader(file); break; default: throw new InvalidDataException(String.Format("Unknown file type {0}", ext)); } return(reader); }
/// <internalonly /> /// <devdoc> /// <para> return true if one of the queries matches with the XmlReader context. </para> /// </devdoc> public bool ReadUntilMatch() { while (true) { if (ProcessAttribute > 0) { //need to process the attribute one at time if (MoveToNextAttribute()) { if (_XPathCollection.MatchAnyQuery()) { return(true); } } else { ProcessAttribute = -1; //stop attributes processing. } } else if (!BaseReader.Read()) { return(false); } else { _XPathCollection.AdvanceUntil(this); if (_XPathCollection.MatchAnyQuery()) { return(true); } } } }
public string? ReadLine() { Buffer.Clear(); LineNumber += 1; LineColumn = 1; return BaseReader.ReadLine(); }
public override int Read() { int ret = base.Read(); _prevLineStart = _atLineStart; if (ret == -1) { _atLineStart = true; return(ret); } _atLineStart = false; ++_position; if (ret == '\r') { if (Peek() == '\n') { ret = BaseReader.Read(); } else { NoteLineAdvance(); } } if (ret == '\n') { NoteLineAdvance(); } return(ret); }
} // proc SetColumn private bool ReadBuffer() { charOffset = 0; charBufferLength = BaseReader.Read(charBuffer, charOffset, charBuffer.Length); return(charBufferLength > 0); } // func ReadBuffer
public override SharedDataBuffer ReadSharedDataBuffer(uint size) { var innerSize = BaseReader.ReadUInt32(); if (size != innerSize + 4) { throw new TodoException("ReadSharedDataBuffer"); } var result = base.ReadSharedDataBuffer(innerSize); if (_parseBuffer) { using var ms = new MemoryStream(result.Buffer.GetBytes()); using var br = new BinaryReader(ms, Encoding.Default, true); using var cr2wReader = new CR2WReader(br); var readResult = cr2wReader.ReadFile(out var c, true); if (readResult == EFileReadErrorCodes.NoCr2w) { throw new TodoException("ReadSharedDataBuffer"); } result.File = c; } return(result); }
public BaseWriter(BaseReader reader) { FieldCache = typeof(T).ToFieldCache <T>(); FieldsCount = reader.FieldsCount; RecordSize = reader.RecordSize; IdFieldIndex = reader.IdFieldIndex; Flags = reader.Flags; StringTableStingAsKeyPosAsValue = new Dictionary <string, int>(); CopyData = new SortedDictionary <int, int>(); field_structure_data = reader.field_structure_data; ColumnMeta = reader.ColumnMeta; if (ColumnMeta != null) { CommonData = new Dictionary <int, Value32> [ColumnMeta.Length]; PalletData = new List <Value32[]> [ColumnMeta.Length]; ReferenceData = new List <int>(); // create the lookup collections for (int i = 0; i < ColumnMeta.Length; i++) { CommonData[i] = new Dictionary <int, Value32>(); PalletData[i] = new List <Value32[]>(); } } // add an empty string at the first index InternString(""); }
/// <summary> /// Parse the xml string into a RssFeed object /// </summary> /// <param name="xml"></param> /// <returns></returns> public static RssFeed LoadFeed(string xml) { XDocument doc; try { doc = XDocument.Parse(xml); } catch (Exception ex) { throw new NotSupportedFeedException("Not Supported", ex); } RssType type = BaseReader.GetFeedType(doc); BaseReader reader; switch (type) { case RssType.Atom: reader = new AtomReader(); break; case RssType.Rdf: reader = new RDFReader(); break; default: reader = new Reader(); break; } return(reader.LoadFeed(doc)); }
public void Dispose() { if (BaseReader != null) { BaseReader.Dispose(); Disposed = true; } }
/// <inheritdoc/> protected override void Dispose(bool disposing) { #if FEATURE_XML_DISPOSE_PROTECTED (BaseReader as IDisposable)?.Dispose(); #else BaseReader.Dispose(); #endif }
public void ReadFlagWord() { if (!ContinuationBitSet) { throw new MalformedFrameException("Attempted to read flag word when none advertised"); } m_flagWord = BaseReader.ReadUInt16(); m_bitCount = 0; }
public void Dispose() { Clear(); if (BaseReader != null) { BaseReader.Dispose(); BaseReader = null; } }
/// <summary> /// Release resource /// </summary> protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing && BaseReader != null) { BaseReader.Dispose(); BaseReader = null; } }
public static RenderResult GenerateRenderResultFromFile(string path, string settingKey) { var type = BaseReader.GetDiamondType(path); if (type == DiamondType.NotExist || !levelRenders.Keys.Contains(type)) { throw new NotSupportedException(path); } return(levelRenders[type].GenerateRenderResult(path, settingKey)); }
/// <devdoc> /// <para> /// Moves to the next attribute. /// </para> /// </devdoc> public override bool MoveToNextAttribute() { var result = BaseReader.MoveToNextAttribute(); if (result) { _XPathCollection.Advance(this); } return(result); }
/// <devdoc> /// <para> /// Moves to the attribute with the specified <see cref='XPathReader.LocalName' /> /// and <see cref='NamespaceURI' /> . /// </para> /// </devdoc> public override bool MoveToAttribute(string AttributeName, string ns) { var result = BaseReader.MoveToAttribute(AttributeName, ns); if (result) { _XPathCollection.Advance(this); } return(result); }
/// <summary> /// Reads memory buffer from the stream. /// </summary> /// <param name="length">Number of bytes to read from the stream.</param> /// <returns>Memory buffer read from the stream.</returns> public MemoryBuffer ReadBuffer(uint length) { if (blockRemaining < length) { blockRemaining -= length; position += length; return(BaseReader.ReadBuffer(length)); } return(new MemoryBuffer(this.ReadByteArray((int)length))); }
/// <devdoc> /// <para> /// Moves to the element that contains the current attribute node. /// </para> /// </devdoc> public override bool MoveToElement() { ReadMethod = ReadMethods.MoveToElement; var result = BaseReader.MoveToElement(); if (result) { _XPathCollection.Advance(this); } return(result); }
protected override DictionaryWord Read() { if (BaseReader.EndOfStream) { return(null); } var line = BaseReader.ReadLine(); if (string.IsNullOrWhiteSpace(line)) { return(null); } var match = ParseRegex.Match(line); if (!match.Success) { return(null); } return(new DictionaryWord { Id = ++_wordCounter, Word = match.Groups["word"].Value, Meanings = match.Groups["meaning"].Captures .Cast <Capture>() .Select((x, i) => { var split = x.Value.Split(':'); if (split.Length == 1) { return new DictionaryMeaning { Id = i + 1, Meaning = split[0], PartOfSpeech = SynsetHelper.GetPos(split[0]) } } ; int.TryParse(split[1], out var encounters); return new DictionaryMeaning { Id = i + 1, Meaning = split[0], PartOfSpeech = SynsetHelper.GetPos(split[0]), Encounters = encounters }; }) .ToMeaningDictionary() });
protected override BaseReader CreateReader(BaseResult result, Node node) { BaseReader reader = base.CreateReader(result, node); if (reader is NewReader newReader) { this.AddParentKeys((ListResult)result, newReader); } return(reader); }
private async Task <char?> ReadCharAsync() { var buffer = _readBuffer; var readCount = await BaseReader.ReadAsync(buffer, 0, 1).ConfigureAwait(false); if (readCount <= 0) { return(null); } return(buffer[0]); }
/// <devdoc> /// <para>Moves to the attribute with the specified <see cref='XPathReader.Name' /> .</para> /// </devdoc> public override bool MoveToAttribute(string AttributeName) { ReadMethod = ReadMethods.MoveToAttribute; var ret = BaseReader.MoveToAttribute(AttributeName); if (ret) { _XPathCollection.Advance(this); } return(ret); }
/// <devdoc> /// <para> /// Reads the next /// node from the stream. /// </para> /// </devdoc> public override bool Read() { ReadMethod = ReadMethods.Read; var ret = BaseReader.Read(); if (ret) { _XPathCollection.Advance(this); } return(ret); }
/// <summary> /// Reads C-style wide (2 bytes) string (null terminated) from the stream. /// </summary> public StringReference ReadCStringWide() { StringReference value = BaseReader.ReadCStringWide(); uint size = (uint)value.Buffer.Bytes.Length + 2; if (size <= blockRemaining) { blockRemaining -= size; position += size; CheckMoveReader(); return(value); } // Check if we are reading from two consecutive blocks if (size < BlockSize * 2 && blockIndex + 1 < Blocks.Length && Blocks[blockIndex] + 1 == Blocks[blockIndex + 1]) { uint secondBlockRead = size - blockRemaining; position += size; // Seek for next block blockIndex++; if (blockIndex + 1 == Blocks.Length) { blockRemaining = (uint)(Length - position); } else { blockRemaining = BlockSize; } blockRemaining -= secondBlockRead; return(value); } // Rewind and fallback to slow reader (byte per byte) BaseReader.Position -= size; List <byte> bytes = new List <byte>(); byte b1 = ReadByte(); byte b2 = ReadByte(); while (b1 != 0 || b2 != 0) { bytes.Add(b1); bytes.Add(b2); b1 = ReadByte(); b2 = ReadByte(); } MemoryBuffer buffer = new MemoryBuffer(bytes.ToArray()); return(new StringReference(buffer, StringReference.Encoding.Unicode)); }
/// <summary> /// Moves position by the specified bytes. /// </summary> /// <param name="bytes">Number of bytes to move the stream.</param> public void Move(uint bytes) { while (bytes > blockRemaining) { bytes -= blockRemaining; Move(blockRemaining); } position += bytes; blockRemaining -= bytes; BaseReader.Move(bytes); CheckMoveReader(); }
/// <inheritdoc/> protected override void Dispose(bool disposing) { #if FEATURE_CLOSE if (ReadState != ReadState.Closed) { Close(); } #endif #if !FEATURE_XML_DISPOSE_PROTECTED BaseReader.Dispose(); #endif }
public DBReader(Stream stream) { using (var bin = new BinaryReader(stream)) { var identifier = new string(bin.ReadChars(4)); stream.Position = 0; switch (identifier) { case "WDC3": _reader = new WDC3Reader(stream); break; case "WDC2": case "1SLC": _reader = new WDC2Reader(stream); break; case "WDC1": _reader = new WDC1Reader(stream); break; case "WDB6": _reader = new WDB6Reader(stream); break; case "WDB5": _reader = new WDB5Reader(stream); break; case "WDB4": _reader = new WDB4Reader(stream); break; case "WDB3": _reader = new WDB3Reader(stream); break; case "WDB2": _reader = new WDB2Reader(stream); break; case "WDBC": _reader = new WDBCReader(stream); break; default: throw new Exception("DB type " + identifier + " is not supported!"); } } }
public string ReadLine() { if (string.IsNullOrEmpty(CommentString)) { return(BaseReader.ReadLine()); } string line = ""; do { line = BaseReader.ReadLine(); } while (line != null && line.StartsWith(CommentString)); return(line); }