/// <summary>
 /// Gets the file description.
 /// </summary>
 /// <param name="descriptionLine">The description line.</param>
 /// <returns></returns>
 public static folderNodeFileDescriptor GetFileDescription(String descriptionLine)
 {
     if (FileDescriptionExtractionRegex.IsMatch(descriptionLine))
     {
         folderNodeFileDescriptor output = new folderNodeFileDescriptor();
         var mch = FileDescriptionExtractionRegex.Match(descriptionLine);
         if (mch.Groups.Count > 0)
         {
             output.filename = mch.Groups[1].Value;
         }
         if (mch.Groups.Count > 1)
         {
             output.description = mch.Groups[2].Value;
         }
         return(output);
     }
     return(null);
 }
Esempio n. 2
0
        //public void AttachSubdirs(ILogBuilder logger)
        //{
        //    Directory.GetDirectories(
        //}

        /// <summary>
        /// Searches for readme file (<see cref="directory_readme_filename"/>) in this folder and extracts: <see cref="caption"/>, <see cref="description"/> and list of files
        /// </summary>
        /// <param name="logger">The logger.</param>
        public void ScanReadMe(ILogBuilder logger = null)
        {
            var p = path + Path.DirectorySeparatorChar + directory_readme_filename;

            if (!File.Exists(p))
            {
                if (logger != null)
                {
                    logger.log("Readme file not found at [" + p + "]");
                }
                return;
            }

            var    lines = File.ReadAllLines(p);
            String line  = lines.FirstOrDefault(x => x.StartsWith("####"));

            if (line.isNullOrEmpty())
            {
                if (logger != null)
                {
                    logger.log("Readme file [" + p + "] format not recognized");
                }
                return;
            }

            caption = line.removeStartsWith("#### ");

            var descriptionLines = lines.Where(x => x.StartsWith(" > ")).ToList();

            if (descriptionLines.Count > 1)
            {
                description = descriptionLines[1];
                description = description.removeStartsWith(" > ");
            }

            Int32 lc = 0;

            for (int i = 10; i < lines.Length; i++)
            {
                String ln = lines[i];
                if (ln.isNullOrEmpty())
                {
                }
                else if (ln.Contains("-----------------------"))
                {
                    lc++;
                    if (lc > 1)
                    {
                        break;
                    }
                }
                else
                {
                    folderNodeFileDescriptor fInfo = folderNodeFileDescriptorTools.GetFileDescription(ln);
                    if (fInfo != null)
                    {
                        RegisterFile(fInfo.filename, fInfo.description);
                        //   AdditionalFileEntries.Add(fInfo.filename, this.GetFileDescription(fInfo.filename, fInfo.description));
                    }
                }
            }
        }
        public static folderNodeFileDescriptor GetFileDescription(this folderNode folder, String filename, String fileDescription)
        {
            if (fileDescription.isNullOrEmpty())
            {
                String fileClean = Path.GetFileNameWithoutExtension(filename);
                String fileTitle = fileClean.imbTitleCamelOperation(true);

                String ext = Path.GetExtension(filename).Trim('.').ToLower();

                switch (ext)
                {
                case "json":
                    fileDescription = "JSON Serialized Data Object";
                    break;

                case "xml":
                    fileDescription = "XML Serialized Data Object";
                    if (filename.ContainsAny(new String[] { "setup", "Setup", "config", "Config", "settings", "Settings" }))
                    {
                        fileTitle       = fileClean.imbTitleCamelOperation(true);
                        fileDescription = "Serialized configuration [" + fileTitle + "] object";
                    }

                    break;

                case "txt":
                    fileDescription = "Plain text file";
                    if (filename.StartsWith("ci_"))
                    {
                        fileClean       = fileClean.removeStartsWith("ci_");
                        fileTitle       = fileClean.imbTitleCamelOperation(true);
                        fileDescription = "Column / Fields meta information for data table [" + fileTitle + "] export";
                    }
                    if (fileClean == "note")
                    {
                        fileDescription = "Relevant notes on [" + folder.caption + "] in markdown/text format";
                    }
                    if (fileClean.Contains("error"))
                    {
                        fileDescription = "Error record(s)";
                    }
                    if (filename == "directory_readme.txt")
                    {
                        fileDescription = "Description of directory content (this file)";
                    }
                    break;

                case "csv":
                    fileDescription = "Comma Separated Value data dump";
                    if (filename.StartsWith("dc_"))
                    {
                        fileClean       = fileClean.removeStartsWith("dc_");
                        fileTitle       = fileClean.imbTitleCamelOperation(true);
                        fileDescription = "Clean data CSV version of data table [" + fileTitle + "] export";
                    }
                    break;

                case "xls":
                case "xlsx":
                    fileDescription = "Excel spreadsheet";
                    if (filename.StartsWith("dt_"))
                    {
                        fileClean       = fileClean.removeStartsWith("dt_");
                        fileTitle       = fileClean.imbTitleCamelOperation(true);
                        fileDescription = "Excel spreadsheet report on [" + fileTitle + "] data table";
                    }
                    break;

                case "md":
                    fileDescription = "Markdown document";
                    break;

                case "bin":
                    fileDescription = "Binary Serialized Data Object";
                    break;

                case "dgml":
                    fileDescription = "Serialized graph in Directed-Graph Markup Language format";
                    break;

                case "html":
                    fileDescription = "HTML Document";
                    break;

                case "log":
                    fileDescription = "Log output plain text file";
                    break;

                default:
                    fileDescription = ext.ToUpper() + " file";
                    break;
                }
            }
            fileDescription = String.Format(FileDescriptionFormat, filename, fileDescription);

            var desc = new folderNodeFileDescriptor();

            desc.filename    = filename;
            desc.description = fileDescription;
            return(desc);
        }