public void testLockFile() { WebDAVInterface wdi = getClient(); bool hasLockFile = wdi.CheckForLockFile(); Assert.IsFalse(hasLockFile, "shouldn't have lock file"); String fileName = "lock"; createTestFile(fileName); try { bool success = wdi.UploadFile(fileName); Assert.IsTrue(success, "upload failed"); hasLockFile = wdi.CheckForLockFile(); Assert.IsTrue(hasLockFile, "uploading lock file error"); success = wdi.RemoveLock(); Assert.IsTrue(success, "remove lock error"); hasLockFile = wdi.CheckForLockFile(); Assert.IsFalse(hasLockFile, "shouldn't have lock file"); } finally { deleteTestFile(fileName); } }
public void testNotesUpAndDownload() { String[] notesNames = new string[] { "note1.note", "blub.note", "asdf.note" }; WebDAVInterface wdi = getClient(); String basepath = "./temp/"; Directory.CreateDirectory(basepath); // create the note files) foreach (String fileName in notesNames) { createTestFile(basepath + fileName); } try { bool success = wdi.UploadNotes(basepath); Assert.IsTrue(success, "upload failed"); // now delete all locally foreach (String fileName in notesNames) { deleteTestFile(basepath + fileName); } // now download them from remote success = wdi.DownloadNotes(basepath); Assert.IsTrue(success, "download failed"); // delete them on the remote server to be clean for the next test foreach (String fileName in notesNames) { wdi.RemoveFile(fileName); } // check if all are there: foreach (String fileName in notesNames) { Assert.IsTrue(File.Exists(basepath + fileName), "we should have this file!"); } } finally { // try again to delete notes foreach (String fileName in notesNames) { try { deleteTestFile(basepath + fileName); } catch (Exception) { ; // ignore } } Directory.Delete(basepath); } }
/// <summary> /// Get config settings /// </summary> private bool GetConfigSettings(out string _password, out WebDAVInterface _webdav) { _password = null; _webdav = null; object ask = Preferences.Get(AddinPreferences.SYNC_PRIVATENOTES_ASKEVERYTIME); if (ask == null) { return(false); } if (((bool)ask == false)) { #if WIN32 && DPAPI object pw = DPAPIUtil.getPassword(); #else object pw = Preferences.Get(AddinPreferences.SYNC_PRIVATENOTES_PASSWORD); #endif if (pw != null) { _password = Convert.ToString(pw); // quick fix -> a num-only pw is returned as an int o.O } } if (_password == null) { // ask for password var entryWindow = new PrivateNotes.PasswordEntry(); _password = entryWindow.getPassword(); } #if USE_LOCAL_TEST _webdav = new WebDAVInterface("http://localhost", "/webdav/notes", "wampp", "xampp", false); #else Uri serverUri = new Uri(Convert.ToString(Preferences.Get(AddinPreferences.SYNC_PRIVATENOTES_SERVERPATH))); String serverHost = serverUri.GetLeftPart(UriPartial.Authority); String serverBasePath = serverUri.AbsolutePath; bool checkSslCertificates = true; object checksslobj = Preferences.Get(AddinPreferences.SYNC_PRIVATENOTES_SERVERCHECKSSLCERT); if (checksslobj != null && (checksslobj.Equals(false) || checksslobj.Equals("false"))) { checkSslCertificates = false; } string serverUser = (string)Preferences.Get(AddinPreferences.SYNC_PRIVATENOTES_SERVERUSER); string serverPass = (string)Preferences.Get(AddinPreferences.SYNC_PRIVATENOTES_SERVERPASS); Logger.Debug("will user server: " + serverHost + " path: " + serverBasePath); //Logger.Debug("creating server with user " + serverUser + " pass: " + serverPass); _webdav = new WebDAVInterface(serverHost, serverBasePath, serverUser, serverPass, checkSslCertificates); #endif if (_webdav != null && _password != null) { return(true); } return(false); }
private WebDAVInterface getClient() { WebDAVInterface wdc = new WebDAVInterface(TESTSERVER, TESTPATH, TESTUSER, TESTPASSWORD, false); return(wdc); }