public void FindTableOperations(string operation, string file) { //if we see the insert statement, we can drop everything after and finf the last function in the file string currentFile = file; while (currentFile.Contains(operation)) { string functionFullText = ""; CutFileOnCurrentFunctionAndRest(ref currentFile, operation, ref functionFullText); //Get function name //when the rest of the file does not have the function anymore ? but how could that be... string FunctionName = ""; if (!functionFullText.ToLower().Contains("function:")) { FunctionName = FileName; } else { FunctionName = GetFunctionName(functionFullText); } //Get all sql operation calls in current function List <string> tableNames = GetTableNames(functionFullText, operation); LogDuplicates(tableNames, FunctionName, operation, FileName); foreach (var table in tableNames) { var record = RequestRecords.Where(r => r.FunctionName == FunctionName & r.TableName == table).FirstOrDefault(); if (record != null) { if (!record.Operation.Contains(operation)) { record.Operation.Add(operation); if (operation != ParsingConstants.SelectString) { record.OperationLevel = 2; } } record.Count++; } else { RequestRecord recordreq = new RequestRecord { FunctionName = FunctionName.ToLower(), Operation = new List <string> { operation }, TableName = table.ToLower(), Count = 1, OperationLevel = operation == ParsingConstants.SelectString ? 1 :2 }; RequestRecords.Add(recordreq); FunctionsNamesList.Add(FunctionName.ToLower()); } } } }
public void FindFunctionCalls(string fileName, string file) { string currentFile = file; while (currentFile.Contains("Call")) { int indexOfCall = currentFile.IndexOf("Call"); var indexOfFunctionEnd = currentFile.IndexOf("(", indexOfCall); var FunctionCallString = currentFile.Substring(indexOfCall, indexOfFunctionEnd - indexOfCall); var FunctionCallStringAr = FunctionCallString.Split(" "); if (FunctionCallStringAr.Count() > 1) { string FunctionCalled = FunctionCallStringAr[1]; if (FunctionsNamesList.Contains(FunctionCalled.ToLower())) { string functionFullText = ""; CutFileOnCurrentFunctionAndRest(ref currentFile, FunctionCallString, ref functionFullText); //Get function name //when the rest of the file does not have the function anymore ? but how could that be... string FunctionName = ""; if (!functionFullText.ToLower().Contains("function:")) { FunctionName = FileName.ToLower(); } else { FunctionName = GetFunctionName(functionFullText); } var record = RequestRecords.Where(r => r.FunctionName == FunctionCalled & r.CalledByFunction == FunctionName) .FirstOrDefault(); if (record == null) { RequestRecord recordreq = new RequestRecord { FunctionName = FunctionCalled, Operation = new List <string> { "FunctionCall" }, CalledByFunction = FunctionName, Count = 1, OperationLevel = 1 }; RequestRecords.Add(recordreq); } } else { currentFile = currentFile.Substring(indexOfFunctionEnd); } } else { currentFile = currentFile.Substring(indexOfFunctionEnd); } } }