/// <summary> /// Constructor /// </summary> /// <param name="archivePath">Path of the archive directory</param> /// <param name="contentPath">Path of the source root directory being archived</param> /// <param name="readPreviousArchiveLog">If true, previous archive will be loaded (if found) and only changed files will be (re)archived</param> public Archive(string archivePath, string contentPath, bool readPreviousArchiveLog) { // Compose and set properties this.archivePath = FsService.FormatDirectoryPathString( Path.Join( archivePath, (contentPath.EndsWith("/") ? contentPath.Substring(0, contentPath.Length - 1) : contentPath).Replace(":", "").Replace(' ', '_').Replace('/', ' ') ) ); this.archiveName = String.Format( "{0} ({1:0000}-{2:00}-{3:00} {4:00}-{5:00}-{6:00})", DateTime.UtcNow.ToFileTimeUtc(), DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second ); string path = String.Format("{0}{1}", this.archivePath, this.archiveName); this.archiveFileFullPath = String.Format("{0}.zip", path); // Initialize logs (load previous log firs, or previous will equal current) if (readPreviousArchiveLog) { this.previousLog = ArchiveLog.GetLastArchiveLog(this.archivePath); if (this.previousLog != null) { this.previousLog.ReadAllEntries(); } } this.currentLog = new ArchiveLog(String.Format("{0}.log", path)); }
/// <summary> /// Transfers unmatched entries from this log to another /// </summary> /// <param name="log">Log to match entries agains and transfer unmatched entries into</param> /// <returns>Number of entries transfered</returns> public long TransferMissingEntries(ArchiveLog log) { long count = 0; // Loop all entries foreach (ArchiveLogEntry entry in this.entries.Values) { // Check if entry not present in target log if (log.FindEntry(entry.path) == null) { // Write entry into new log as deleted log.WriteEntry(new ArchiveLogEntry() { path = entry.path, status = ArchiveLogFileArchivingStatus.DELETED, mtime = entry.mtime, size = entry.size, archive = entry.archive }); } } return(count); }