TVSorter.Model.FileResult.FormatOutputPath C# (CSharp) 메소드

FormatOutputPath() 공개 메소드

Formats the output path of the episode.
public FormatOutputPath ( string formatString ) : string
formatString string /// The format string to use. ///
리턴 string
        public string FormatOutputPath(string formatString)
        {
            if (this.Show == null || this.Episode == null || this.InputFile == null)
            {
                return string.Empty;
            }

            // Replace the extension and folder name. (Format codes with no parameters)
            formatString = formatString.Replace("{Ext}", this.InputFile.Extension);
            formatString = formatString.Replace("{FName}", this.Show.FolderName);

            // Identify the other format codes and their parameters.
            var regExp = new Regex(@"{([a-zA-Z]+)\(([^\)}]+)\)}");

            // Replace the matches with the appropriate strings.
            formatString = regExp.Replace(formatString, this.ProcessMatch);

            // Replace : with .
            formatString = formatString.Replace(':', '.');

            // Get the invalid characters for a file name, not including the DirectorySeparatorChar.
            IEnumerable<char> invalidChars =
                StringExtensions.InvalidFilenameChars.Where(x => !x.Equals(Path.DirectorySeparatorChar));

            // Remove any characters that can't be in a filename from the formatString.
            return invalidChars.Aggregate(
                formatString, (current, ch) => current.Replace(ch.ToString(CultureInfo.InvariantCulture), string.Empty));
        }

Usage Example

예제 #1
0
        public string TestOutputFormat(string format)
        {
            // Creat the result.
            var result = new FileResult
                {
                   Checked = true, Show = this.TestShows.First(), InputFile = Substitute.For<IFileInfo>()
                };
            result.Episode = result.Show.Episodes.First();
            result.Episodes = new List<Episode> { result.Episode };
            result.InputFile.Extension.Returns(".avi");

            // Format the string.
            return result.FormatOutputPath(format);
        }
All Usage Examples Of TVSorter.Model.FileResult::FormatOutputPath