예제 #1
0
        public static FileDate FindLastCacheFile(string cacheDir, string cacheFileNamePrefix, string dateFromToRegexPattern, string dateParsePattern, string separator)
        {
            var dateDictionary = new SortedDictionary <DateTime, FileDate>();

            string regexp = string.Format("{0}{1}{2}", cacheFileNamePrefix, separator, dateFromToRegexPattern);
            Regex  reg    = new Regex(regexp);

            string directorySearchPattern  = string.Format("{0}*", cacheFileNamePrefix);
            IEnumerable <string> filePaths = Directory.EnumerateFiles(cacheDir, directorySearchPattern);

            foreach (var filePath in filePaths)
            {
                var fileName = Path.GetFileName(filePath);
                var match    = reg.Match(fileName);
                if (match.Success)
                {
                    var from = match.Groups[1].Value;
                    var to   = match.Groups[2].Value;

                    var dateFrom = DateTime.ParseExact(from, dateParsePattern, CultureInfo.InvariantCulture);
                    var dateTo   = DateTime.ParseExact(to, dateParsePattern, CultureInfo.InvariantCulture);
                    var fileDate = new FileDate
                    {
                        From     = dateFrom,
                        To       = dateTo,
                        FilePath = filePath
                    };
                    dateDictionary.Add(dateTo, fileDate);
                }
            }

            if (dateDictionary.Count() > 0)
            {
                // the first element is the newest date
                return(dateDictionary.Last().Value);
            }

            // return a default file date
            return(default(FileDate));
        }
예제 #2
0
 public abstract Task <List <T> > GetCombinedUpdatedAndExistingAsync(IMyConfiguration configuration, TextWriter writer, FileDate lastCacheFileInfo, DateTime from, DateTime to);