public void ReadAssemblySFs(ReadingState state, List <ScriptFile> filesForReading, bool compileIgnoreExcluded) { _waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset); _activeThreads = 0; int currentIndex = 0; while (true) { for (; currentIndex < filesForReading.Count; currentIndex++) { lock (_activeThreadsLocker) { if (_activeThreads > _maxActiveThreads) { break; } } ScriptFile curSF = filesForReading[currentIndex]; if (compileIgnoreExcluded && curSF.Compile_IsExcluded) { continue; } switch (state) { case ReadingState.ScriptInfo: ReadSFInThread(curSF.ReadSI); break; case ReadingState.ScriptCode: if (!curSF.IsExtern) { ReadSFInThread(curSF.ReadSC); } break; case ReadingState.CheckCode: if (curSF.SC != null) { ReadSFInThread(curSF.CheckSC); } break; default: throw new ArgumentException("state"); } } if (_activeThreads > 0) // because this... { _waitHandle.WaitOne(60000); // it can freeze here... } else { break; } } }
void IEnumerator.Reset() { xml?.Dispose(); xml = null; columns = null; currentRow = null; state = ReadingState.Unread; } // proc Reset
public SharpPcapReader(string captureFile) { // Get an offline device _device = new CaptureFileReaderDevice(captureFile); // Open the device _device.Open(); _state = ReadingState.NotStarted; }
private void Reset(ReadingState state = ReadingState.SkipControlChars) { _message = null; _interleavedPacket = null; _chunkSize = 0; _bufferIdx = 0; _state = state; }
public RtspMessageDecoder(IPEndPoint remoteEndpoint) { _message = null; _chunkSize = 0; _bufferIdx = 0; _interleavedPacket = null; _remoteEndpoint = remoteEndpoint; _lineReader = new LineReader(); _state = ReadingState.SkipControlChars; }
} // proc CheckDisposed #endregion #region -- IEnumerator<T> ----------------------------------------------------- private bool MoveNext(bool headerOnly) { CheckDisposed(); switch (state) { case ReadingState.Unread: if (reader == null) { reader = command.ExecuteReader(CommandBehavior.SingleResult); } state = ReadingState.FetchRows; if (headerOnly) { return(true); } else { goto case ReadingState.FetchRows; } case ReadingState.FetchRows: if (!reader.Read()) { goto case ReadingState.Complete; } return(true); case ReadingState.Complete: state = ReadingState.Complete; return(false); default: throw new InvalidOperationException("The state of the object is invalid."); } // switch state } // func MoveNext
private bool GetNextFrameInternal() { if (_state == ReadingState.Closed) { throw new InvalidOperationException("Reader is not open."); } if (_state == ReadingState.Finished) { return(false); } _current = _device.GetNextPacket(); if (_current != null) { _state = ReadingState.Success; return(true); } else { _current = default; _state = ReadingState.Finished; return(false); } }
/// <inheritdoc/> public void Close() { _device.Close(); _state = ReadingState.Closed; }
private void Read() { List <StringPair> earnixAttributesList = new List <StringPair>(); try { System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(_filename); reader.WhitespaceHandling = WhitespaceHandling.None; ReadingState readingState = ReadingState.None; bool reading = false; string elementName = null; int pairIndex = 0; int nodeIndex = -1; while (reader.Read()) { // reader.MoveToContent(); nodeIndex += 1; switch (reader.NodeType) { case XmlNodeType.Element: if (_debug) { Debug.WriteLine("Element = \"" + reader.Name + "\""); // Debug.WriteLine(" " + reader.ReadElementString() ; } elementName = reader.Name; if (String.Compare(reader.Name, "attributeNames") == 0) { if (_debug) { Debug.WriteLine("Reading Earnix attribute names"); } readingState = ReadingState.Names; pairIndex = 0; } else if (String.Compare(reader.Name, "ProfileValues") == 0) { if (_debug) { Debug.WriteLine("Reading Request Earnix attribute values"); } readingState = ReadingState.Values; pairIndex = 0; } else if (String.Compare(reader.Name, "PricingResultsV6") == 0) { if (_debug) { Debug.WriteLine("Reading Response Earnix attribute values"); } readingState = ReadingState.Values; pairIndex = 0; } else if (String.Compare(reader.Name, "string") == 0) { if (reading) { Debug.WriteLine("Inconsistent state. Already reading."); } else if (readingState != ReadingState.None) { reading = true; } } break; case XmlNodeType.Text: // Reading a Response if (_debug) { Debug.WriteLine("Text = \"" + reader.Value + "\""); } switch (readingState) { case ReadingState.None: if (elementName != null) { Debug.WriteLine("Unexpected read of Value \"{0}\"", reader.Value); StringPair stringPair = new StringPair(); stringPair.First = elementName; stringPair.Second = reader.Value; earnixAttributesList.Add(stringPair); pairIndex += 1; } break; case ReadingState.Names: if (reading) { StringPair stringPair = new StringPair(); stringPair.First = reader.Value; earnixAttributesList.Add(stringPair); pairIndex += 1; } else { Debug.WriteLine("Unexpected read of Name \"{0}\"", reader.Value); StringPair stringPair = new StringPair(); stringPair.First = elementName; stringPair.Second = reader.Value; earnixAttributesList.Add(stringPair); pairIndex += 1; } break; case ReadingState.Values: { if (reading) { if (pairIndex >= earnixAttributesList.Count) { Debug.WriteLine("Attribute Count {0} out bounds of {1} List Members", pairIndex, earnixAttributesList.Count); } else { earnixAttributesList[pairIndex].Second = reader.Value; pairIndex += 1; } } else { Debug.WriteLine("Unexpected read of Value \"{0}\"", reader.Value); StringPair stringPair = new StringPair(); stringPair.First = elementName; stringPair.Second = reader.Value; earnixAttributesList.Add(stringPair); pairIndex += 1; } } break; } break; case XmlNodeType.CDATA: if (_debug) { Debug.WriteLine("CDATA = \"" + reader.Value + "\""); } // Reading a Request switch (readingState) { case ReadingState.None: if (elementName != null) { Debug.WriteLine("Unexpected read of Value \"{0}\"", reader.Value); StringPair stringPair = new StringPair(); stringPair.First = elementName; stringPair.Second = reader.Value; earnixAttributesList.Add(stringPair); pairIndex += 1; } break; case ReadingState.Names: if (reading) { StringPair stringPair = new StringPair(); stringPair.First = reader.Value; earnixAttributesList.Add(stringPair); pairIndex += 1; } else { Debug.WriteLine("Unexpected read of Name \"{0}\"", reader.Value); StringPair stringPair = new StringPair(); stringPair.First = elementName; stringPair.Second = reader.Value; earnixAttributesList.Add(stringPair); pairIndex += 1; } break; case ReadingState.Values: if (reading) { if (pairIndex >= earnixAttributesList.Count) { Debug.WriteLine("Attribute Count {0} out bounds of {1} List Members", pairIndex, earnixAttributesList.Count); } else { earnixAttributesList[pairIndex].Second = reader.Value; pairIndex += 1; } } else { Debug.WriteLine("Unexpected read of Value \"{0}\"", reader.Value); StringPair stringPair = new StringPair(); stringPair.First = elementName; stringPair.Second = reader.Value; earnixAttributesList.Add(stringPair); pairIndex += 1; } break; } break; case XmlNodeType.ProcessingInstruction: if (_debug) { Debug.WriteLine("Processing = \"" + reader.Name + "\"=\"" + reader.Value + "\""); } break; case XmlNodeType.Comment: if (_debug) { Debug.WriteLine("Comment = \"" + reader.Value + "\""); } break; case XmlNodeType.XmlDeclaration: if (_debug) { Debug.WriteLine("Declaration \"<?xml version='1.0'?>\""); } break; case XmlNodeType.Document: case XmlNodeType.DocumentType: if (_debug) { Debug.WriteLine("DOC Type =\"" + reader.Name + "\" Value = \"" + reader.Value + "\""); } break; case XmlNodeType.EntityReference: if (_debug) { Debug.WriteLine("Entity Reference = \"" + reader.Name + "\""); } break; case XmlNodeType.EndElement: if (_debug) { Debug.WriteLine("End Element \"" + reader.Name + "\""); } reading = false; elementName = null; break; default: Debug.WriteLine("Unknown Node Type " + reader.NodeType.ToString()); break; } // switch ( reader.NodeType ) } // while } // try catch (System.ArgumentException) { _errorText = String.Format("Invalid filename \"{0}\"", _filename); } catch (System.IO.FileNotFoundException) { _errorText = String.Format("File not found \"{0}\"", _filename); } catch (System.IO.IOException eek) { _errorText = String.Format("File \"{0}\" : System.IO.IOException \"{1}\"", _filename, eek.ToString()); } _earnixAttributesDictionary.Clear(); foreach (StringPair stringPair in earnixAttributesList) { _earnixAttributesDictionary.Add(stringPair.First, stringPair.Second); } } // Read
/// <summary> /// Sets the read state of this source to a value. /// </summary> public void SetReadingState(IntercomSide source, ReadingState state) { Shared.Write((long)source, (byte)state); }
private void ReadLine(string line, out List <int> numbers, out List <ConnectionType> connections) { numbers = new List <int>(); connections = new List <ConnectionType>(); string currentSection = ""; ReadingState state = ReadingState.ReadingNumber; for (int i = 0; i < line.Length; i++) { if (state == ReadingState.ReadingNumber) { if (line[i] >= '0' && line[i] <= '9') { currentSection += line[i]; } else if (IsConnectionChar(line[i])) { int.TryParse(currentSection, out int num); numbers.Add(num); currentSection = line[i].ToString(); state = ReadingState.ReadingConnection; } else { throw new FormatException("Error reading file!"); } } else if (state == ReadingState.ReadingConnection) { if (IsConnectionChar(line[i])) { currentSection += line[i]; } else if (line[i] >= '0' && line[i] <= '9') { ConnectionType connection = GetConnectionType(currentSection); if (connection == ConnectionType.Error) { throw new FormatException("Error reading file!"); } connections.Add(connection); currentSection = line[i].ToString(); state = ReadingState.ReadingNumber; } else { throw new FormatException("Error reading file!"); } } } if (state == ReadingState.ReadingNumber) { int.TryParse(currentSection, out int num); numbers.Add(num); } else { throw new FormatException("Error reading file!"); } return; }
/// <summary> /// Reads one message. /// </summary> /// <param name="commandStream">The Rtsp stream.</param> /// <returns>Message readen</returns> public RtspChunk ReadOneMessage(Stream commandStream) { if (commandStream == null) { throw new ArgumentNullException("commandStream"); } Contract.EndContractBlock(); ReadingState currentReadingState = ReadingState.NewCommand; // current decode message , create a fake new to permit compile. RtspChunk currentMessage = null; int size = 0; int byteReaden = 0; List <byte> buffer = new List <byte>(256); string oneLine = String.Empty; while (currentReadingState != ReadingState.End) { // if the system is not reading binary data. if (currentReadingState != ReadingState.Data && currentReadingState != ReadingState.MoreInterleavedData) { oneLine = String.Empty; bool needMoreChar = true; // I do not know to make readline blocking while (needMoreChar) { int currentByte = commandStream.ReadByte(); switch (currentByte) { case -1: // the read is blocking, so if we got -1 it is because the client close; currentReadingState = ReadingState.End; needMoreChar = false; break; case '\n': oneLine = ASCIIEncoding.UTF8.GetString(buffer.ToArray()); buffer.Clear(); needMoreChar = false; break; case '\r': // simply ignore this break; case '$': // if first caracter of packet is $ it is an interleaved data packet if (currentReadingState == ReadingState.NewCommand && buffer.Count == 0) { currentReadingState = ReadingState.InterleavedData; needMoreChar = false; } else { goto default; } break; default: buffer.Add((byte)currentByte); break; } } } switch (currentReadingState) { case ReadingState.NewCommand: currentMessage = RtspMessage.GetRtspMessage(oneLine); currentReadingState = ReadingState.Headers; break; case ReadingState.Headers: string line = oneLine; if (string.IsNullOrEmpty(line)) { currentReadingState = ReadingState.Data; ((RtspMessage)currentMessage).InitialiseDataFromContentLength(); } else { ((RtspMessage)currentMessage).AddHeader(line); } break; case ReadingState.Data: if (currentMessage.Data.Length > 0) { // Read the remaning data byteReaden += commandStream.Read(currentMessage.Data, byteReaden, currentMessage.Data.Length - byteReaden); //_logger.Debug(CultureInfo.InvariantCulture, "Readen {0} byte of data", byteReaden); } // if we haven't read all go there again else go to end. if (byteReaden >= currentMessage.Data.Length) { currentReadingState = ReadingState.End; } break; case ReadingState.InterleavedData: currentMessage = new RtspData(); ((RtspData)currentMessage).Channel = commandStream.ReadByte(); size = (commandStream.ReadByte() << 8) + commandStream.ReadByte(); currentMessage.Data = new byte[size]; currentReadingState = ReadingState.MoreInterleavedData; break; case ReadingState.MoreInterleavedData: // apparently non blocking byteReaden += commandStream.Read(currentMessage.Data, byteReaden, size - byteReaden); if (byteReaden < size) { currentReadingState = ReadingState.MoreInterleavedData; } else { currentReadingState = ReadingState.End; } break; default: break; } } if (currentMessage != null) { currentMessage.SourcePort = this; } return(currentMessage); }
private bool isEndingReadFirstRow(OpenXmlReader reader, ReadingState firstRowState) { return(reader.ElementType == typeof(Row) && reader.IsEndElement && firstRowState == ReadingState.Reading); }
public void Reset() { _device.Close(); _device.Open(); _state = ReadingState.NotStarted; }
public int UpdatePvcsForPromotionGroup(string pvcsUserId, BuildSetDetails buildsetDetails, string gitLogReportFilenameWithPath) { int error = 0; PvcsPromotionGroupData promotionGroupData = GetPromotionGroupData(buildsetDetails.SecondaryIdentifier); if (promotionGroupData == null) { Console.WriteLine("PvcsPromotionGroupDataSortedSet.UpdatePvcsForPromotionGroup : Promotion Group \"{0}\" is not known", buildsetDetails.SecondaryIdentifier); error = WindowsErrorDefinition.BadEnvironment; } else { // Promotion Group is known if (!File.Exists(gitLogReportFilenameWithPath)) { Console.WriteLine("PvcsPromotionGroupDataSortedSet.UpdatePvcsForPromotionGroup : git log report file \"{0}\" does not exist", gitLogReportFilenameWithPath); error = WindowsErrorDefinition.FileNotFound; } else { // git log report file exists Console.WriteLine("Current directory is \"{0}\"", Directory.GetCurrentDirectory()); using (StreamReader gitLogFileStream = new StreamReader(gitLogReportFilenameWithPath)) { string gitLogLine = null; int lineNumber = 0; int commitCount = 0; int commitAttributeCount = 0; PvcsCommitData pvcsCommitData = null; // One object reused for each commit ReadingState readingState = ReadingState.Reading; while (((gitLogLine = gitLogFileStream.ReadLine()) != null) && (error == WindowsErrorDefinition.Success)) { lineNumber += 1; Console.WriteLine("{0,-2} : {1}", lineNumber.ToString("###"), gitLogLine); if (!gitLogLine.StartsWith("#")) { // Not a commented out line switch (readingState) { case ReadingState.Reading: // Check for entering a processing state if (gitLogLine == "+++") { readingState = ReadingState.ProcessingCommitAttributes; commitCount += 1; commitAttributeCount = 0; // Replace any existing commit data pvcsCommitData = new PvcsCommitData(pvcsUserId); } break; case ReadingState.ProcessingCommitAttributes: // Check for a exiting a commit attributs processing state if (gitLogLine == "---") { readingState = ReadingState.ProcessingCommitFilenames; } else { // Process the attribute switch (commitAttributeCount) { case 0: // Must be the Commit Hash pvcsCommitData.Hash = gitLogLine; commitAttributeCount += 1; break; case 1: // Must be the email address pvcsCommitData.emailAddress = gitLogLine; commitAttributeCount += 1; break; case 2: { // Must be the Commit Data/Time try { pvcsCommitData.DateTime = System.Convert.ToDateTime(gitLogLine); } catch (Exception) { pvcsCommitData.DateTime = DateTime.Now; Console.WriteLine("{0} : Line Number {1} : Unable to convert \"{2}\" to a DateTime, Defaulting to \"Now\" = {3}", gitLogReportFilenameWithPath, lineNumber, gitLogLine, pvcsCommitData.DateTime.ToString("yyyy-MM-dd HH:mm:ss")); } commitAttributeCount += 1; break; } case 3: // Cope with multi-line descriptions if (String.IsNullOrEmpty(pvcsCommitData.Description)) { commitAttributeCount += 1; } if (!(String.IsNullOrEmpty(gitLogLine)) && (!String.IsNullOrWhiteSpace(gitLogLine))) { if (String.IsNullOrEmpty(pvcsCommitData.Description)) { pvcsCommitData.Description = gitLogLine; } else { // Separate multiple lines with a space pvcsCommitData.Description += " " + gitLogLine; } } break; default: Console.WriteLine("PvcsPromotionGroupDataSortedSet.UpdatePvcsForPromotionGroup : Unexpected Commit Attribute Index {0}", commitAttributeCount); break; } } // Process the attribute break; case ReadingState.ProcessingCommitFilenames: if (gitLogLine.Length == 0) { // Nothing to do } else if (gitLogLine == "+++") { // Found the next commit entry so process this one error = pvcsCommitData.Commit(pvcsUserId, buildsetDetails, promotionGroupData, this); if (error == WindowsErrorDefinition.Success) { // Go back to processing commit attributes readingState = ReadingState.ProcessingCommitAttributes; commitCount += 1; commitAttributeCount = 0; pvcsCommitData = new PvcsCommitData(pvcsUserId); } // Go back to processing commit attributes } // Found the next commit entry so process this one else { // Process the filename string commitstatus = new string(gitLogLine.ToCharArray(), 0, 1); string filename = gitLogLine.Substring(1).Trim(); // Replace all forward slashes with back slashes filename = filename.Replace("/", "\\"); PvcsCommitFileData pvcsCommitFileData = new PvcsCommitFileData(filename, commitstatus); pvcsCommitData.PvcsCommitFileDataCollection.Add(pvcsCommitFileData); } // Process the filename break; default: Console.WriteLine("Reading \"{0}\" : Unexpected Reading State = \"{1}\"", gitLogReportFilenameWithPath, readingState.ToString()); break; } // switch } // Not a commented out line } // while if (error == WindowsErrorDefinition.Success) { // Ensure it was committed error = pvcsCommitData.Commit(pvcsUserId, buildsetDetails, promotionGroupData, this); } if (error == WindowsErrorDefinition.Success) { Console.WriteLine("PvcsPromotionGroupDataSortedSet.UpdatePvcsForPromotionGroup : Successfully processed {0} PVCS Commits", commitCount); } else { Console.WriteLine("PvcsPromotionGroupDataSortedSet.UpdatePvcsForPromotionGroup : Processed {0} PVCS Commits with error {1}", commitCount, error); } } // using } // git log report file exists } // Promotion Group is known return(error); } // UpdatePvcsForPromotionGroup
} // proc Dispose #endregion #region -- IEnumerator ------------------------------------------------------------ private bool MoveNext(bool headerOnly) { switch (state) { #region -- ReadingState.Unread -- case ReadingState.Unread: // open the xml stream xml = owner.request.GetXmlStreamAsync(owner.path, owner.acceptedMimeType).Result; xml.Read(); if (xml.NodeType == XmlNodeType.XmlDeclaration) { xml.Read(); } if (xml.NodeType != XmlNodeType.Element || xml.LocalName != xnView.LocalName) { throw new InvalidDataException($"Expected \"{xnView}\", read \"{xml.LocalName}\"."); } xml.Read(); if (xml.NodeType != XmlNodeType.Element || xml.LocalName != xnFields.LocalName) { throw new InvalidDataException($"Expected \"{xnFields}\", read \"{xml.LocalName}\"."); } var viewColumns = new List <ViewDataColumn>(); var fields = (XElement)XNode.ReadFrom(xml); foreach (var field in fields.Elements()) { var columnName = field.Name.LocalName; var columnDataType = LuaType.GetType(field.GetAttribute("type", "string"), lateAllowed: false).Type; var columnId = field.GetAttribute("field", String.Empty); var attributes = new PropertyDictionary(); // add colum id if (!String.IsNullOrEmpty(columnId)) { attributes.SetProperty("field", typeof(string), columnId); } foreach (var c in field.Elements("attribute")) { if (c.IsEmpty) { continue; } var attributeName = c.GetAttribute("name", String.Empty); if (String.IsNullOrEmpty(attributeName)) { continue; } attributes.SetProperty(attributeName, LuaType.GetType(c.GetAttribute("type", "string"), lateAllowed: false).Type, c.Value); } // foreach c viewColumns.Add(new ViewDataColumn(columnName, columnDataType, attributes)); } // foreach field if (viewColumns.Count < 1) { throw new InvalidDataException("No header found."); } columns = viewColumns.ToArray(); state = ReadingState.FetchFirstRow; if (headerOnly) { return(true); } else { goto case ReadingState.FetchFirstRow; } #endregion #region -- ReadingState.FetchFirstRow -- case ReadingState.FetchFirstRow: if (xml.NodeType != XmlNodeType.Element || xml.LocalName != xnRows.LocalName) { throw new InvalidDataException($"Expected \"{xnRows}\", read \"{xml.LocalName}\"."); } if (xml.IsEmptyElement) { xml.Read(); if (xml.NodeType != XmlNodeType.EndElement || xml.LocalName != xnView.LocalName) { throw new InvalidDataException($"Expected \"{xnView}\", read \"{xml.LocalName}\"."); } xml.Read(); if (!xml.EOF) { throw new InvalidDataException("Unexpected eof."); } state = ReadingState.Complete; goto case ReadingState.Complete; } // if xml.IsEmptyElement else { xml.Read(); state = ReadingState.FetchRows; goto case ReadingState.FetchRows; } #endregion #region -- ReadingState.FetchRows -- case ReadingState.FetchRows: if (xml.NodeType != XmlNodeType.Element || xml.LocalName != xnRow.LocalName) { throw new InvalidDataException($"Expected \"r\", read \"{xml.LocalName}\"."); } var values = new object[columns.Length]; if (!xml.IsEmptyElement) { var rowData = (XElement)XNode.ReadFrom(xml); foreach (var column in rowData.Elements()) { var columnIndex = Array.FindIndex(columns, c => String.Compare(c.Name, column.Name.LocalName, StringComparison.OrdinalIgnoreCase) == 0); if (columnIndex != -1) { values[columnIndex] = Procs.ChangeType(column.Value, columns[columnIndex].DataType); } } } // if xml.IsEmptyElement else { // Without a call to XNode.ReadFrom() it's necessary to read to the next node. xml.Read(); } currentRow = new ViewDataRow(this, values); if (xml.NodeType == XmlNodeType.Element && xml.LocalName == xnRow.LocalName) { return(true); } if (xml.NodeType != XmlNodeType.EndElement || xml.LocalName != xnRows.LocalName) { throw new InvalidDataException($"Expected \"{xnRows}\", read \"{xml.LocalName}\"."); } xml.Read(); if (xml.NodeType != XmlNodeType.EndElement || xml.LocalName != xnView.LocalName) { throw new InvalidDataException($"Expected \"{xnView}\", read \"{xml.LocalName}\"."); } xml.Read(); if (!xml.EOF) { throw new InvalidDataException("Unexpected eof."); } state = ReadingState.Complete; return(true); #endregion case ReadingState.Complete: return(false); default: throw new InvalidOperationException("The state of the object is invalid."); } // switch state } // func MoveNext
public void ReadAssemblySFs(ReadingState state, List <ScriptFile> filesForReading) { ReadAssemblySFs(state, filesForReading, false); }
public void ReadAssemblySFs(ReadingState state) { ReadAssemblySFs(state, GetAllSFs(), false); }
public bool Decode(MemoryStream stream, out RtspChunk chunk) { chunk = null; using (var reader = new BinaryReader(stream, Encoding.UTF8, true)) { switch (_state) { case ReadingState.SkipControlChars: { SkipControlCharacters(reader); _state = ReadingState.ReadInitial; break; } case ReadingState.ReadInitial: { char currentChar = Convert.ToChar(reader.PeekChar()); if (currentChar == INTERLEAVED_MARKER) { _state = ReadingState.ReadInterleavedData; return(false); } else { try { string line = _lineReader.Read(reader); string[] parts = SplitInitialLine(line); if (parts.Length < 3) { // This is an invalid initial line just ignore it. LOG.Warn($"Invalid start of RTSP message: '{line}', ignoring..."); _state = ReadingState.SkipControlChars; return(false); } else { _message = RtspMessage.CreateNewMessage(parts, _remoteEndpoint); _state = ReadingState.ReadHeader; } } catch (Exception e) { LOG.Error($"Failed to parse RTSP message, reason: {e.Message}"); _state = ReadingState.BadMessage; } } break; } case ReadingState.ReadHeader: { _state = ReadHeaders(_message, reader); // If the check size is greater than zero it will be decreased as the // ReadFixedContentLength state reads the body chunk by chunk. _chunkSize = _message.ContentLength; if (_state == ReadingState.SkipControlChars || (_chunkSize <= 0)) { // No content data expected. // TODO(frank.lamar): Add support for chunking. Not important // at the moment because I have yet to see a device use chunking. chunk = _message; Reset(); return(true); } break; } case ReadingState.ReadFixedContentLength: { if (_bufferIdx == 0) { // We are reading the first chunk of data. We need to first // allocate the message's data array. _message.Body = new byte[_chunkSize]; } int bytesRead = reader.Read(_message.Body, _bufferIdx, _chunkSize); _chunkSize -= bytesRead; // Decrement the bytes read from the chunk size. _bufferIdx += bytesRead; // Increment the index to write next chunk to. if (_chunkSize == 0) { chunk = _message; Reset(); return(true); } break; } case ReadingState.ReadInterleavedData: { if (_chunkSize == 0 && _bufferIdx == 0) { reader.ReadByte(); // Consume the '$' marker left in the buffer. byte channel = reader.ReadByte(); _chunkSize = GetUint16(reader); _interleavedPacket = new InterleavedData(channel); _interleavedPacket.Payload = new byte[_chunkSize]; } int bytesRead = reader.Read(_interleavedPacket.Payload, _bufferIdx, _chunkSize); _chunkSize -= bytesRead; // Decrement the bytes read from the chunk size. _bufferIdx += bytesRead; // Increment the index to write next chunk to. if (_chunkSize == 0) { chunk = _interleavedPacket; Reset(); return(true); } break; } case ReadingState.BadMessage: { LOG.Debug("Unable to decode RTSP message, ignoring messsage"); stream.Seek(0, SeekOrigin.End); // Skip the remaining buffer. Reset(); break; } default: { LOG.Warn($"Unknown state: {_state}"); Reset(); break; } } } return(false); }
private bool isStartingReadFirstRow(OpenXmlReader reader, ReadingState firstRowState) { return(reader.ElementType == typeof(Row) && reader.IsStartElement && firstRowState == ReadingState.NotStarted); }