public LiteDB_Test(int count, string password, LiteDB.FileOptions options) { _count = count; _filename = "dblite-" + Guid.NewGuid().ToString("n") + ".db"; var disk = new FileDiskService(_filename, options); _db = new LiteEngine(disk, password); }
static void Init() { if (!triedToInit) { triedToInit = true; var fileName = GetCacheFileName(); if (!string.IsNullOrEmpty(fileName)) { var folder = Path.GetDirectoryName(fileName); try { //!!!!Android readonly? bool readOnly = SystemSettings.CurrentPlatform == SystemSettings.Platform.UWP || SystemSettings.CurrentPlatform == SystemSettings.Platform.Android; bool skip = false; if (readOnly && !File.Exists(fileName)) { skip = true; } if (!skip) { if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } var options = new LiteDB.FileOptions(); //in UWP we do not have write access to the application folder if (readOnly) { options.FileMode = LiteDB.FileMode.ReadOnly; } database = new LiteDatabase(new FileDiskService(fileName, options)); //!!!! //in UWP we do not have write access to the application folder //even if we set FileMode = LiteDB.FileMode.ReadOnly, EnsureIndex() method writes to disk. it is a LiteDB issue? if (!readOnly) { var collection = database.GetCollection <DatabaseItem>("items"); collection.EnsureIndex("KeyIndex"); } } } catch (Exception e) { Log.Warning(e.Message); return; } } } }
public LiteDB_Test2(int count, string password, LiteDB.FileOptions options) { _count = count; _filename = "dblite-" + Guid.NewGuid().ToString("n") + ".db"; var disk = new FileDiskService(_filename, options); _db = new LiteDatabase(disk); _collection = _db.GetCollection <TestDoc>(); }
public FileDiskService(string filename, FileOptions options) { // simple validations if (filename.IsNullOrWhiteSpace()) throw new ArgumentNullException("filename"); if (options.InitialSize > options.LimitSize) throw new ArgumentException("limit size less than initial size"); // setting class variables _filename = filename; _options = options; // journal filename _journalFilename = FileHelper.GetTempFile(_filename, "-journal", false); }
public IDiskService Disk(FileOptions options) { return(new FileDiskService(Filename, options)); }