public Object[] ParameterParser(string CommandLineString) { try { EncodingManager Encode = new EncodingManager(); string ParameterString = ExtensionManager.Window(CommandLineString, ExtensionManager.Position(CommandLineString, "(", 1) + 1, ExtensionManager.Position(CommandLineString, ")", ExtensionManager.PatternCount(CommandLineString, ")"))).Trim(); ParameterString.Replace("\\" + Convert.ToChar(34), Encode.DoubleQuote); //Encode Double Quotes if (ParameterString.Contains(Convert.ToChar(34).ToString())) { if (ExtensionManager.PatternCount(ParameterString, (Convert.ToChar(34)).ToString()) / 2 == (ExtensionManager.PatternCount(ParameterString, (Convert.ToChar(34)).ToString()) / 2)) { ParameterString = Encode.StringEncoder(ParameterString, false); } else { throw new ErrorManager.NewException("ERROR: The Command: '" + _CommandName + "' has an invalid number of double-quotations within a parammeter on line: '" + LineNumber.ToString() + "'. Be sure to use the double-quote escape '/\"' when placing double quotes within a string."); } } //Encode Semi-Colon Within Inner Bracketed Commands if (ExtensionManager.PatternCount(ParameterString, ";") > 0) { //Detect Bracketed Inner Commands if (ParameterString.Contains("(") | ParameterString.Contains(")")) { //Validate Proper Inner Bracket Syntax if (ExtensionManager.PatternCount(ParameterString, "(") == ExtensionManager.PatternCount(ParameterString, ")")) { ParameterString = ";" + ParameterString + ";"; //Add a Leading and Trailing Semi-Colon For Encoding Process int SemiColonCount = ExtensionManager.PatternCount(ParameterString, ";"); bool Flag = false; int ParseInstance = 1; int InstanceStep = 1; Flag = false; //Scenario ;....;... Until Found Bracket Balance while (Flag == false) { if (!(ExtensionManager.PatternCount(ExtensionManager.Window(ParameterString, ExtensionManager.Position(ParameterString, ";", ParseInstance), ExtensionManager.Position(ParameterString, ";", ParseInstance + InstanceStep)), "(") == ExtensionManager.PatternCount(ExtensionManager.Window(ParameterString, ExtensionManager.Position(ParameterString, ";", ParseInstance), ExtensionManager.Position(ParameterString, ";", ParseInstance + InstanceStep)), ")"))) { InstanceStep = InstanceStep + 1; //If Open to Close Bracket Count Mis-Matches Increase the Step Instance of the Semi-Colons } else { int i = 0; //If Open to Close Bracket Count Matches then Encode and Increase the Instance of the Semi-Colon i = ParameterString.Length; ParameterString = ExtensionManager.WindowReplace( ParameterString, ExtensionManager.Position( ParameterString, ";", ParseInstance) + 1, ExtensionManager.Position( ParameterString, ";", ParseInstance + InstanceStep), ";", Encode.InnerSemiColon); //i = ParameterString.Length //ParameterString = ";" & ParameterString & ";" if (InstanceStep > 1) { ParseInstance = ParseInstance + InstanceStep; InstanceStep = 1; } else { ParseInstance = ParseInstance + 1; } } if (ParseInstance == SemiColonCount) Flag = true; //If ParseInstance = ParameterString.PatternCount(";") Then Flag = True } ParameterString = ExtensionManager.Left(ParameterString, ParameterString.Length - 1); //Remove Leading and Trailing Semi-Colon ParameterString = ExtensionManager.Right(ParameterString, ParameterString.Length - 1); ParameterString = ParameterString.Replace(Encode.InnerSemiColon, Encode.SemiColon); } else { //Error Invalid Encode of "(" or ")" Character Found! throw new ErrorManager.NewException("ERROR: The Command: '" + CommandName + "' has an invalid number of brackets '()' within a parammeter on line: '" + LineNumber.ToString() + "'."); } } } string[] ParamArr = ParameterString.Split(';'); for (int i = 0; i <= ParamArr.Length - 1; i++) { ParamArr[i] = ParamArr[i].Replace(Encode.SemiColon, ";"); ParamArr[i] = Encode.StringDecoder(ParamArr[i]); } return ParamArr; } catch (Exception ex) { throw; } }
public string ParameterEvaluation(string ParameterString) { // Output! StringBuilder SbCommandProcessingResult = new StringBuilder(); StringBuilder SbConcatenationResult = new StringBuilder(); StringBuilder dynamic = new StringBuilder(); StringBuilder SbCommand = new StringBuilder(); EncodingManager Encode = new EncodingManager(); //string TestResultStr = null; //string TestCommandStr = null; try { int Cycle = 0; bool Processing = false; ParameterString = Encode.StringEncoder(ParameterString, true); string[] ParameterArray = ParameterString.Split('|'); ParameterArray = ExtensionManager.ArrayTrim(ParameterArray, true); if (!string.IsNullOrEmpty(ParameterString.Trim())) { for (int i = 1; i <= ParameterArray.Length; i++) { if (CommandIsValid(ParameterArray[i - 1]) == true) { SbCommand.Append(ParameterArray[i - 1]); Cycle++; if (ParameterArray.Length > 1) { if (ParameterArray[i] == "(") { Processing = true; //'Keep Adding Values from the Array until the command is balanced in terms of braces. while (Processing) { if (!(ExtensionManager.Right(SbCommand.ToString(), 1) == "$")) SbCommand.Append(" "); SbCommand.Append(ParameterArray[(i - 1) + Cycle].ToString()); if (!(ParameterArray[(i - 1) + Cycle].ToString() == "$")) SbCommand.Append(" "); Cycle++; //TestCommandStr = SbCommand.ToString(); if (ExtensionManager.PatternCount(SbCommand.ToString(), "(") == ExtensionManager.PatternCount(SbCommand.ToString(), ")")) { ClixScriptManager CSM = (ClixScriptManager)this.Clone(); SbCommandProcessingResult.Append(" "); SbCommandProcessingResult.Append(CSM.ExecuteCommandLine(SbCommand.ToString(), true).ToString()); SbCommandProcessingResult.Append(" "); //TestResultStr = SbResult.ToString(); i = i + Cycle;// !!!!!!! Validate used to be i = Cycle Cycle = 0; Processing = false; } } } else { //Create New Instance of ClixScript Engine And Process ClixScriptManager CSM = (ClixScriptManager)this.Clone(); SbCommandProcessingResult.Append(" "); SbCommandProcessingResult.Append(CSM.ExecuteCommandLine(ParameterArray[i], true).ToString()); SbCommandProcessingResult.Append(" "); //TestResultStr = SbResult.ToString(); Processing = false; } } else { //Create New Instance of ClixScript Engine And Process ClixScriptManager CSM = (ClixScriptManager)this.Clone(); SbCommandProcessingResult.Append(" "); SbCommandProcessingResult.Append(CSM.ExecuteCommandLine(ParameterArray[i - 1], true).ToString()); SbCommandProcessingResult.Append(" "); //TestResultStr = SbResult.ToString(); Processing = false; } } else { if (!(ExtensionManager.Right(SbCommandProcessingResult.ToString(), 1) == "$")) { SbCommandProcessingResult.Append(" "); } SbCommandProcessingResult.Append(ParameterArray[(i - 1)].ToString()); if (!(ParameterArray[(i - 1) + Cycle].ToString() == "$")) { SbCommandProcessingResult.Append(" "); } //TestResultStr = SbResult.ToString(); if (ParameterArray.Length == 1) { break; } } } } // Begin String Concatenation Processing - '&' ParameterString = Encode.StringEncoder(SbCommandProcessingResult.ToString(), true); ParameterArray = ParameterString.Split('|'); bool buffers_full = false; bool is_first_concatenated_value = true; bool is_active_concatenation = false; StringBuilder concatenation_buffer = new StringBuilder(); ; StringBuilder output_buffer = new StringBuilder(); ; //int process_phase = 1; ConcatenationPhase current_phase = new ConcatenationPhase(); current_phase = ConcatenationPhase.Search; for (int i = 0; i <= ParameterArray.Length - 1; i++) { if (i == ParameterArray.Length - 1) { if (ParameterArray[i] != "&" && ParameterArray[i].Trim() != "") { if (current_phase == ConcatenationPhase.Search) { ParameterArray[i] = ParameterArray[i].Trim(); // Pass the Current Value to Output stream ParameterArray[i] = " " + ParameterArray[i]; SbConcatenationResult.Append(ParameterArray[i]); } else if (current_phase == ConcatenationPhase.Concatenate) { ParameterArray[i] = ParameterArray[i].Trim(); ParameterArray[i] = ParameterArray[i] + "\""; SbConcatenationResult.Append(ParameterArray[i]); } } if (current_phase == ConcatenationPhase.Buffer) { if (is_active_concatenation) { // Dump the Concatenation Buffer to the Output Stream //concatenation_buffer = concatenation_buffer.Trim(); //concatenation_buffer = concatenation_buffer + "\""; concatenation_buffer.Append("\""); SbConcatenationResult.Append(concatenation_buffer.ToString()); } else { // Dump the Output Buffer to the Output Stream //output_buffer = output_buffer.Trim(); //output_buffer = " " + output_buffer; output_buffer.Insert(0, " "); SbConcatenationResult.Append(output_buffer.ToString()); } if (ParameterArray[i] != "&" && ParameterArray[i].Trim() != "") { ParameterArray[i] = ParameterArray[i].Trim(); // Pass the Current Value to Output stream ParameterArray[i] = " " + ParameterArray[i]; SbConcatenationResult.Append(ParameterArray[i]); } } } else { if (ParameterArray[i] == "&") { // Concatenation Phase // Push the Concatenation Buffer into the output stream SbConcatenationResult.Append(concatenation_buffer); // Clear Buffers //output_buffer = ""; //concatenation_buffer = ""; output_buffer.Clear(); concatenation_buffer.Clear(); buffers_full = false; // Set Current Phase current_phase = ConcatenationPhase.Concatenate; // Flag Active Concatenation Cycle is_active_concatenation = true; } else { if (ParameterArray[i].Trim() == "") { // Store Value into Output Buffer Even if value is Whitespace //output_buffer += ParameterArray[i]; output_buffer.Append(ParameterArray[i]); } else { if (buffers_full) { // Search Phase // This Concatination Cycle has ended, dump the buffers and start a new concatenation cycle if (is_first_concatenated_value) { // No Active Concatination is occurring SbConcatenationResult.Append(output_buffer); } else { // Complete current Active Concatenation //concatenation_buffer += "\""; concatenation_buffer.Append("\""); SbConcatenationResult.Append(concatenation_buffer.ToString()); is_first_concatenated_value = true; } // Clear Buffers //output_buffer = ""; //concatenation_buffer = ""; output_buffer.Clear(); concatenation_buffer.Clear(); buffers_full = false; // Set Current Phase current_phase = ConcatenationPhase.Search; // Un-Flag Active Concatenation Cycle is_active_concatenation = false; } else { // Buffer Phase // Store Value into Concatenatenation Buffer if (is_first_concatenated_value) { ParameterArray[i] = ParameterArray[i].Trim(); if (ParameterArray[i].Length >= 2 && ParameterArray[i].Left(1) == "\"" && ParameterArray[i].Right(1) == "\"") { // ""string"" -> ""string" also """" -> """ //concatenation_buffer = ParameterArray[i].Left(ParameterArray[i].Length - 1); concatenation_buffer.Clear(); concatenation_buffer.Append(ParameterArray[i].Left(ParameterArray[i].Length - 1)); } else { // "xy" -> ""xy" or "x" -> ""x" //concatenation_buffer = "\"" + ParameterArray[i]; concatenation_buffer.Clear(); concatenation_buffer.Append("\"" + ParameterArray[i]); } // Set first concatenation processing flag to false (controls how the items in the buffers are encapsulated) is_first_concatenated_value = false; } else { ParameterArray[i] = ParameterArray[i].Trim(); if (ParameterArray[i].Length >= 2 && ParameterArray[i].Left(1) == "\"" && ParameterArray[i].Right(1) == "\"") { // ""string"" -> "string" also """" -> "" //concatenation_buffer = ParameterArray[i].Window(1, ParameterArray[i].Length - 1); concatenation_buffer.Append(ParameterArray[i].Window(1, ParameterArray[i].Length - 1)); } else { // "xy" -> "xy" or "x" -> "x" //concatenation_buffer = ParameterArray[i]; concatenation_buffer.Clear(); concatenation_buffer.Append(ParameterArray[i]); } } // Store Value into Output Buffer //output_buffer += ParameterArray[i]; output_buffer.Append(ParameterArray[i]); buffers_full = true; // Set Current Phase current_phase = ConcatenationPhase.Buffer; } } } } string str = SbConcatenationResult.ToString(); } } catch (Exception ex) { throw; } String TestResultStr = SbConcatenationResult.ToString(); return Encode.StringDecoder(SbConcatenationResult.ToString()); }