Prebuild.Core.Kernel.ProcessFile C# (CSharp) Method

ProcessFile() public method

public ProcessFile ( string file, IList solutions ) : void
file string
solutions IList
return void
		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();
			}
		}

Same methods

Kernel::ProcessFile ( ProcessNode node, SolutionNode parent ) : void
Kernel::ProcessFile ( string file ) : void