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); input.Close(); } 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); }; }
/// <summary> /// Will create a new sync client using a custom IStorage as data backend. /// When using different IStorage backend, multiple instances of ISyncClient /// are allowed to exist simultaneously. /// </summary> public FilesystemSyncClient(Engine engine, SyncManifest manifest) { this.manifest = manifest; this.Engine = engine; this.DeletedNotes = new List<Note> (); }
public AppDelegate() { // TODO, set it in a generic way Tomboy.DiskStorage.Instance.SetPath ("/Users/jeremie/projects/MacBoy/test-notes"); NoteEngine = new Engine (Tomboy.DiskStorage.Instance); Notes = NoteEngine.GetNotes (); // Create our cache directory if (!Directory.Exists (BaseUrlPath)) Directory.CreateDirectory (BaseUrlPath); }
public void SetUp() { var current_dir = Directory.GetCurrentDirectory (); serverStorageDir = Path.Combine (current_dir, "../../syncserver/"); serverStorage = new DiskStorage (serverStorageDir); serverEngine = new Engine (serverStorage); manifest = new SyncManifest (); syncServer = new FilesystemSyncServer (serverEngine, manifest); CreateSomeSampleNotes (); }
public FilesystemSyncServer(Engine engine, SyncManifest manifest) { this.engine = engine; this.manifest = manifest; // if not server id is set, set a new one if (string.IsNullOrEmpty (this.Id)) { this.Id = Guid.NewGuid ().ToString (); } newRevision = this.LatestRevision + 1; this.UploadedNotes = new List<Note> (); this.DeletedServerNotes = new List<string> (); }
public DatabaseNoteRepository(IDbConnectionFactory factory, DbStorageFactory storageFactory, IUser user) : base(factory) { this.storage = storageFactory.GetDbStorage (user); engine = new Engine (storage); using (var db = connFactory.OpenDbConnection ()) { this.dbUser = db.Select<DBUser> (u => u.Username == user.Username)[0]; } if (dbUser.Manifest == null || string.IsNullOrEmpty (dbUser.Manifest.ServerId)) { // the user may not yet have synced dbUser.Manifest.ServerId = Guid.NewGuid ().ToString (); } }
public void BenchmarkNoteStorage() { var local_storage = new DiskStorage ("../../tmpstorage"); var sample_notes = TestBase.GetSampleNotes (); var manifest = new SyncManifest (); var engine = new Engine (local_storage); sample_notes.ForEach(n => engine.SaveNote (n)); var sync_client = new FilesystemSyncClient (engine, manifest); var access_token = WebSyncServer.PerformFastTokenExchange (listenUrl, "testuser", "testpass"); var sync_server = new WebSyncServer (listenUrl, access_token); Action benchmark = () => new SyncManager (sync_client, sync_server).DoSync (); DbBenchmarks.RunBenchmark ("initial sync with 100 times no change at all", benchmark, 100); }
public override void SetUp() { base.SetUp (); DTOUser user; List<DTONote> sample_notes; JsonServiceClient client = GetAdminServiceClient (); user = new DTOUser() { Username = "******", Password = "******", AdditionalData = "Its just john" }; var user_url = new Rainy.WebService.Management.UserRequest ().ToUrl("POST"); client.Post<DTOUser> (user_url, user); sampleUser.Add (user); // add sample notes sample_notes = AbstractSyncServerTests.GetSomeSampleNotes () .Select (n => n.ToDTONote ()).ToList (); var syncServer = new WebSyncServer (testServer.RainyListenUrl, testServer.GetAccessToken ()); var storage = new DiskStorage (); var tmpPath = "/tmp/sync1"; storage.SetPath (tmpPath); var engine = new Engine (storage); var syncClient = new FilesystemSyncClient (engine, new SyncManifest ()); var syncManager = new Tomboy.Sync.SyncManager (syncClient, syncServer); syncManager.DoSync (); sampleNotes[user.Username] = sample_notes; user = new DTOUser() { Username = "******", Password = "******", AdditionalData = "Jane, Johns wife" }; client.Post<DTOUser> (user_url, user); sampleUser.Add (user); sampleNotes[user.Username] = AbstractSyncServerTests.GetSomeSampleNotes () .Select (n => n.ToDTONote ()).ToList (); // add sample user data }
private static void ProcessDirectory(string targetDirectory, Engine appEngine) { DiskStorage noteStorage = new DiskStorage (targetDirectory); Engine noteEngine = new Engine (noteStorage); Dictionary<string,Note> notes = new Dictionary<string,Note>(); try { notes = noteEngine.GetNotes (); } catch (ArgumentException) { Console.WriteLine ("Found an exception with {0}",targetDirectory); } foreach (Note note in notes.Values) { Note newNote = appEngine.NewNote (); newNote.ChangeDate = note.ChangeDate; newNote.CreateDate = note.CreateDate; newNote.CursorPosition = note.CursorPosition; newNote.Height = note.Height; newNote.MetadataChangeDate = note.MetadataChangeDate; newNote.Notebook = note.Notebook; newNote.OpenOnStartup = note.OpenOnStartup; newNote.SelectionBoundPosition = note.SelectionBoundPosition; newNote.Tags = note.Tags; newNote.Text = note.Text; newNote.Title = note.Title; newNote.Width = note.Width; newNote.X = note.X; newNote.Y = note.Y; appEngine.SaveNote (newNote, false); Console.WriteLine ("Imported the Note {0}",newNote.Title); } string [] subdirectoryEntries = System.IO.Directory.GetDirectories(targetDirectory); foreach(string subdirectory in subdirectoryEntries) ProcessDirectory(subdirectory, appEngine); }
/// <summary> /// Initializes a new instance of the <see cref="Tomboy.AppDelegate"/> class. /// </summary> public AppDelegate () { var storage_path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Library", "Application Support", "Tomboy"); // TODO, set it in a generic way noteStorage = new DiskStorage (storage_path); noteStorage.SetBackupPath(backupPathUri); if (!Directory.Exists(backupPathUri)) noteStorage.Backup(); //FIXME: Need to better handle status messages. Logger.Debug ("Backup Path set to {0}", backupPathUri); NoteEngine = new Engine (noteStorage); // keep track of note for syncing // TODO move this into an Add-in one day var manifest_path = Path.Combine (storage_path, "manifest.xml"); manifestTracker = new ManifestTracker (NoteEngine, manifest_path); // Create our cache directory if (!Directory.Exists (BaseUrlPath)) Directory.CreateDirectory (BaseUrlPath); // Currently lazy load because otherwise the Dock Menu throws an error about there being no notes. if (Notes == null) Notes = NoteEngine.GetNotes (); NoteEngine.NoteAdded += HandleNoteAdded; NoteEngine.NoteRemoved += HandleNoteRemoved; NoteEngine.NoteUpdated += HandleNoteUpdated; settings = SettingsSync.Read(); Notebooks = new List<string>(); currentNotebook = "All Notebooks"; PopulateNotebookList(); }
/// <summary> /// Syncs the notes. /// </summary> /// <param name="sender">Sender.</param> 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 void Init() { IPortableIoC container = new PortableIoc (); container.Register<DiskStorage> (c => { return new DiskStorage ("../../test_notes/proper_notes") { Logger = new ConsoleLogger () }; }); diskStorage = container.Resolve<DiskStorage> (); engine = new Engine (diskStorage); // get a new note instance note = engine.NewNote (); note.Title = "Unit Test Note"; note.Text = "Unit test note by NewNote() method"; engine.SaveNote (note); NOTE_PATH = Path.Combine ("../../test_notes/proper_notes", Utils.GetNoteFileNameFromURI (note)); }
public void Init() { IStorage storage = new DiskStorage ("../../test_notes/proper_notes"); engine = new Engine (storage); }
public DatabaseNoteRepository(string username) { dbConnection = DbConfig.GetConnection (); dbUser = dbConnection.First<DBUser> (u => u.Username == username); storage = new DbStorage (dbUser); engine = new Engine (storage); if (dbUser.Manifest == null || string.IsNullOrEmpty (dbUser.Manifest.ServerId)) { // the user may not yet have synced dbUser.Manifest.ServerId = Guid.NewGuid ().ToString (); } }
protected override void ClearServer(bool reset = false) { if (reset) { serverManifest = new SyncManifest (); CleanupServerDirectory (); } serverStorage = new DiskStorage (); serverStorage.SetPath (serverStorageDir); serverEngine = new Engine (serverStorage); syncServer = new FilesystemSyncServer (serverEngine, serverManifest); }
public DatabaseNoteRepository(string username) { username = username; dbConnection = DbConfig.GetConnection (); storage = new DbStorage (username); engine = new Engine (storage); var db_user = dbConnection.Select <DBUser> ("Username = {0}", username); if (db_user.Count == 0) { dbUser = new DBUser () { Username = username }; } else dbUser = db_user[0]; if (dbUser.Manifest == null || string.IsNullOrEmpty (dbUser.Manifest.ServerId)) { // the user may not yet have synced dbUser.Manifest = new SyncManifest (); dbUser.Manifest.ServerId = Guid.NewGuid ().ToString (); } }
/// <summary> /// Syncs the notes. /// </summary> /// <param name="sender">Sender.</param> partial void SyncNotes(NSObject sender) { bool success = false; if (!String.IsNullOrEmpty (settings.syncURL) || !String.IsNullOrWhiteSpace (settings.syncURL)) { 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); new SyncManager(client, server).DoSync (); // write back the dest manifest using (var output = new FileStream (dest_manifest_path, FileMode.Create)) { SyncManifest.Write (dest_manifest, output); } PopulateNotebookList (false); RefreshNotesWindowController (); success = true; } else if (!String.IsNullOrEmpty (settings.webSyncURL) ||!String.IsNullOrWhiteSpace (settings.webSyncURL)) { ServicePointManager.CertificatePolicy = new DummyCertificateManager(); OAuthToken reused_token = new OAuthToken { Token = settings.token, Secret = settings.secret }; ISyncClient client = new FilesystemSyncClient (NoteEngine, manifestTracker.Manifest); ISyncServer server = new WebSyncServer (settings.webSyncURL, reused_token); new SyncManager (client, server).DoSync (); PopulateNotebookList (false); RefreshNotesWindowController (); success = true; } if (success) { NSAlert alert = new NSAlert () { MessageText = "Sync Successful", InformativeText = "The sync was successful", AlertStyle = NSAlertStyle.Warning }; alert.AddButton ("OK"); alert.BeginSheet (null); alert.Window.Title = "Sync Successful"; } else { NSAlert alert = new NSAlert () { MessageText = "Sync Failed", InformativeText = "The sync was not successful. Please check the Sync Settings.", AlertStyle = NSAlertStyle.Warning }; alert.AddButton ("OK"); alert.BeginSheet (null); alert.Window.Title = "Sync Failed"; } }
public static void Export(string rootDirectory, Engine appEngine) { ProcessDirectory(rootDirectory, appEngine); }
private void InitServer() { serverStorage = new DiskStorage (); serverStorage.SetPath (serverStorageDir); serverEngine = new Engine (serverStorage); serverManifest = new SyncManifest (); syncServer = new FilesystemSyncServer (serverEngine, serverManifest); }
public void Init() { IStorage storage = DiskStorage.Instance; storage.SetPath ("../../test_notes/proper_notes"); engine = new Engine (storage); }
public void Init() { //TODO: The storage instance needs swapping with a stub/mock! DiskStorage.Instance.SetPath ("../../test_notes/proper_notes"); engine = new Engine (DiskStorage.Instance); // get a new note instance note = engine.NewNote (); note.Title = "Unit Test Note"; note.Text = "Unit test note by NewNote() method"; engine.SaveNote (note); NOTE_PATH = Path.Combine ("../../test_notes/proper_notes", Utils.GetNoteFileNameFromURI (note)); }
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 (); } }
public void Init() { //TODO: The storage instance needs swapping with a stub/mock! DiskStorage.Instance.SetPath ("../../test_notes/proper_notes"); engine = new Engine (DiskStorage.Instance); }