/// <summary> /// Adds the given filter to the pipe. /// </summary> private void AddFilter(Filter TheFilter) { Filters.Add(TheFilter); }
/// <summary> /// Compiles the pipe given its command line. Normally, InitialCharPos is set to 0 unless /// the CALL filter is compiling a pipe in which case the CALL filter's original command /// line is passed in and InitialCharPos is passed a value > 0 so that command line parsing /// can begin where the CALL filter's command line parsing left off. /// </summary> public void Compile(string PipeArgs, int InitialCharPos, string ParentSource, int ParentLineNo) { int CmdLinePtr; string MethodName = "Pipe.Compile"; int LineNo = 0; string TempStr; LogWrite(MethodName + ": begin"); if (this.Folder != string.Empty) { // Set the currently logged folder to this pipe's folder: Directory.SetCurrentDirectory(this.Folder); } CmdLine.Text = PipeArgs; try { // Parse the pipe's arguments (note: a pipe's string // arguments should never be interpreted, hence the // xlatStrings parameter is passed as false): CmdLine.Parse(InitialCharPos, false); // Process each script line: string[] ScriptLines = Script.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.None); foreach (string ScriptLn in ScriptLines) { LineNo++; LogWrite(MethodName + ": Raw Script Line = \"" + ScriptLn + "\""); TempStr = ScriptLn.Trim(); if ((TempStr != String.Empty) && (TempStr[0] != CommentChar)) { // The line isn't blank or a comment. string ScriptLine = ScriptLn; if (Template != string.Empty) { // Replace all placeholders in the line // with their respective pipe arguments: try { ScriptLine = ReplacePlaceholders(ScriptLine); } catch (PipeWrenchCompileException ex) { ex.Data.Add("Source", this.Name); ex.Data.Add("LineNo", LineNo); Errors.Add(ex); } } // Get the filter's name: string FilterName = ParseFilterName(ScriptLine, out CmdLinePtr); // Determine if the filter is registered: int i = Eng.CmdSpecs.IndexOf(FilterName); if (i > -1) { // The filter is registered. string TypeName = Eng.CmdSpecs[i].TypeName; LogWrite(MethodName + ": Filter TypeName: \"" + TypeName + "\""); string AssyPath = Eng.CmdSpecs[i].AssyPath; LogWrite(MethodName + ": Filter AssyPath: \"" + AssyPath + "\""); Filter TheFilter = new Filter(FilterName, TypeName, AssyPath, this, LineNo); try { // "Compile" the filter: TheFilter.Compile(ScriptLine, CmdLinePtr); } catch (PipeWrenchCompileException ex) { ex.Data.Add("Source", this.Name); ex.Data.Add("LineNo", LineNo); Errors.Add(ex); } // Add the filter container to the pipe: AddFilter(TheFilter); } else { // The filter is not registered. PipeWrenchCompileException ex = new PipeWrenchCompileException("Filter " + FilterName + " is unknown."); ex.Data.Add("CmdLine", ScriptLine); ex.Data.Add("CharPos", CmdLinePtr); ex.Data.Add("LineNo", LineNo); ex.Data.Add("Source", this.Name); Errors.Add(ex); } } } } catch (PipeWrenchCompileException ex) { ex.Data.Add("Source", ParentSource); ex.Data.Add("LineNo", ParentLineNo); Errors.Add(ex); } LogWrite(MethodName + ": end"); }