public static void AnalyzeIfFunctions(List <AnalysisForm.ScriptStepRec> allScriptSteps, RichTextBox rTxtBox, List <ScriptNoteLblFound> labelsFound) { rTxtBox.Text += string.Format( "================================================================================================{0}" + "={0}" + "= Beginning Analysis of IFs/Gotos - Verifying that the script label in every IF/Goto function's \"script note\" parameter exists{0}" + "={0} \t\t See notes 1 & 2 - Click the \"View Suggested Practices\" button for more info {0}" + //"= i.e.) line 3 IF @Ticket#@ Exists goto :TicketExists{0}"+ //"= line 9 :TicketExist <----- Typos happen!{0}"+ //"= Since this label doesn't exist, the script will exit immediately on line 3{0}"+ //"={0}"+ "================================================================================================", Environment.NewLine); if (allScriptSteps == null) { rTxtBox.Text += "No problems detected!" + Environment.NewLine; return; } // FOR EACH IF FUNCTION ... foreach (var item in AnalysisForm._GotoFunctionList.ToList()) { var funcId = item.FunctionId; var paramName = item.ParamIdForLabel; var funcName = item.FunctionName; var currentItems = new List <AnalysisForm.ScriptStepRec>(); switch (paramName) { case "Param1": { currentItems = allScriptSteps.Where(o => o != null) .Where(o => o.osLimit != "-2147483648") .Where(x => Int32.Parse(x.functionId) == funcId && Converter(x.action) != 1) .Select(z => new AnalysisForm.ScriptStepRec { param1 = z.param1, sort = z.sort, functionId = z.functionId }).ToList(); break; } case "Param2": { currentItems = allScriptSteps.Where(o => o != null) .Where(o => o.osLimit != "-2147483648") .Where(x => Int32.Parse(x.functionId) == funcId && Converter(x.action) != 1) .Select(z => new AnalysisForm.ScriptStepRec { param1 = z.param2, sort = z.sort, functionId = z.functionId }).ToList(); break; } case "Param3": { currentItems = allScriptSteps.Where(o => o != null) .Where(o => o.osLimit != "-2147483648") .Where(x => Int32.Parse(x.functionId) == funcId && Converter(x.action) != 1) .Select(z => new AnalysisForm.ScriptStepRec { param1 = z.param3, sort = z.sort, functionId = z.functionId }).ToList(); break; } case "Param4": { currentItems = allScriptSteps.Where(o => o != null) .Where(o => o.osLimit != "-2147483648") .Where(x => Int32.Parse(x.functionId) == funcId && Converter(x.action) != 1) .Select(z => new AnalysisForm.ScriptStepRec { param1 = z.param4, sort = z.sort, functionId = z.functionId }).ToList(); break; } } // don't iterate unless we identified steps of this function var relativeStepsFound = currentItems.Any(); if (relativeStepsFound == false) { continue; } rTxtBox.Text += String.Format( "{0}----------------------------------------------------------------------------------------------------------------------------------------------------{0}" + "Analyzing detected \"{1}\" script steps ....\t Number of steps found: {2}" + "{0}----------------------------------------------------------------------------------------------------------------------------------------------------{0}{0}", Environment.NewLine, funcName, currentItems.Count); currentItems.Sort((a, x) => int.Parse(a.sort).CompareTo(int.Parse(x.sort))); foreach (var specifiedJump in currentItems) { if (specifiedJump == null) { continue; } // prep work for line number int lineNumber = 9999; bool isLineNumInt = false; Int32.TryParse(specifiedJump.sort, out lineNumber); // Best-practice - should NOT be skipping lines by # int linesToSkip = -9999; bool isGotoSkip = false; specifiedJump.param1 = specifiedJump.param1.TrimStart('!'); isGotoSkip = int.TryParse(specifiedJump.param1, out linesToSkip); if (isLineNumInt = true) { lineNumber = lineNumber + 1; } // just using param1 in this object for simplicity. May be 4, 3 2 or 1... var logmsg = String.Format("[Line {1}] \tJump Label Specified: {0}", specifiedJump.param1, lineNumber).PadRight(70, '.'); rTxtBox.Text += logmsg; // identify matched labels var matchedObjects = labelsFound.Where( o => o.ItemFlag.Equals(AnalysisForm.ScriptNoteFlags.GotoLabel) && string.Equals(o.ItemName, specifiedJump.param1.Replace("!:", ":"), StringComparison.OrdinalIgnoreCase)) .ToList(); var foundMatchingLabel = matchedObjects.Any(); if (foundMatchingLabel) { rTxtBox.Text += String.Format("\t[SUCCESS] Found label: {0}{1}", matchedObjects[0].ItemName, Environment.NewLine); // Ok, now that we've joined two labels together, we need to add this label name // to the list of accounted for labels. var labelUsed = new ScriptNoteLblFound(lineNumber, specifiedJump.param1, AnalysisForm.ScriptNoteFlags.FoundRecord); labelsUsedByIFs.Add(labelUsed); } else if (String.IsNullOrEmpty(specifiedJump.param1) || specifiedJump.param1 == "0") { if (specifiedJump.functionId == "129") { // It's a GOTO ... this is ok rTxtBox.Text += String.Format("\t[NOTE] - Exit Specified (Exits immediately){0}", Environment.NewLine); } else { rTxtBox.Text += String.Format("\t[FAIL] - Exit Specified. See note 4 on suggestions tab.{0}", Environment.NewLine, specifiedJump.functionId); } } else if (isGotoSkip == true && linesToSkip != 0) { rTxtBox.Text += String.Format("\t[FAIL] - Skip {1} lines detected (bad practice)! {0}", Environment.NewLine, linesToSkip.ToString()); } else { rTxtBox.Text += String.Format("\t[FAIL] Did not find matching label: {0}{1}", specifiedJump.param1, Environment.NewLine); AnalysisForm.AddOneMissingLabel(); } } } rTxtBox.Text += Environment.NewLine; }
public static List <ScriptNoteLblFound> AnalyzeScriptNotes(List <AnalysisForm.ScriptStepRec> scriptnoteRecs, RichTextBox rTxtBox) { var parsedLabelsFound = new List <ScriptNoteLblFound>(); foreach (var entry in scriptnoteRecs) { // Does it start with :, indicating it's a script note //var es = scriptdata.Where(e => int.Parse(e.functionId) == 139).ToString(); byte flag = 0; var stepsToSkip = 0; Enum resultEnum = null; // prep work int lineNumber = 0; bool isInt = false; Int32.TryParse(entry.sort, out lineNumber); if (isInt = false) { lineNumber = 9999; } else { lineNumber = lineNumber + 1; } var currentP1 = entry.param1; var currentP2 = entry.param2; var currentP3 = entry.param3; var currentP4 = entry.param4; var currentP5 = entry.param5; var currentFid = Int32.Parse(entry.functionId); var isNumber = Int32.TryParse(entry.param1, out stepsToSkip); ////////////////////////////////////// // logic for script notes // ////////////////////////////////////// if (currentP1.Length > 2 && !currentP1.StartsWith(":") || currentP1.Equals("")) { resultEnum = AnalysisForm.ScriptNoteFlags.NotesOnly; //rTxtBoxResults.Text += String.Format("[Line: {0}]\t[NOTES ONLY] - Value:\t{1} \n", entry.sort.ToString(), currentP1); LogResults(lineNumber.ToString(), currentP1, resultEnum, rTxtBox); } else if (currentP1.StartsWith(":")) { resultEnum = AnalysisForm.ScriptNoteFlags.GotoLabel; //rTxtBoxResults.Text += String.Format("[Line: {0}]\t[VALID LABEL] - Value:\t{1} \n", entry.sort.ToString(), currentP1); LogResults(lineNumber.ToString(), currentP1, resultEnum, rTxtBox); } var currentItem = new ScriptNoteLblFound(lineNumber, entry.param1, resultEnum); parsedLabelsFound.Add(currentItem); } return(parsedLabelsFound); }