/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception> private void ReplaceDatabase(string databaseName, InputStream databaseStream, IEnumerator <KeyValuePair <string, InputStream> > attachmentStreams) { try { Database database = GetDatabase(databaseName); string dstAttachmentsPath = database.GetAttachmentStorePath(); OutputStream destStream = new FileOutputStream(new FilePath(database.GetPath())); StreamUtils.CopyStream(databaseStream, destStream); FilePath attachmentsFile = new FilePath(dstAttachmentsPath); FileDirUtils.DeleteRecursive(attachmentsFile); attachmentsFile.Mkdirs(); if (attachmentStreams != null) { StreamUtils.CopyStreamsToFolder(attachmentStreams, attachmentsFile); } database.Open(); database.ReplaceUUIDs(); } catch (FileNotFoundException e) { Log.E(Database.Tag, string.Empty, e); throw new CouchbaseLiteException(Status.InternalServerError); } catch (IOException e) { Log.E(Database.Tag, string.Empty, e); throw new CouchbaseLiteException(Status.InternalServerError); } }
/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception> public virtual void TestServer() { //to ensure this test is easily repeatable we will explicitly remove //any stale foo.cblite bool mustExist = true; Database old = manager.GetDatabaseWithoutOpening("foo", mustExist); if (old != null) { old.Delete(); } mustExist = false; Database db = manager.GetDatabaseWithoutOpening("foo", mustExist); NUnit.Framework.Assert.IsNotNull(db); NUnit.Framework.Assert.AreEqual("foo", db.GetName()); NUnit.Framework.Assert.IsTrue(db.GetPath().StartsWith(GetServerPath())); NUnit.Framework.Assert.IsFalse(db.Exists()); // because foo doesn't exist yet IList <string> databaseNames = manager.GetAllDatabaseNames(); NUnit.Framework.Assert.IsTrue(!databaseNames.Contains("foo")); NUnit.Framework.Assert.IsTrue(db.Open()); NUnit.Framework.Assert.IsTrue(db.Exists()); databaseNames = manager.GetAllDatabaseNames(); NUnit.Framework.Assert.IsTrue(databaseNames.Contains("foo")); db.Close(); db.Delete(); }
public virtual void ReplaceDatabase(string databaseName, FilePath databaseFile, FilePath attachmentsDirectory) { Database database = GetDatabase(databaseName); string dstAttachmentsPath = database.GetAttachmentStorePath(); FilePath destFile = new FilePath(database.GetPath()); FileDirUtils.CopyFile(databaseFile, destFile); FilePath attachmentsFile = new FilePath(dstAttachmentsPath); FileDirUtils.DeleteRecursive(attachmentsFile); attachmentsFile.Mkdirs(); if (attachmentsDirectory != null) { FileDirUtils.CopyFolder(attachmentsDirectory, attachmentsFile); } database.ReplaceUUIDs(); }
public void ReplaceDatabase(string databaseName, FilePath databaseFile, FilePath attachmentsDirectory) { try { Database database = GetDatabase(databaseName); string dstAttachmentsPath = database.GetAttachmentStorePath(); FilePath destFile = new FilePath(database.GetPath()); FileDirUtils.CopyFile(databaseFile, destFile); FilePath attachmentsFile = new FilePath(dstAttachmentsPath); FileDirUtils.DeleteRecursive(attachmentsFile); attachmentsFile.Mkdirs(); if (attachmentsDirectory != null) { FileDirUtils.CopyFolder(attachmentsDirectory, attachmentsFile); } database.ReplaceUUIDs(); } catch (IOException e) { Log.E(Database.Tag, string.Empty, e); throw new CouchbaseLiteException(Status.InternalServerError); } }