/// <summary> /// Method to run the CMCD algorithm /// </summary> /// <param name="filepath">The directory to operate in</param> /// <param name="comparer">The code comparer</param> public static List <DuplicateResult> Run(string filepath, ICodeComparer comparer) { var comparisonResults = new List <DuplicateResult>(); try { var allMethods = new List <Method>(); var attr = File.GetAttributes(filepath); var files = attr.HasFlag(FileAttributes.Directory) ? Directory.GetFiles(filepath, "*.cs", SearchOption.AllDirectories).ToList() : new List <string>() { filepath }; foreach (var file in files) { var methods = GetMethods(file).Select(c => new Method() { FilePath = Path.GetFullPath(file), FileName = Path.GetFileName(file), MethodNode = c }); allMethods.AddRange(methods); } for (int i = 0; i < allMethods.Count; i++) { for (int j = i + 1; j < allMethods.Count; j++) { try { var methodA = allMethods[i]; var methodB = allMethods[j]; var compareResult = comparer.Compare(methodA, methodB); comparisonResults.Add(new DuplicateResult() { MethodA = new MethodInfo(methodA), MethodB = new MethodInfo(methodB), Score = compareResult }); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(comparisonResults); }