示例#1
0
 private void OnProcessedStream(ProcessedStreamEventArgs ea)
 {
     if (null != this.ProcessedStream)
     {
         this.ProcessedStream(this, ea);
     }
 }
示例#2
0
        public XmlDocument Process(string sourceFile, Hashtable variables)
        {
            Stream      processed      = new MemoryStream();
            XmlDocument sourceDocument = new XmlDocument();

            try
            {
                this.core = new PreprocessorCore(sourceFile, variables);
                this.core.CurrentPlatform = this.currentPlatform;
                this.currentFileStack.Clear();
                this.currentFileStack.Push(this.core.GetVariableValue("sys", "SOURCEFILEDIR"));

                // open the source file for processing
                using (Stream sourceStream = new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    XmlReader     reader = new XmlTextReader(sourceStream);
                    XmlTextWriter writer = new XmlTextWriter(processed, Encoding.UTF8);

                    // process the reader into the writer
                    try
                    {
                        this.PreprocessReader(false, reader, writer, 0);
                    }
                    catch (XmlException e)
                    {
                        throw new Exception(e.Message);
                    }

                    writer.Flush();
                }

                // fire event with processed stream
                ProcessedStreamEventArgs args = new ProcessedStreamEventArgs(sourceFile, processed);
                this.OnProcessedStream(args);

                // create an XML Document from the post-processed memory stream
                XmlTextReader xmlReader = null;

                try
                {
                    // create an XmlReader with the path to the original file
                    // to properly set the BaseURI property of the XmlDocument
                    processed.Position = 0;
                    xmlReader          = new XmlTextReader(new Uri(Path.GetFullPath(sourceFile)).AbsoluteUri, processed);
                    sourceDocument.Load(xmlReader);
                }
                catch (XmlException e)
                {
                    throw new Exception(e.Message);
                }
                finally
                {
                    if (null != xmlReader)
                    {
                        xmlReader.Close();
                    }
                }
            }
            finally
            {
                ;
            }

            if (this.core.EncounteredError)
            {
                return(null);
            }
            else
            {
                if (null != this.preprocessOut)
                {
                    sourceDocument.Save(this.preprocessOut);
                    this.preprocessOut.Flush();
                }

                return(sourceDocument);
            }
        }