Пример #1
0
        public static void AddDummyUserIfRequired(Funq.Container container)
        {
            // create a dummy user
            var fac = container.Resolve<IDbConnectionFactory> ();
            using (var db = fac.OpenDbConnection ()) {

                if (db.FirstOrDefault<DBUser> (u => u.Username == "dummy") == null) {

                    var user = new DBUser ();
                    user.Username = "******";
                    user.CreateCryptoFields ("foobar123");
                    user.FirstName = "John Dummy";
                    user.LastName = "Doe";
                    user.AdditionalData  = "Dummy user that is created when in development mode";
                    user.IsActivated = true;
                    user.IsVerified = true;
                    user.Manifest.LastSyncRevision = 0;
                    user.EmailAddress = "*****@*****.**";
                    db.Insert<DBUser> (user);
                    // insert some sample notes
                    var f = container.Resolve<IDbStorageFactory> ();
                    var key = user.GetPlaintextMasterKey ("foobar123");
                    var r = new RequestingUser {
                        Username = "******",
                        EncryptionMasterKey = key.ToHexString ()
                    };
                    using (var storage = f.GetDbStorage (r)) {
                        var sample_notes = new DiskStorage ();
                        sample_notes.SetPath ("../../../sample_notes/");
                        sample_notes.CopyTo (storage);
                    }

                }
            }
        }
Пример #2
0
 public void GetNotes_NoteFolderDoesNotExist_ReturnsNone()
 {
     IStorage storage = new DiskStorage (NOTE_FOLDER_INVALID);
     Dictionary<string, Note> notes = storage.GetNotes ();
     Assert.IsNotNull (notes);
     Assert.IsTrue (notes.Count == 0);
 }
Пример #3
0
 public void GetNotes_NotesExist_ReturnsNotes()
 {
     IStorage storage = new DiskStorage (NOTE_FOLDER_PROPER_NOTES);
     Dictionary<string, Note> notes = storage.GetNotes ();
     Assert.IsNotNull (notes);
     Assert.IsTrue (notes.Count > 0);
 }
Пример #4
0
        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);
        }
Пример #5
0
        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
        }
Пример #6
0
		/// <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.ReadFile ();

			if (settings == null) {
				SettingsSync.CreateSettings ();
				settings = new SettingsSync ();
				Console.WriteLine ("Created New settings");
			}

            		Notebooks = new List<string>();
            		currentNotebook = "All Notebooks";
			PopulateNotebookList(true);

			Console.WriteLine ("App Delegate Loaded!");
		}
Пример #7
0
        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);
        }
Пример #8
0
 public void GetNotes_NoteExistsWithSpecificKey_ReturnsNoteWithSpecificKey()
 {
     IStorage storage = new DiskStorage (NOTE_FOLDER_PROPER_NOTES);
     Dictionary<string, Note> notes = storage.GetNotes ();
     Assert.IsTrue (notes.ContainsKey ("note://tomboy/90d8eb70-989d-4b26-97bc-ba4b9442e51f"));
 }
Пример #9
0
 public void GetNotes_NoteDoesNotExistWithSpecificKey_DoesNotReturnNoteWithSpecificKey()
 {
     IStorage storage = new DiskStorage (NOTE_FOLDER_PROPER_NOTES);
     Dictionary<string, Note> notes = storage.GetNotes ();
     Assert.IsFalse (notes.ContainsKey ("not-a-key"));
 }
Пример #10
0
        public void WriteNote_NoteFileExists_NoteFileIsOverwritten()
        {
            DiskStorage storage = new DiskStorage (NOTE_FOLDER_TEMP);

            string note_name = "existing_note.note";
            string note_path = Path.Combine (NOTE_FOLDER_TEMP, note_name);

            System.IO.File.WriteAllText (note_path, "Test");

            storage.Write (note_name, TesterNote.GetTesterNote ());

            string noteContents = System.IO.File.ReadAllText (note_path);
            Assert.AreNotEqual (noteContents, "Test", "The pre-existing note has not been overwritten!");

            System.IO.File.Delete (note_path); //Clear up test for next time
        }
Пример #11
0
        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));
        }
Пример #12
0
        public void ReadConfigVariable_NoConfigFile_ThrowsException()
        {
            IStorage storage = new DiskStorage (NOTE_FOLDER_TEMP);

            storage.GetConfigVariable ("whatever");
        }
Пример #13
0
        public void SetConfigVariable_ConfigFileExists_UpdatesVariable()
        {
            IStorage storage = new DiskStorage (NOTE_FOLDER_PROPER_NOTES);
            string config_name = "config.xml";
            string config_path = Path.Combine (NOTE_FOLDER_PROPER_NOTES, config_name);

            storage.SetConfigVariable ("testvar", "testval2");

            XDocument config = XDocument.Load (config_path);
            Assert.AreEqual ("testval2", config.Root.Element ("testvar").Value);

            config.Root.Element ("testvar").Value = "testval"; //Reset
            config.Save (config_path);
        }
Пример #14
0
		/// <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";
			}
        	}
Пример #15
0
            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);
                }

                var disk_storage = new DiskStorage (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);
                    Manifest = SyncManifest.Read(manifest_xml);
                } else {
                    Manifest = new SyncManifest ();
                    Manifest.ServerId = Guid.NewGuid ().ToString ();
                }
            }
Пример #16
0
        public void ReadConfigVariable_ConfigFileExists_ReturnsVariable()
        {
            IStorage storage = new DiskStorage (NOTE_FOLDER_PROPER_NOTES);

            Assert.AreEqual ("testval", storage.GetConfigVariable ("testvar"));
        }
Пример #17
0
        public void SetConfigVariable_NoConfigFile_CreatesFileAndVariable()
        {
            IStorage storage = new DiskStorage (NOTE_FOLDER_TEMP);

            string config_name = "config.xml";
            string config_path = Path.Combine (NOTE_FOLDER_TEMP, config_name);
            System.IO.File.Delete (config_path); //Make sure it doesn't exist from before

            storage.SetConfigVariable ("testvar", "testval");

            Assert.IsTrue (System.IO.File.Exists (config_path));
            XDocument config = XDocument.Load (config_path);
            Assert.AreEqual ("testval", config.Root.Element ("testvar").Value);

            System.IO.File.Delete (config_path); //Clear up test for next time
        }
Пример #18
0
 public void Init()
 {
     IStorage storage = new DiskStorage ("../../test_notes/proper_notes");
     engine = new Engine (storage);
 }
Пример #19
0
        public void SetPath_NoteFolderDoesNotExist_CreatesFolder()
        {
            try {
                System.IO.Directory.Delete (NOTE_FOLDER_INVALID);
            }
            catch (System.IO.DirectoryNotFoundException) {} //This is expected provided the test passed last time.

            IStorage storage = new DiskStorage (NOTE_FOLDER_INVALID);

            Assert.IsTrue (System.IO.Directory.Exists (NOTE_FOLDER_INVALID));
            System.IO.Directory.Delete (NOTE_FOLDER_INVALID);
        }
Пример #20
0
		/// <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);
			}

        	}
Пример #21
0
        public void WriteNote_NoteFileDoesNotExist_NoteFileIsCreated()
        {
            DiskStorage storage = new DiskStorage (NOTE_FOLDER_TEMP);

            string note_name = "90d8eb70-989d-4b26-97bc-ba4b9442e51d.note";
            string note_path = Path.Combine (NOTE_FOLDER_TEMP, note_name);
            System.IO.File.Delete (note_path); //Make sure it doesn't exist from before

            storage.Write (note_name, TesterNote.GetTesterNote ());
            Assert.IsTrue (System.IO.File.Exists (note_path));

            System.IO.File.Delete (note_path); //Clear up test for next time
        }