Пример #1
0
        /// <summary>
        /// Initializes a Manager that stores Databases in the given directory.
        /// </summary>
        /// <param name="directoryFile"><see cref="System.IO.DirectoryInfo"/> object for initializing the Manager object.</param>
        /// <param name="options">Option flags for initialization.</param>
        /// <exception cref="T:System.IO.DirectoryNotFoundException">Thrown when there is an error while accessing or creating the given directory.</exception>
        public Manager(DirectoryInfo directoryFile, ManagerOptions options)
        {
            Log.I(Tag, "Starting Manager version: " + VersionString);

            this.directoryFile = directoryFile;
            this.options       = options ?? DefaultOptions;
            this.databases     = new Dictionary <string, Database>();
            this.replications  = new List <Replication>();

            //create the directory, but don't fail if it already exists
            if (!directoryFile.Exists)
            {
                directoryFile.Create();
                directoryFile.Refresh();
                if (!directoryFile.Exists)
                {
                    throw new  DirectoryNotFoundException("Unable to create directory " + directoryFile);
                }
            }

            UpgradeOldDatabaseFiles(directoryFile);

            var scheduler = options.CallbackScheduler;

            CapturedContext = new TaskFactory(scheduler);
            workExecutor    = new TaskFactory(new SingleTaskThreadpoolScheduler());
            Log.D(Tag, "New Manager uses a scheduler with a max concurrency level of {0}".Fmt(workExecutor.Scheduler.MaximumConcurrencyLevel));

            this.NetworkReachabilityManager = new NetworkReachabilityManager();

            SharedCookieStore = new CookieStore(this.directoryFile.FullName);
        }
Пример #2
0
        public void TestAPIManager()
        {
            Manager manager = this.manager;
            Assert.IsTrue(manager != null);

            foreach (string dbName in manager.AllDatabaseNames)
            {
                Database db = manager.GetDatabase(dbName);
                Log.I(TAG, "Database '" + dbName + "':" + db.DocumentCount + " documents");
            }

            var options = new ManagerOptions();
            options.ReadOnly = true;
            options.CallbackScheduler = new SingleTaskThreadpoolScheduler();

            var roManager = new Manager(new DirectoryInfo(manager.Directory), options);
            Assert.IsTrue(roManager != null);

            var nonExistantDatabase = roManager.GetDatabase("foo");
            Assert.IsNull(nonExistantDatabase);

            var dbNames = manager.AllDatabaseNames;
            Assert.IsFalse(dbNames.Contains<String>("foo"));
            Assert.IsTrue(dbNames.Contains(DefaultTestDb));
        }
Пример #3
0
        //SERVER & DOCUMENTS
        /// <exception cref="System.IO.IOException"></exception>
        // [Test]
        public void TestAPIManager()
        {
            Manager manager = this.manager;

            Assert.IsTrue(manager != null);

            foreach (string dbName in manager.AllDatabaseNames)
            {
                Database db = manager.GetDatabase(dbName);
                Log.I(Tag, "Database '" + dbName + "':" + db.DocumentCount + " documents");
            }

            var options = new ManagerOptions();

            options.ReadOnly          = true;
            options.CallbackScheduler = new SingleTaskThreadpoolScheduler();

            var roManager = new Manager(new DirectoryInfo(manager.Directory), options);

            Assert.IsTrue(roManager != null);

            var nonExistantDatabase = roManager.GetDatabase("foo");

            Assert.IsNull(nonExistantDatabase);

            var dbNames = manager.AllDatabaseNames;

            Assert.IsFalse(dbNames.Contains <String>("foo"));
            Assert.IsTrue(dbNames.Contains(DefaultTestDb));
        }
Пример #4
0
        public void TestReadOnlyDb()
        {
            CreateDocuments(database, 10);
            database.Close();

            var options = new ManagerOptions();

            options.ReadOnly = true;
            var readOnlyManager = new Manager(new DirectoryInfo(manager.Directory), options);

            database = readOnlyManager.GetExistingDatabase(database.Name);
            Assert.IsNotNull(database);
            var e = Assert.Throws <CouchbaseLiteException>(() => CreateDocuments(database, 1));

            Assert.AreEqual(StatusCode.Forbidden, e.Code);
            database.Close();

            var dbOptions = new DatabaseOptions();

            dbOptions.ReadOnly = true;
            database           = manager.OpenDatabase(database.Name, dbOptions);
            Assert.IsNotNull(database);
            e = Assert.Throws <CouchbaseLiteException>(() => CreateDocuments(database, 1));
            Assert.AreEqual(StatusCode.Forbidden, e.Code);
            database.Close();

            dbOptions.ReadOnly = false;
            database           = manager.OpenDatabase(database.Name, dbOptions);
            Assert.DoesNotThrow(() => CreateDocuments(database, 1));
        }
Пример #5
0
        public Manager(DirectoryInfo directoryFile, ManagerOptions options)
        {
            Log.V(Database.Tag, "Starting Manager version: " + VersionString);

            this.directoryFile = directoryFile;
            this.options       = options ?? DefaultOptions;
            this.databases     = new Dictionary <string, Database>();
            this.replications  = new AList <Replication>();

            //create the directory, but don't fail if it already exists
            if (!directoryFile.Exists)
            {
                directoryFile.Create();
                directoryFile.Refresh();
                if (!directoryFile.Exists)
                {
                    throw new  DirectoryNotFoundException("Unable to create directory " + directoryFile);
                }
            }

            UpgradeOldDatabaseFiles(directoryFile);

            scheduler    = TaskScheduler.Current; //new ConcurrentExclusiveSchedulerPair();
            workExecutor = new TaskFactory(scheduler /*.ExclusiveScheduler*/);
        }
Пример #6
0
        /// <summary>
        /// Initializes a Manager that stores Databases in the given directory.
        /// </summary>
        /// <param name="directoryFile"><see cref="System.IO.DirectoryInfo"/> object for initializing the Manager object.</param>
        /// <param name="options">Option flags for initialization.</param>
        /// <exception cref="T:System.IO.DirectoryNotFoundException">Thrown when there is an error while accessing or creating the given directory.</exception>
        public Manager(DirectoryInfo directoryFile, ManagerOptions options)
        {
            Log.I(TAG, "Starting Manager version: " + VersionString);

            this.directoryFile = directoryFile;
            this.options       = options ?? DefaultOptions;
            this.databases     = new Dictionary <string, Database>();
            this.replications  = new List <Replication>();

            //create the directory, but don't fail if it already exists
            if (!directoryFile.Exists)
            {
                directoryFile.Create();
                directoryFile.Refresh();
                if (!directoryFile.Exists)
                {
                    throw new  DirectoryNotFoundException("Unable to create directory " + directoryFile);
                }
            }

            UpgradeOldDatabaseFiles(directoryFile);

            #if __IOS__
            Foundation.NSString protection;
            switch (options.FileProtection & Foundation.NSDataWritingOptions.FileProtectionMask)
            {
            case Foundation.NSDataWritingOptions.FileProtectionNone:
                protection = Foundation.NSFileManager.FileProtectionNone;
                break;

            case Foundation.NSDataWritingOptions.FileProtectionComplete:
                protection = Foundation.NSFileManager.FileProtectionComplete;
                break;

            case Foundation.NSDataWritingOptions.FileProtectionCompleteUntilFirstUserAuthentication:
                protection = Foundation.NSFileManager.FileProtectionCompleteUntilFirstUserAuthentication;
                break;

            default:
                protection = Foundation.NSFileManager.FileProtectionCompleteUnlessOpen;
                break;
            }

            var attributes = new Foundation.NSDictionary(Foundation.NSFileManager.FileProtectionKey, protection);
            Foundation.NSError error;
            Foundation.NSFileManager.DefaultManager.SetAttributes(attributes, directoryFile.FullName, out error);
            #endif

            var scheduler = options.CallbackScheduler;
            CapturedContext = new TaskFactory(scheduler);
            workExecutor    = new TaskFactory(new SingleTaskThreadpoolScheduler());
            Log.D(TAG, "New Manager uses a scheduler with a max concurrency level of {0}".Fmt(workExecutor.Scheduler.MaximumConcurrencyLevel));

            this.NetworkReachabilityManager = new NetworkReachabilityManager();

            SharedCookieStore = new CookieStore(this.directoryFile.FullName);
            StorageType       = "SQLite";
            Shared            = new SharedState();
        }
Пример #7
0
 public Manager(FilePath directoryFile, ManagerOptions options)
 {
     this.directoryFile = directoryFile;
     this.options       = (options != null) ? options : DefaultOptions;
     this.databases     = new Dictionary <string, Database>();
     this.replications  = new AList <Replication>();
     directoryFile.Mkdirs();
     if (!directoryFile.IsDirectory())
     {
         throw new IOException(string.Format("Unable to create directory for: %s", directoryFile
                                             ));
     }
     UpgradeOldDatabaseFiles(directoryFile);
     workExecutor = Executors.NewSingleThreadScheduledExecutor();
 }
Пример #8
0
 public Manager(Context context, ManagerOptions options)
 {
     Log.I(Database.Tag, "Starting Manager version: %s", Couchbase.Lite.Manager.Version
           );
     this.context       = context;
     this.directoryFile = context.GetFilesDir();
     this.options       = (options != null) ? options : DefaultOptions;
     this.databases     = new Dictionary <string, Database>();
     this.replications  = new AList <Replication>();
     directoryFile.Mkdirs();
     if (!directoryFile.IsDirectory())
     {
         throw new IOException(string.Format("Unable to create directory for: %s", directoryFile
                                             ));
     }
     UpgradeOldDatabaseFiles(directoryFile);
     workExecutor = Executors.NewSingleThreadScheduledExecutor();
 }
Пример #9
0
		//SERVER & DOCUMENTS
		/// <exception cref="System.Exception"></exception>
		public virtual void TestAPIManager()
		{
			Manager manager = this.manager;
			NUnit.Framework.Assert.IsTrue(manager != null);
			foreach (string dbName in manager.GetAllDatabaseNames())
			{
				Database db = manager.GetDatabase(dbName);
				Log.I(Tag, "Database '" + dbName + "':" + db.GetDocumentCount() + " documents");
			}
			ManagerOptions options = new ManagerOptions();
			options.SetReadOnly(true);
			Manager roManager = new Manager(new FilePath(manager.GetDirectory()), options);
			NUnit.Framework.Assert.IsTrue(roManager != null);
			Database db_1 = roManager.GetDatabase("foo");
			NUnit.Framework.Assert.IsNull(db_1);
			IList<string> dbNames = manager.GetAllDatabaseNames();
			NUnit.Framework.Assert.IsFalse(dbNames.Contains("foo"));
			NUnit.Framework.Assert.IsTrue(dbNames.Contains(DefaultTestDb));
		}
Пример #10
0
 static ManagerOptions()
 {
     Default = new ManagerOptions();
 }
Пример #11
0
 static ManagerOptions()
 {
     Default = new ManagerOptions();
 }
Пример #12
0
 public Manager(FilePath directoryFile, ManagerOptions options)
 {
     this.directoryFile = directoryFile;
     this.options = (options != null) ? options : DefaultOptions;
     this.databases = new Dictionary<string, Database>();
     this.replications = new AList<Replication>();
     directoryFile.Mkdirs();
     if (!directoryFile.IsDirectory())
     {
         throw new IOException(string.Format("Unable to create directory for: %s", directoryFile
             ));
     }
     UpgradeOldDatabaseFiles(directoryFile);
     workExecutor = Executors.NewSingleThreadScheduledExecutor();
 }
Пример #13
0
 static ManagerOptions()
 {
     SerializationEngine = new NewtonsoftJsonSerializer();
     Default             = new ManagerOptions();
 }
        public void TestReadOnlyDb()
        {
            CreateDocuments(database, 10);
            database.Close();

            var options = new ManagerOptions();
            options.ReadOnly = true;
            var readOnlyManager = new Manager(new DirectoryInfo(manager.Directory), options);
            database = readOnlyManager.GetExistingDatabase(database.Name);
            Assert.IsNotNull(database);
            var e = Assert.Throws<CouchbaseLiteException>(() => CreateDocuments(database, 1));
            Assert.AreEqual(StatusCode.Forbidden, e.Code);
            database.Close();

            var dbOptions = new DatabaseOptions();
            dbOptions.ReadOnly = true;
            database = manager.OpenDatabase(database.Name, dbOptions);
            Assert.IsNotNull(database);
            e = Assert.Throws<CouchbaseLiteException>(() => CreateDocuments(database, 1));
            Assert.AreEqual(StatusCode.Forbidden, e.Code);
            database.Close();

            dbOptions.ReadOnly = false;
            database = manager.OpenDatabase(database.Name, dbOptions);
            Assert.DoesNotThrow(() => CreateDocuments(database, 1));
        }
Пример #15
0
        /// <summary>
        /// Initializes a Manager that stores Databases in the given directory.
        /// </summary>
        /// <param name="directoryFile"><see cref="System.IO.DirectoryInfo"/> object for initializing the Manager object.</param>
        /// <param name="options">Option flags for initialization.</param>
        /// <exception cref="T:System.IO.DirectoryNotFoundException">Thrown when there is an error while accessing or creating the given directory.</exception>
        public Manager(DirectoryInfo directoryFile, ManagerOptions options)
        {
            if (directoryFile == null)
            {
                Log.To.Database.E(TAG, "directoryFile cannot be null in ctor, throwing...");
                throw new ArgumentNullException("directoryFile");
            }

            this.directoryFile = directoryFile;
            Options            = options ?? DefaultOptions;
            this.databases     = new Dictionary <string, Database>();
            this.replications  = new List <Replication>();
            Shared             = new SharedState();

            //create the directory, but don't fail if it already exists
            if (!directoryFile.Exists)
            {
                directoryFile.Create();
                directoryFile.Refresh();
                if (!directoryFile.Exists)
                {
                    throw Misc.CreateExceptionAndLog(Log.To.Database, StatusCode.InternalServerError, TAG,
                                                     "Unable to create directory {0}", directoryFile);
                }
            }

            UpgradeOldDatabaseFiles(directoryFile);

#if __IOS__
            Foundation.NSString protection;
            switch (options.FileProtection & Foundation.NSDataWritingOptions.FileProtectionMask)
            {
            case Foundation.NSDataWritingOptions.FileProtectionNone:
                protection = Foundation.NSFileManager.FileProtectionNone;
                break;

            case Foundation.NSDataWritingOptions.FileProtectionComplete:
                protection = Foundation.NSFileManager.FileProtectionComplete;
                break;

            case Foundation.NSDataWritingOptions.FileProtectionCompleteUntilFirstUserAuthentication:
                protection = Foundation.NSFileManager.FileProtectionCompleteUntilFirstUserAuthentication;
                break;

            default:
                protection = Foundation.NSFileManager.FileProtectionCompleteUnlessOpen;
                break;
            }

            var attributes = new Foundation.NSDictionary(Foundation.NSFileManager.FileProtectionKey, protection);
            Foundation.NSError error;
            Foundation.NSFileManager.DefaultManager.SetAttributes(attributes, directoryFile.FullName, out error);
#endif

            var scheduler = options.CallbackScheduler;
            CapturedContext = new TaskFactory(scheduler);
            Log.To.TaskScheduling.I(TAG, "Callbacks will be scheduled on {0}", scheduler);
            workExecutor = new TaskFactory(new SingleTaskThreadpoolScheduler());
            _networkReachabilityManager = new NetworkReachabilityManager();
            _networkReachabilityManager.StartListening();
            StorageType = "SQLite";
            Log.To.Database.I(TAG, "Created {0}", this);
        }
Пример #16
0
 public Manager(Context context, ManagerOptions options)
 {
     Log.I(Database.Tag, "Starting Manager version: %s", Couchbase.Lite.Manager.Version
         );
     this.context = context;
     this.directoryFile = context.GetFilesDir();
     this.options = (options != null) ? options : DefaultOptions;
     this.databases = new Dictionary<string, Database>();
     this.replications = new AList<Replication>();
     directoryFile.Mkdirs();
     if (!directoryFile.IsDirectory())
     {
         throw new IOException(string.Format("Unable to create directory for: %s", directoryFile
             ));
     }
     UpgradeOldDatabaseFiles(directoryFile);
     workExecutor = Executors.NewSingleThreadScheduledExecutor();
 }
 static ManagerOptions()
 {
     SerializationEngine = new NewtonsoftJsonSerializer();
     Default = new ManagerOptions();
 }