/// <summary>
        ///
        /// </summary>
        /// <param name="file"></param>
        /// <param name="solutions"></param>
        /// <returns></returns>
        public void ProcessFile(string file, IList <SolutionNode> solutions)
        {
            m_CurrentWorkingDirectory.Push();

            string path = file;

            try
            {
                try
                {
                    path = Helper.ResolvePath(path);
                }
                catch (ArgumentException)
                {
                    m_Log.Write("Could not open Prebuild file: " + path);
                    m_CurrentWorkingDirectory.Pop();
                    return;
                }

                Helper.SetCurrentDir(Path.GetDirectoryName(path));

                XmlTextReader reader = new XmlTextReader(path);

                Core.Parse.Preprocessor pre = new Core.Parse.Preprocessor();

                //register command line arguments as XML variables
                IEnumerator <KeyValuePair <string, string> > dict = m_CommandLine.GetEnumerator();
                while (dict.MoveNext())
                {
                    string name = dict.Current.Key.Trim();
                    if (name.Length > 0)
                    {
                        pre.RegisterVariable(name, dict.Current.Value);
                    }
                }

                string xml = pre.Process(reader);                //remove script and evaulate pre-proccessing to get schema-conforming XML

                // See if the user put into a pseudo target of "prebuild:preprocessed-input" to indicate they want to see the
                // output before the system processes it.
                if (m_CommandLine.WasPassed("ppi"))
                {
                    // Get the filename if there is one, otherwise use a default.
                    string ppiFile = m_CommandLine["ppi"];
                    if (ppiFile == null || ppiFile.Trim().Length == 0)
                    {
                        ppiFile = "preprocessed-input.xml";
                    }

                    // Write out the string to the given stream.
                    try
                    {
                        using (StreamWriter ppiWriter = new StreamWriter(ppiFile))
                        {
                            ppiWriter.WriteLine(xml);
                        }
                    }
                    catch (IOException ex)
                    {
                        Console.WriteLine("Could not write PPI file '{0}': {1}", ppiFile, ex.Message);
                    }

                    // Finish processing this special tag.
                    return;
                }

                m_CurrentDoc = new XmlDocument();
                try
                {
#if NO_VALIDATE
                    XmlReader validator = XmlReader.Create(new StringReader(xml));
                    m_CurrentDoc.Load(validator);
#else
                    XmlValidatingReader validator = new XmlValidatingReader(new XmlTextReader(new StringReader(xml)));

                    //validate while reading from string into XmlDocument DOM structure in memory
                    foreach (XmlSchema schema in m_Schemas)
                    {
                        validator.Schemas.Add(schema);
                    }
                    m_CurrentDoc.Load(validator);
#endif
                }
                catch (XmlException e)
                {
                    throw new XmlException(e.ToString());
                }

                //is there a purpose to writing it?  An syntax/schema problem would have been found during pre.Process() and reported with details
                if (m_CommandLine.WasPassed("ppo"))
                {
                    string ppoFile = m_CommandLine["ppo"];
                    if (ppoFile == null || ppoFile.Trim().Length < 1)
                    {
                        ppoFile = "preprocessed.xml";
                    }

                    StreamWriter writer = null;
                    try
                    {
                        writer = new StreamWriter(ppoFile);
                        writer.Write(xml);
                    }
                    catch (IOException ex)
                    {
                        Console.WriteLine("Could not write PPO file '{0}': {1}", ppoFile, ex.Message);
                    }
                    finally
                    {
                        if (writer != null)
                        {
                            writer.Close();
                        }
                    }
                    return;
                }
                //start reading the xml config file
                XmlElement rootNode = m_CurrentDoc.DocumentElement;
                //string suggestedVersion = Helper.AttributeValue(rootNode,"version","1.0");
                Helper.CheckForOSVariables = Helper.ParseBoolean(rootNode, "checkOsVars", false);

                foreach (XmlNode node in rootNode.ChildNodes)               //solutions or if pre-proc instructions
                {
                    IDataNode dataNode = ParseNode(node, null);
                    if (dataNode is ProcessNode)
                    {
                        ProcessNode proc = (ProcessNode)dataNode;
                        if (proc.IsValid)
                        {
                            ProcessFile(proc.Path);
                        }
                    }
                    else if (dataNode is SolutionNode)
                    {
                        solutions.Add((SolutionNode)dataNode);
                    }
                }
            }
            catch (XmlSchemaException xse)
            {
                m_Log.Write("XML validation error at line {0} in {1}:\n\n{2}",
                            xse.LineNumber, path, xse.Message);
            }
            finally
            {
                m_CurrentWorkingDirectory.Pop();
            }
        }
Exemple #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
		public void ProcessFile(string file, IList solutions)
		{
			m_CurrentWorkingDirectory.Push();
            
			string path = file;
			try
			{
				try
				{
					path = Helper.ResolvePath(path);
				}
				catch(ArgumentException)
				{
					m_Log.Write("Could not open Prebuild file: " + path);
					m_CurrentWorkingDirectory.Pop();
					return;
				}

				m_CurrentFile = path;
				Helper.SetCurrentDir(Path.GetDirectoryName(path));
				
				XmlTextReader reader = new XmlTextReader(path);

                Core.Parse.Preprocessor pre = new Core.Parse.Preprocessor();

                //register command line arguments as XML variables
                IDictionaryEnumerator dict = m_CommandLine.GetEnumerator();
                while (dict.MoveNext())
                {
                    string name = dict.Key.ToString().Trim();
                    if (name.Length > 0)
                        pre.RegisterVariable(name, dict.Value.ToString());
                }

				string xml = pre.Process(reader);//remove script and evaulate pre-proccessing to get schema-conforming XML

				
				m_CurrentDoc = new XmlDocument();
				try
				{
					XmlValidatingReader validator = new XmlValidatingReader(new XmlTextReader(new StringReader(xml)));

					//validate while reading from string into XmlDocument DOM structure in memory
					foreach(XmlSchema schema in m_Schemas) 
					{
						validator.Schemas.Add(schema);
					}
					m_CurrentDoc.Load(validator);
				} 
				catch(XmlException e) 
				{
					throw new XmlException(e.ToString());
				}

				//is there a purpose to writing it?  An syntax/schema problem would have been found during pre.Process() and reported with details
				if(m_CommandLine.WasPassed("ppo"))
				{
					string ppoFile = m_CommandLine["ppo"];
					if(ppoFile == null || ppoFile.Trim().Length < 1)
					{
						ppoFile = "preprocessed.xml";
					}

					StreamWriter writer = null;
					try
					{
						writer = new StreamWriter(ppoFile);
						writer.Write(xml);
					}
					catch(IOException ex)
					{
						Console.WriteLine("Could not write PPO file '{0}': {1}", ppoFile, ex.Message);
					}
					finally
					{
						if(writer != null)
						{
							writer.Close();
						}
					}
					return;
				}
				//start reading the xml config file
				XmlElement rootNode = m_CurrentDoc.DocumentElement;
				//string suggestedVersion = Helper.AttributeValue(rootNode,"version","1.0");
				Helper.CheckForOSVariables = Helper.ParseBoolean(rootNode,"checkOsVars",false);

				foreach(XmlNode node in rootNode.ChildNodes)//solutions or if pre-proc instructions
				{
					IDataNode dataNode = ParseNode(node, null);
					if(dataNode is ProcessNode)
					{
						ProcessNode proc = (ProcessNode)dataNode;
						if(proc.IsValid)
						{
							ProcessFile(proc.Path);
						}
					}
					else if(dataNode is SolutionNode)
					{
						solutions.Add(dataNode);
					}
				}
			}
			catch(XmlSchemaException xse)
			{
				m_Log.Write("XML validation error at line {0} in {1}:\n\n{2}",
					xse.LineNumber, path, xse.Message);
			}
			finally
			{
				m_CurrentWorkingDirectory.Pop();
			}
		}
Exemple #3
0
        private void ProcessFile(string file)
        {
            m_CurrentWorkingDirectory.Push();

            string path = file;

            try
            {
                try
                {
                    path = Helper.ResolvePath(path);
                }
                catch (ArgumentException)
                {
                    m_Log.Write("Could not open Prebuild file: " + path);
                    m_CurrentWorkingDirectory.Pop();
                    return;
                }

                m_CurrentFile = path;
                Helper.SetCurrentDir(Path.GetDirectoryName(path));


                XmlTextReader reader = new XmlTextReader(path);

                Core.Parse.Preprocessor pre = new Core.Parse.Preprocessor();

                //register command line arguments as XML variables
                IDictionaryEnumerator dict = m_CommandLine.GetEnumerator();
                while (dict.MoveNext())
                {
                    string name = dict.Key.ToString().Trim();
                    if (name.Length > 0)
                    {
                        pre.RegisterVariable(name, dict.Value.ToString());
                    }
                }

                string xml = pre.Process(reader);                //remove script and evaulate pre-proccessing to get schema-conforming XML


                XmlDocument doc = new XmlDocument();
                try
                {
                    XmlValidatingReader validator = new XmlValidatingReader(new XmlTextReader(new StringReader(xml)));

                    //validate while reading from string into XmlDocument DOM structure in memory
                    foreach (XmlSchema schema in m_Schemas)
                    {
                        validator.Schemas.Add(schema);
                    }
                    doc.Load(validator);
                }
                catch (XmlException e)
                {
                    throw new XmlException(e.ToString());
                }

                //is there a purpose to writing it?  An syntax/schema problem would have been found during pre.Process() and reported with details
                if (m_CommandLine.WasPassed("ppo"))
                {
                    string ppoFile = m_CommandLine["ppo"];
                    if (ppoFile == null || ppoFile.Trim().Length < 1)
                    {
                        ppoFile = "preprocessed.xml";
                    }

                    StreamWriter writer = null;
                    try
                    {
                        writer = new StreamWriter(ppoFile);
                        writer.Write(xml);
                    }
                    catch (IOException ex)
                    {
                        Console.WriteLine("Could not write PPO file '{0}': {1}", ppoFile, ex.Message);
                    }
                    finally
                    {
                        if (writer != null)
                        {
                            writer.Close();
                        }
                    }
                    return;
                }
                //start reading the xml config file
                XmlElement rootNode = doc.DocumentElement;
                //string suggestedVersion = Helper.AttributeValue(rootNode,"version","1.0");
                Helper.CheckForOSVariables = Helper.ParseBoolean(rootNode, "checkOsVars", false);

                foreach (XmlNode node in rootNode.ChildNodes)               //solutions or if pre-proc instructions
                {
                    IDataNode dataNode = ParseNode(node, null);
                    if (dataNode is ProcessNode)
                    {
                        ProcessNode proc = (ProcessNode)dataNode;
                        if (proc.IsValid)
                        {
                            ProcessFile(proc.Path);
                        }
                    }
                    else if (dataNode is SolutionNode)
                    {
                        m_Solutions.Add(dataNode);
                    }
                }
            }
            catch (XmlSchemaException xse)
            {
                m_Log.Write("XML validation error at line {0} in {1}:\n\n{2}",
                            xse.LineNumber, path, xse.Message);
            }
            finally
            {
                m_CurrentWorkingDirectory.Pop();
            }
        }