示例#1
0
        public async Task <Match> ReadUntilMatchAsync(string pattern, CancellationToken cancelToken)
        {
            Match  match;
            string header;
            int    ret;

            do
            {
                header = m_xmlStream.processNextXMLTag();
                while (header == "") //there's nothing in the buffer or incomplete tags
                {
                    ret = await ReadFromStreamAsync(cancelToken);

                    header = m_xmlStream.processNextXMLTag();
                }

                match = Regex.Match(header, pattern);

                if (!match.Success)
                {
                    LogMessage("WARNING: Unexpected XML tag in ReadUntilMatchAsync(): " + header);
                    LogMessage("Buffer contents: " + Encoding.Default.GetString(m_xmlStream.getBuffer()));
                }
            }while (!match.Success);

            return(match);
        }
示例#2
0
        public void CheckCancellationRequests()
        {
            try
            {
                if (!m_netStream.DataAvailable)
                {
                    return;
                }

                XMLStream inputXMLStream = new XMLStream();
                var       bytes          = m_netStream.Read(inputXMLStream.getBuffer(), inputXMLStream.getBufferOffset(),
                                                            inputXMLStream.getBufferSize() - inputXMLStream.getBufferOffset());

                inputXMLStream.addBytesRead(bytes);
                //we let the xmlstream object know that some bytes have been read in its buffer
                string xmlItem = inputXMLStream.peekNextXMLItem();
                if (xmlItem != "")
                {
                    string xmlItemContent = inputXMLStream.getLastXMLItemContent();
                    if (xmlItemContent == JobTransmitter.m_quitMessage)
                    {
                        inputXMLStream.addProcessedBytes(bytes);
                        inputXMLStream.discardProcessedData();
                        LogMessage("Stopping job execution");
                        m_cancelTokenSource.Cancel();
                    }
                }
            }
            catch (IOException)
            {
                LogMessage("IOException in CheckCancellationRequests()");
            }
            catch (OperationCanceledException)
            {
                LogMessage("Thread finished gracefully");
            }
            catch (ObjectDisposedException)
            {
                LogMessage("Network stream closed: async read finished");
            }
            catch (InvalidOperationException ex)
            {
                LogMessage("InvalidOperationException in CheckCancellationRequests");
                LogMessage(ex.ToString());
            }
            catch (Exception ex)
            {
                LogMessage("Unhandled exception in CheckCancellationRequests");
                LogMessage(ex.ToString());
            }
        }