public async Task SetConfig(ConfigurationModel configurationModel)
        {
            await FileOperations.CheckOrCreateDirectory(_path);

            using (var stream = new StreamWriter(_path + "/config.conf"))
            {
                await stream.WriteAsync(JsonConvert.SerializeObject(configurationModel));
            }
        }
예제 #2
0
        public static Task <List <string> > GetDatabases()
        {
            var path = $"{AppDomain.CurrentDomain.BaseDirectory}data/";

            FileOperations.CheckOrCreateDirectory(path);
            var dbs    = Directory.GetDirectories(path).ToList();
            var result = dbs.Select(db => db.Replace('\\', '/').Split("/").LastOrDefault()).ToList();

            return(Task.FromResult(result));
        }
        public DocumentDatabase(IndexModel indexModel)
        {
            var path = $"{AppDomain.CurrentDomain.BaseDirectory}data/{indexModel.DatabaseName}";

            FileOperations.CheckOrCreateDirectory(path);
            path         += $"/{indexModel.IndexName}";
            _dbFileStream = new FileStream(path + ".col", FileMode.OpenOrCreate, FileAccess.ReadWrite,
                                           FileShare.None, 4096);
            _indexFileStream = new FileStream(path + ".pidx", FileMode.OpenOrCreate, FileAccess.ReadWrite,
                                              FileShare.None, 4096);
            _secondaryFileStream = new FileStream(path + ".sidx", FileMode.OpenOrCreate, FileAccess.ReadWrite,
                                                  FileShare.None, 4096);

            // Construct the RecordStorage that use to store main cow data
            _records = new RecordStorage(new BlockStorage(_dbFileStream, 4096));

            // Construct the primary and secondary indexes
            _index = new Tree <Guid, uint>(
                new TreeDiskNodeManager <Guid, uint>(
                    new GuidSerializer(),
                    new TreeUIntSerializer(),
                    new RecordStorage(new BlockStorage(_indexFileStream, 4096))
                    )
                );

            _secondaryIndex = new Tree <string, Dictionary <string, Guid> >(
                new TreeDiskNodeManager <string, Dictionary <string, Guid> >(
                    new StringSerializer(),
                    new DictSerializer(),
                    new RecordStorage(
                        new BlockStorage(_secondaryFileStream, 4096)
                        )
                    ),
                true);

            _documentSerializer = new DocumentSerializer();
            _indexingOperations = new IndexingOperations();
            IndexModel          = indexModel;
        }