/// <summary>
        /// convert the sortfield for serialisation
        /// </summary>
        /// <returns></returns>
        public static string WriteSortField(PodcastFileSortField sortField)
        {
            switch (sortField)
            {
            case PodcastFileSortField.CreationTime:
                return("creationtime");

            default:
                return("name");
            }
        }
示例#2
0
        /// <summary>
        /// sort the supplied list of abstract files
        /// </summary>
        /// <param name="files">list of abstract files</param>
        /// <param name="sortField">field to sort on "creationtime" to use the file created time anything else to use the file name</param>
        /// <param name="ascendingSort">true to sort ascending false to sort descending</param>
        public IList <IFileInfo> Sort(IEnumerable <IFileInfo> files, PodcastFileSortField sortField, bool ascendingSort)
        {
            List <IFileInfo> sortedFiles = new List <IFileInfo>(files);

            switch (sortField)
            {
            case PodcastFileSortField.CreationTime:
                sortedFiles.Sort((f1, f2) => f1.CreationTime.CompareTo(f2.CreationTime));
                break;

            default:
                sortedFiles.Sort((f1, f2) => string.Compare(f1.Name, f2.Name, StringComparison.OrdinalIgnoreCase));
                break;
            }

            if (!ascendingSort)
            {
                sortedFiles.Reverse();
            }

            return(sortedFiles);
        }
示例#3
0
 /// <summary>
 /// the global default for podcasts
 /// </summary>
 public void SetDefaultSortField(PodcastFileSortField sortField)
 {
     DefaultSortField = sortField;
 }
示例#4
0
        /// <summary>
        /// gets a number of files that match a given pattern
        /// </summary>
        /// <param name="folderPath">folder to look in</param>
        /// <param name="pattern">pattern to look for eg. *.mp3</param>
        /// <param name="maximumNumberOfFiles">maximum number of files to find</param>
        /// <param name="sortField">field to sort on</param>
        /// <param name="ascendingSort">true to sort ascending false to sort descending</param>
        /// <returns></returns>
        public IList <IFileInfo> GetFiles(string folderPath, string pattern, int maximumNumberOfFiles, PodcastFileSortField sortField, bool ascendingSort)
        {
            var directoryInfo = DirectoryInfoProvider.GetDirectoryInfo(folderPath);

            var sortedFiles = GetSortedFiles(directoryInfo, pattern, sortField, ascendingSort);

            if (maximumNumberOfFiles >= 0)
            {
                sortedFiles = sortedFiles.Take(maximumNumberOfFiles);
            }

            return(sortedFiles.ToList());
        }
示例#5
0
        private IEnumerable <IFileInfo> GetSortedFiles(IDirectoryInfo src, string pattern, PodcastFileSortField sortField, bool ascendingSort)
        {
            try
            {
                var fileList = new Collection <IFileInfo>(src.GetFiles(pattern));

                return(FileSorter.Sort(fileList, sortField, ascendingSort));
            }
            catch (DirectoryNotFoundException)
            {
                // if the folder is not there then there is nothing to do
                return(new Collection <IFileInfo>());
            }
        }