Esempio n. 1
0
        internal static FileInfo WithRemovedTimeStamp(this FileInfo file, IBackupSettings setting)
        {
            if (setting.TimeStampFormat is null)
            {
                return(file);
            }

            var pattern  = setting.TimeStampPattern();
            var stripped = Regex.Replace(file.FullName, pattern, string.Empty, RegexOptions.RightToLeft | RegexOptions.Singleline);

            return(new FileInfo(stripped));
        }
Esempio n. 2
0
        internal static FileInfo WithRemovedTimeStamp(this FileInfo file, IBackupSettings setting)
        {
            Ensure.NotNull(file, nameof(file));
            Ensure.NotNull(setting, nameof(setting));
            if (setting.TimeStampFormat == null)
            {
                return(file);
            }
            var pattern  = setting.TimeStampPattern();
            var stripped = Regex.Replace(file.FullName, pattern, "", RegexOptions.RightToLeft | RegexOptions.Singleline);

            return(new FileInfo(stripped));
        }
Esempio n. 3
0
        internal static DateTime GetTimeStamp(this FileInfo file, IBackupSettings setting)
        {
            Ensure.NotNull(file, nameof(file));
            Ensure.NotNull(setting, nameof(setting));
            if (setting.TimeStampFormat == null)
            {
                return(file.CreationTime);
            }
            var pattern      = setting.TimeStampPattern();
            var timeAsString = Regex.Match(file.FullName, pattern, RegexOptions.RightToLeft | RegexOptions.Singleline)
                               .Groups["timestamp"]
                               .Value;

            if (string.IsNullOrEmpty(timeAsString))
            {
                return(file.CreationTime);
            }
            var timeStamp = DateTime.ParseExact(timeAsString, setting.TimeStampFormat, CultureInfo.InvariantCulture);

            return(timeStamp);
        }