public void Add(string[] path, CodeVolume volume) { if (path.Length > 0) { string key = path[0]; path = path.Where((val, i) => i != 0).ToArray(); if (!nodes.ContainsKey(key)) { nodes.Add(key, new FileTreeNode(key)); } nodes[key].Add(path, volume); } else { _Volume = volume; } }
private void Process(List <Project> projects, Dispatcher dispatcher) { void ProcessUpdate(InspectorStage stage, InspectState state) { dispatcher.Invoke(() => OnUpdate?.Invoke(stage, state)); } // var allFiles = new List <string>(); int i = 0, j = 0; foreach (var project in projects) { ProcessUpdate(InspectorStage.Progress, new InspectState { Used = ++i, All = projects.Count }); // var projectPath = project.Path.Replace('\\', '/'); var files = project.GetFiles(InspectorConfig.CodeExtensions, InspectorConfig.FilesBlackList, (files, dirs, cur) => { ProcessUpdate(InspectorStage.Progress2, new InspectState { Used = Math.Min(files, dirs), All = Math.Max(files, dirs) }); }); project.Info.Clear(); // var projectVolume = new CodeVolume(); if (files.Count == 0) { project.Info.Error("This project has no files to analyse"); } j = 0; foreach (var file in files) { if (j % 10 == 0) { ProcessUpdate(InspectorStage.Progress2, new InspectState { Used = j, All = files.Count }); } j++; // if (!allFiles.Contains(file.Path)) { allFiles.Add(file.Path); if (allFiles.Count % 10 == 0) { ProcessUpdate(InspectorStage.FetchingFiles, new InspectState { All = allFiles.Count }); } } else { project.Info.Error($"File '{file.Path}' already has added"); } } j = 0; foreach (var file in files) { if (!file.IsMatch) { continue; } // if (j % 10 == 0) { ProcessUpdate(InspectorStage.Progress2, new InspectState { Used = j, All = files.Count }); ProcessUpdate(InspectorStage.FetchingLines, new InspectState { All = projectVolume.Lines }); } j++; if (File.Exists(file.Path)) { // Geting data string data = ""; try { data = File.ReadAllText(file.Path); // long newLastEdit = UnixTime.ToTimestamp(File.GetLastWriteTime(file.Path)); project.LastEdit = Math.Max(project.LastEdit, newLastEdit); } catch (Exception ex) { project.Info.Error($"File '{file.Path}' thrown {ex.GetType().Name}"); } // Calculating lines string localPath = file.Path.StartsWith(projectPath) ? file.Path.Substring(projectPath.Length) : file.Path; string[] lines = data.Split("\n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); int linesCount = lines.Length; int sloc = 0; bool skip = false; foreach (string line in lines) { string s = line.Trim(); // if (s.StartsWith("/*")) { skip = true; } if (s.EndsWith("*/") && skip) { skip = false; } // if (!skip) { if (s.StartsWith("//") || s.StartsWith("#")) { continue; } if ("{}()[]".Contains(s)) { continue; } sloc++; } } // var volume = new CodeVolume(sloc, linesCount, 1); projectVolume += volume; // string ext = Path.GetExtension(file.Path); // Пушим список расширений project.Info.ExtensionsVolume.Push(ext, volume, (A, B) => A + B); // Пушим список файлов project.Info.FilesVolume.Push(localPath, volume); } else { project.Info.Error($"{file} doesn't exist"); } } project.Info.Volume = projectVolume; //project.Info.Files = filesCount; } // GC.Collect(); }
public FileTreeNode(string key) { Key = key; _Volume = new CodeVolume(); }
public void Add(string path, CodeVolume volume) { Add(path.Split(new char[] { '\\', '/' }, StringSplitOptions.RemoveEmptyEntries), volume); }
private void Process(List <Project> projects, Dispatcher dispatcher) { void ProcessUpdate(InspectorStage stage, InspectState state) { dispatcher.Invoke(() => OnUpdate?.Invoke(stage, state)); } // var allFiles = new List <string>(); int i = 0, j = 0; foreach (var project in projects) { ProcessUpdate(InspectorStage.Progress, new InspectState { Used = ++i, All = projects.Count }); // var projectPath = project.Path.Replace('\\', '/'); var files = project.GetFiles(InspectorConfig.CodeExtensions, InspectorConfig.FilesBlackList, (files, dirs, cur) => { ProcessUpdate(InspectorStage.Progress2, new InspectState { Used = Math.Min(files, dirs), All = Math.Max(files, dirs) }); }); project.Info.Clear(); // var projectVolume = new CodeVolume(); if (files.Count == 0) { project.Info.Error("This project has no files to analyse"); } j = 0; foreach (var file in files) { if (j % 10 == 0) { ProcessUpdate(InspectorStage.Progress2, new InspectState { Used = j, All = files.Count }); } j++; // if (!allFiles.Contains(file.Path)) { allFiles.Add(file.Path); if (allFiles.Count % 10 == 0) { ProcessUpdate(InspectorStage.FetchingFiles, new InspectState { All = allFiles.Count }); } } else { project.Info.Error($"File '{file.Path}' already has added"); } } j = 0; foreach (var file in files) { if (!file.IsMatch) { continue; } // if (j % 10 == 0) { ProcessUpdate(InspectorStage.Progress2, new InspectState { Used = j, All = files.Count }); ProcessUpdate(InspectorStage.FetchingLines, new InspectState { All = projectVolume.Lines }); } j++; if (File.Exists(file.Path)) { // Geting data var data = ""; try { data = File.ReadAllText(file.Path); // var newLastEdit = UnixTime.ToTimestamp(File.GetLastWriteTime(file.Path)); project.LastEdit = Math.Max(project.LastEdit, newLastEdit); } catch (Exception ex) { project.Info.Error($"File '{file.Path}' thrown {ex.GetType().Name}"); } // Calculating lines var localPath = file.Path.StartsWith(projectPath) ? file.Path[projectPath.Length..] : file.Path;