Exemplo n.º 1
0
        internal void AddErrorRecoveryNode(XmlNode parent, Node ctx, string error)
        {
            this.errorHandler.HandleError(ctx, error, this.scanner.GetString());
            XmlError xmlError = new XmlError();

            xmlError.SourceContext = this.scanner.CurrentSourceContext;
            this.SkipToTagEnd();
            xmlError.SourceContext.EndCol = this.scanner.CurrentSourceContext.EndCol;
            parent.AddChild((Node)xmlError);
            parent.SourceContext.EndCol = this.scanner.CurrentSourceContext.EndCol;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reports given <see cref="XmlError"/> using internal error handler or forwards the error to common error handler.
        /// </summary>
        /// <param name="err">Error to report;</param>
        public static void IssueXmlError(XmlError err)
        {
            if (err == null)
            {
                return;
            }

            if (error_handler != null)
            {
                error_handler(err);
            }
            else
            {
                PhpException.Throw(PhpError.Warning, err.ToString());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reports given <see cref="XmlError"/> using internal error handler or forwards the error to common error handler.
        /// </summary>
        /// <param name="err">Error to report;</param>
        public static void IssueXmlError(XmlError err)
        {
            if (err == null)
                return;

            if (error_handler != null)
            {
                error_handler(err);
            }
            else
            {
                PhpException.Throw(PhpError.Warning, err.ToString());
            }
        }
Exemplo n.º 4
0
        private void Worker()
        {
            try
            {
                var request = (HttpWebRequest)WebRequest.Create(Url);
                using (var response = (HttpWebResponse)request.GetResponse())
                    using (var stream = response.GetResponseStream())
                        using (var reader = new StreamReader(stream, Encoding.GetEncoding("utf-8")))
                        {
                            // Set Read Buffer
                            var buffer = new char[1048576]; // 1 MB
                            int i      = reader.Read(buffer, 0, buffer.Length);

                            string xml = "";

                            while (i > 0 && !stop.WaitOne(0, true))
                            {
                                // Get string from buffer
                                var s = new string(buffer, 0, i);

                                // Find Beginning of XML (exclude HTTP header)
                                int b = s.IndexOf("<?xml ");
                                if (b >= 0)
                                {
                                    s = s.Substring(b);
                                }

                                // Add buffer to XML
                                xml += s;

                                // Find Closing Tag
                                int c = FindClosingTag(xml);

                                // Test if End of XML
                                if (c >= 0)
                                {
                                    b = xml.LastIndexOf("<?xml ");
                                    if (c > b)
                                    {
                                        // Raise XML Received Event and pass XML
                                        XmlReceived?.Invoke(xml.Substring(b, c - b));

                                        // Remove MTConnect document from xml
                                        xml = xml.Remove(b, c - b).Trim();
                                    }

                                    if (!string.IsNullOrEmpty(xml))
                                    {
                                        // Raise XML Error and break from while
                                        XmlError?.Invoke(xml);
                                        break;
                                    }

                                    // Reset XML
                                    xml = "";
                                }

                                // Clear Buffer
                                Array.Clear(buffer, 0, buffer.Length);

                                // Read Next Chunk
                                i = reader.Read(buffer, 0, buffer.Length);
                            }
                        }
            }
            catch (Exception ex)
            {
                ConnectionError?.Invoke(ex);
            }
        }
Exemplo n.º 5
0
 private void SampleStream_XmlError(string xml)
 {
     XmlError?.Invoke(xml);
 }