partial void SyncNotes(NSObject sender) { var dest_manifest_path = Path.Combine(settings.syncURL, "manifest.xml"); SyncManifest dest_manifest; if (!File.Exists(dest_manifest_path)) { using (var output = new FileStream(dest_manifest_path, FileMode.Create)) { SyncManifest.Write(new SyncManifest(), output); } } using (var input = new FileStream(dest_manifest_path, FileMode.Open)) { dest_manifest = SyncManifest.Read(input); } var dest_storage = new DiskStorage(settings.syncURL); var dest_engine = new Engine(dest_storage); var client = new FilesystemSyncClient(NoteEngine, manifestTracker.Manifest); var server = new FilesystemSyncServer(dest_engine, dest_manifest); var sync_manager = new SyncManager(client, server); sync_manager.DoSync(); RefreshNotesWindowController(); // write back the dest manifest using (var output = new FileStream(dest_manifest_path, FileMode.Create)) { SyncManifest.Write(dest_manifest, output); } }
public ManifestTracker(Engine engine, string path) { this.path = path; if (!File.Exists(path)) { Manifest = new SyncManifest(); using (var output = new FileStream(path, FileMode.Create)) { SyncManifest.Write(Manifest, output); } foreach (Note note in engine.GetNotes().Values) { Manifest.NoteRevisions [note.Guid] = Manifest.LastSyncRevision + 1; } Flush(); } using (var input = new FileStream(path, FileMode.Open)) { this.Manifest = SyncManifest.Read(input); } engine.NoteAdded += (Note note) => { Console.WriteLine("Note added"); Manifest.NoteRevisions [note.Guid] = Manifest.LastSyncRevision + 1; }; engine.NoteUpdated += (Note note) => { Console.WriteLine("Note updated"); Manifest.NoteRevisions [note.Guid] = Manifest.LastSyncRevision + 1; }; engine.NoteRemoved += (Note note) => { Console.WriteLine("Note removed: " + note.Guid); Manifest.NoteDeletions.Add(note.Guid, note.Title); }; }
public DirectoryBasedNoteRepository(string username, string notes_base_path) { this.Username = username; this.notesBasePath = notes_base_path; lock (userLocks) { if (!userLocks.ContainsKey(Username)) { userLocks [Username] = new Semaphore(1, 10); } } // if another instance for this user exists, wait until it is freed userLocks [username].WaitOne(); storagePath = this.notesBasePath + "/" + Username; if (!Directory.Exists(storagePath)) { Directory.CreateDirectory(storagePath); } storage = new DiskStorage(); storage.SetPath(storagePath); Engine = new Engine(storage); // read in data from "manifest" file manifestPath = Path.Combine(storagePath, "manifest.xml"); if (File.Exists(manifestPath)) { string manifest_xml = File.ReadAllText(manifestPath); var textreader = new StringReader(manifest_xml); var xmlreader = new XmlTextReader(textreader); Manifest = SyncManifest.Read(xmlreader); } else { Manifest = new SyncManifest(); Manifest.ServerId = Guid.NewGuid().ToString(); } }