/// <summary>
        /// Iterate over lists of regular and backup files
        /// and delete those which match the list of years
        /// passed in by the caller.
        ///
        /// Iterate in descending order so that we can delete items from the
        /// lists without changing the indices.
        ///
        /// Do not delete ParticipantList files.
        ///
        /// Return the count of files deleted.
        /// </summary>
        /// <param name="years"></param>
        /// <returns></returns>
        public int DeleteOldFiles(List <String> years)
        {
            int retInt = 0;

            for (int idx = RegularFilesCount - 1; idx >= 0; idx--)
            {
                HllFileInfo fi = RegularHllFiles[idx];
                if ((years.Contains(fi.Year)) &&
                    (!fi.Type.IsParticipantList))
                {
                    if (File.Exists(fi.FullPath))
                    {
                        File.Delete(fi.FullPath);
                    }
                    RegularHllFiles.RemoveAt(idx);
                    retInt++;
                }
            }
            for (int idx = BackupFilesCount - 1; idx >= 0; idx--)
            {
                HllFileInfo fi = BackupHllFiles[idx];
                if ((years.Contains(fi.Year)) &&
                    (!fi.Type.IsParticipantList))
                {
                    if (File.Exists(fi.FullPath))
                    {
                        File.Delete(fi.FullPath);
                    }
                    BackupHllFiles.RemoveAt(idx);
                    retInt++;
                }
            }
            return(retInt);
        }
 /// <summary>
 /// The UI allows users to select which files to see in the list. Filtering
 /// is possible by year, donor, and file type, and users can also choose
 /// whether or not to display backup files.
 /// </summary>
 /// <param name="fullpath"></param>
 /// <returns></returns>
 private bool PassesFilter(HllFileInfo hfi, FilterSet filterset)
 {
     if (!hfi.IsValidHLL)
     {
         return(false);
     }
     if (hfi.Year != this.filterset.YearFilter)
     {
         return(false);
     }
     if (!this.filterset.TypeFIlter.Matches(hfi.Type))
     {
         return(false);
     }
     if (hfi.HasNoDonor)
     {
         return(true);
     }
     else
     {
         return(DonorMatches(hfi, filterset.DonorFilter));
     }
 }
        /// <summary>
        /// Get names of all files in and under output folder that
        /// have the appropriate extension.
        ///
        /// For each of those files, make an HllFileInfo object
        /// and add that object to either the RegularHllFiles or the
        /// BackupHllFiles list.
        ///
        /// </summary>
        public void LoadSourceFileList()
        {
            string fld = FolderManager.OutputFolder;

            this.RegularHllFiles.Clear();
            this.BackupHllFiles.Clear();

            if (Directory.Exists(fld))
            {
                // do recursive search for all files with appropriate extensions
                this.AllFilenames = Directory.GetFiles(fld, "*", SearchOption.AllDirectories)
                                    .Where(f => HllUtils.LIST_AND_LABEL_EXTENSIONS.Contains(Path.GetExtension(f))).ToArray();
            }
            else
            {
                this.AllFilenames = new string[0];
            }

            if (this.AllFilenames.Count() > 0)
            {
                foreach (string fs in this.AllFilenames)
                {
                    HllFileInfo fi = new HllFileInfo(fs);
                    if (fi.IsValidHLL) // Don't bother if it's not a valid file.
                    {
                        if (fi.IsBackupFile)
                        {
                            this.BackupHllFiles.Add(fi);
                        }
                        else
                        {
                            this.RegularHllFiles.Add(fi);
                        }
                    }
                }
            }
        }
 private bool TypeMatches(HllFileInfo hfi, FilterSetTypeFilters tf)
 {
     return(hfi.Type.Matches(tf));
 }
 private bool DonorMatches(HllFileInfo hfi, string donor_filter)
 {
     return(hfi.DonorCode == donor_filter);
 }
 private bool YearMatches(HllFileInfo hfi, string year)
 {
     return(hfi.Year == year);
 }