Ejemplo n.º 1
0
        /// <summary>
        /// Parses a file name into it's constituent parts.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        private FileNameInfo ParseFileName(string name)
        {
            var ext = System.IO.Path.GetExtension(name);

            var fileNameInfo = new FileNameInfo
            {
                FullName  = name,
                SortOrder = -1,
                Extension = ext,
                TypeName  = GetDefaultFileType(ext).Name
            };

            var nameParts = name.Split('.');

            if (nameParts.Length > 2)
            {
                fileNameInfo.TypeName = nameParts[1];
            }

            int parsedSortOrder;

            if (VisibleRegex.IsMatch(nameParts[0]))
            {
                var hyphenIndex       = nameParts[0].IndexOf('-');
                var possibleSortOrder = nameParts[0].Substring(0, hyphenIndex);

                if (int.TryParse(possibleSortOrder, out parsedSortOrder))
                {
                    fileNameInfo.Name      = nameParts[0].Substring(hyphenIndex + 1) + fileNameInfo.Extension;
                    fileNameInfo.SortOrder = parsedSortOrder;
                }
            }
            else
            {
                fileNameInfo.Name = nameParts[0] + fileNameInfo.Extension;
                if (int.TryParse(nameParts[0], out parsedSortOrder))
                {
                    fileNameInfo.SortOrder = parsedSortOrder;
                }
            }


            return(fileNameInfo);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses a file name into it's constituent parts.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        private FileNameInfo ParseFileName(string name)
        {
            var ext = System.IO.Path.GetExtension(name);

            var fileNameInfo = new FileNameInfo
            {
                FullName = name,
                SortOrder = -1,
                Extension = ext,
                TypeName = GetDefaultFileType(ext).Name
            };

            var nameParts = name.Split('.');
            if(nameParts.Length > 2)
            {
                fileNameInfo.TypeName = nameParts[1];
            }

            int parsedSortOrder;
            if (VisibleRegex.IsMatch(nameParts[0]))
            {
                var hyphenIndex = nameParts[0].IndexOf('-');
                var possibleSortOrder = nameParts[0].Substring(0, hyphenIndex);

                if (int.TryParse(possibleSortOrder, out parsedSortOrder))
                {
                    fileNameInfo.Name = nameParts[0].Substring(hyphenIndex + 1) + fileNameInfo.Extension;
                    fileNameInfo.SortOrder = parsedSortOrder;
                }
            }
            else
            {
                fileNameInfo.Name = nameParts[0] + fileNameInfo.Extension;
                if(int.TryParse(nameParts[0], out parsedSortOrder))
                {
                    fileNameInfo.SortOrder = parsedSortOrder;
                }
            }

            return fileNameInfo;
        }