private static void UpdateDirectory(SyncDirectory syncDirA, SyncDirectory syncDirB) { var fm = new FileInfoHelper(); syncDirA.SyncFileData.ToList().ForEach(syncFileData => { Compare(syncFileData, syncDirA, syncDirB); }); fm.WriteToSyncFile(syncDirB); }
private static void Compare(SyncFileData syncFileData, SyncDirectory syncDirA, SyncDirectory syncDirB) { var fileInfoHelper = new FileInfoHelper(); var syncFile = syncDirB.SyncFileData.SingleOrDefault(f => f.Name == syncFileData.Name); if (syncFile == null) { fileInfoHelper.Copy(syncFileData, syncDirA, syncDirB); } else { if (syncFileData.Logs.Last().Hash != syncFile.Logs.Last().Hash) { if (syncFileData.Logs.Last().Date > syncFile.Logs.Last().Date) { //fm.Copy(syncDirA, syncDirB, syncFileData); } } else { if (syncFileData.Logs.Last().Date > syncFile.Logs.Last().Date) { // fm.Copy(syncDirB, syncDirA, syncFileData); } } } }
private static void Start(string[] args) { var fileHelper = new FileInfoHelper(); var dirs = fileHelper.GetDirectoryInfo(args).ToList(); var syncDirA = new SyncDirectory(dirs.ElementAt(0)); var syncDirB = new SyncDirectory(dirs.ElementAt(1)); var syncMan = new SyncManager(); syncMan.Sync(syncDirA, syncDirB); }
internal void Copy(SyncFileData fileToCopy, SyncDirectory fromDirectory, SyncDirectory toDirectory) { var src = Format(fromDirectory, fileToCopy.Name); var dest = Format(toDirectory, fileToCopy.Name); File.Copy(src, dest, true); var syncFileData = SyncFileManager.CreateSyncFileData(dest); var foo = toDirectory.SyncFileData.ToList(); foo.Add(syncFileData); toDirectory.SyncFileData = foo; WriteToSyncFile(toDirectory); }
private static string Format(SyncDirectory fullName, string fileName) { return string.Format(@"{0}\{1}", fullName.FileInfo.FullName, fileName); }
internal void WriteToSyncFile(SyncDirectory syncDirB) { var syncPath = string.Format(@"{0}\{1}", syncDirB.FileInfo.FullName, SynFile); var json = JsonConvert.SerializeObject(syncDirB.SyncFileData); File.WriteAllText(syncPath, json); }
internal void Sync(SyncDirectory syncDirA, SyncDirectory syncDirB) { UpdateDirectory(syncDirA, syncDirB); //DoStuff(syncDirB, syncDirA); }