Esempio n. 1
0
        public string GetText(Project project)
        {
            if (project == null)
            {
                return(string.Empty);
            }

            var text = new StringBuilder();

            void Push(string line)
            {
                text.Append(line);
                text.Append(Environment.NewLine);
            }

            //
            if (project.Title != "")
            {
                Push(project.Title);
            }
            if (project.Path != "")
            {
                Push($"Path: {project.Path}");
            }
            if (project.LastEdit != 0)
            {
                Push($"Last edit: {UnixTime.ToDateTime(project.LastEdit)}");
            }

            Push("");
            if (project.Folders?.Count > 0)
            {
                Push($"Folders: ");

                int i = 0;
                foreach (string folder in project.Folders)
                {
                    Push($"{++i}. {folder}");
                }

                Push("");
            }

            var info = project.Info;

            Push($"SLOC/lines: {info.Volume} ({info.Volume.Ratio * 100}%)");
            Push("");

            if (info.ExtensionsVolume?.Count > 0)
            {
                Push($"Extensions ({info.ExtensionsVolume.Count}): ");

                int i      = 0;
                var sorted = info.ExtensionsVolume.OrderBy(v => - v.Value.Lines);
                foreach (var pair in sorted)
                {
                    var vol = pair.Value;
                    Push($"{++i}. {pair.Key} ".PadRight(40, '.') + $" {vol} ({vol.Ratio * 100}%) [{vol.Files} files]");
                }

                Push("");
            }

            if (info.FilesVolume?.Count > 0)
            {
                FileTreeNode tree = new FileTreeNode("root");

                Push($"Files ({info.FilesVolume.Count}): ");
                foreach (var pair in info.FilesVolume)
                {
                    tree.Add(pair.Key, pair.Value);
                }
                Push(tree.ToString());
                Push("");
            }

            if (info.Errors?.Count > 0)
            {
                Push($"Errors ({info.Errors.Count}): ");
                int i = 0;
                foreach (var error in info.Errors)
                {
                    Push($"{++i}. {error}");
                }
                Push("");
            }

            Push("".PadRight(50, '_'));
            Push("");
            //
            return(text.ToString());
        }