Esempio n. 1
0
        // ----------------------------------------------------------------------------------------
        /// <!-- NiceName -->
        /// <summary>
        ///      Returns a usable storage file name
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        /// <remarks>beta code - used once in production</remarks>
        public static string NiceName(string path)
        {
            int sectionLength = 8;


            // --------------------------------------------------------------------------
            //  Name components
            // --------------------------------------------------------------------------
            string suffix = FilesIO.FileSuffix(path);
            string body   = FilesIO.ThinFileBody(path);
            Random r      = RandomSource.New().Random;
            string num    = r.Next(10000).ToString().PadLeft(4, '0');


            // --------------------------------------------------------------------------
            //  Construct name
            // --------------------------------------------------------------------------
            string nice = "";

            if (body.Length > sectionLength * 2)
            {
                string body1 = Regex.Replace(body, "^(.{" + sectionLength + "}).*$", "$1");
                string body2 = Regex.Replace(body, "^.*(.{" + sectionLength + "})$", "$1");

                nice = body1 + body2 + num + suffix;
            }
            else
            {
                nice = body + num + suffix;
            }


            return(nice);
        }
Esempio n. 2
0
        // ----------------------------------------------------------------------------------------
        /// <!-- GetFileList -->
        /// <summary>
        ///      Gets a list of files of a particular pattern under a particular directory, recursively
        /// </summary>
        /// <param name="mainDirPath"></param>
        /// <param name="fileNamePattern">for example "\.vb$"</param>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <remarks>beta code - used once in production</remarks>
        public static List <string> GetFileList(string mainDirPath, string fileNamePattern)
        {
            List <string> file = new List <string>();

            // --------------------------------------------------------------------------
            //  Read list of directories, recursively, then check each one for the files
            // --------------------------------------------------------------------------
            if (!string.IsNullOrEmpty(mainDirPath))
            {
                DirectoryInfo mainDir = new DirectoryInfo(mainDirPath);
                List <string> dir     = FilesIO.LoadSubDirectoryList(mainDir);
                file = GetFileList(dir, fileNamePattern);
            }

            return(file);
        }