示例#1
0
        public SyncLogEntry(FileEntryType entryType, string decrFileName, DateTime decrModified, string encrFileName, DateTime encrModified)
        {
            if (string.IsNullOrWhiteSpace(decrFileName))
            {
                throw new ArgumentNullException(nameof(decrFileName));
            }
            if (string.IsNullOrWhiteSpace(encrFileName))
            {
                throw new ArgumentNullException(nameof(encrFileName));
            }
            if (!HelixUtil.IsValidPath(decrFileName))
            {
                throw new ArgumentOutOfRangeException(nameof(decrFileName), "Invalid Path '" + decrFileName + "'");
            }
            if (!HelixUtil.IsValidPath(encrFileName))
            {
                throw new ArgumentOutOfRangeException(nameof(encrFileName), "Invalid Path '" + encrFileName + "'");
            }

            this.EntryType = entryType;

            this.DecrFileName = HelixUtil.PathUniversal(decrFileName);

            if (entryType != FileEntryType.File)
            {
                this.DecrModified = DateTime.MinValue;
            }
            else
            {
                this.DecrModified = HelixUtil.TruncateTicks(decrModified);
            }

            this.EncrFileName = HelixUtil.PathUniversal(encrFileName);
            this.EncrModified = HelixUtil.TruncateTicks(encrModified);
        }
示例#2
0
        public static FileEntry FromFile(string fullPath, string root)
        {
            root     = HelixUtil.PathNative(root);
            fullPath = HelixUtil.PathNative(fullPath);

            string    casedFullPath = HelixUtil.GetExactPathName(fullPath);
            FileEntry fileInfo      = new FileEntry
            {
                FileName = HelixUtil.PathUniversal(HelixUtil.RemoveRootFromPath(fullPath, root))
            };

            var fi = new FileInfo(casedFullPath);

            //Check to ensure ends with to address case changes
            if (fi.Exists && fi.FullName.EndsWith(fullPath, StringComparison.Ordinal))
            {
                fileInfo.LastWriteTimeUtc = HelixUtil.TruncateTicks(fi.LastWriteTimeUtc);
                fileInfo.Length           = fi.Length;
                fileInfo.EntryType        = FileEntryType.File;
                return(fileInfo);
            }

            var di = new DirectoryInfo(casedFullPath);

            if (di.Exists && di.FullName.EndsWith(fullPath, StringComparison.Ordinal))
            {
                fileInfo.LastWriteTimeUtc = DateTime.MinValue;
                fileInfo.EntryType        = FileEntryType.Directory;
                return(fileInfo);
            }

            fileInfo.LastWriteTimeUtc = DateTime.MinValue;
            fileInfo.EntryType        = FileEntryType.Removed;
            return(fileInfo);
        }
示例#3
0
        public static SyncLogEntry TryParseFromString(string line)
        {
            var match = lineParse.Match(line);

            if (!match.Success)
            {
                return(null);
            }

            var typeFlag = match.Groups["Type"].Value;

            DateTime decrModified;

            if (match.Groups["DecrModified"].Value == dateZero)
            {
                decrModified = DateTime.MinValue;
            }
            else if (!DateTime.TryParseExact(match.Groups["DecrModified"].Value, dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out decrModified))
            {
                return(null);
            }

            string decrFileName = HelixUtil.Unquote(match.Groups["DecrFileName"].Value);

            DateTime encrModified;

            if (match.Groups["EncrModified"].Value == dateZero)
            {
                encrModified = DateTime.MinValue;
            }
            else if (!DateTime.TryParseExact(match.Groups["EncrModified"].Value, dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out encrModified))
            {
                return(null);
            }

            string encrFileName = HelixUtil.Unquote(match.Groups["EncrFileName"].Value);

            return(new SyncLogEntry
            {
                DecrFileName = HelixUtil.PathUniversal(decrFileName),
                DecrModified = HelixUtil.TruncateTicks(decrModified),
                EncrFileName = HelixUtil.PathUniversal(encrFileName),
                EncrModified = HelixUtil.TruncateTicks(encrModified),
                EntryTypeFlag = typeFlag,
            });
        }