コード例 #1
0
        public void SaveEntities <TEntity>(IEnumerable <TEntity> entities)
        {
            using (LiteDatabase db = new LiteDatabase(_appSettings.LightDbConnection))
            {
                ILiteCollection <TEntity> col = db.GetCollection <TEntity>(typeof(TEntity).Name);

                col.Upsert(entities);
            }
        }
コード例 #2
0
        public List <TEntity> GetEntities <TEntity>()
        {
            using (LiteDatabase db = new LiteDatabase(_appSettings.LightDbConnection))
            {
                ILiteCollection <TEntity> col = db.GetCollection <TEntity>(typeof(TEntity).Name);

                return(col.Query().ToList());
            }
        }
コード例 #3
0
        public LiteDbCollection(ILiteDatabase database)
        {
            if (database == null)
            {
                throw new ArgumentNullException(nameof(database));
            }

            _collection = database.GetCollection <TEntity>(typeof(TEntity).Name);
        }
コード例 #4
0
 public ScheduledEvent[] FindGuildEvents(
     ulong guildId, 
     string message = null, 
     EventState? state = null, 
     int limit = 0)
 {
     ILiteCollection<ScheduledEvent> collection = EnsureEventCollection(guildId);
     return FindInternal(collection, message, state, limit);            
 }
コード例 #5
0
        public void GlobalCleanupNormal()
        {
            _fileMetaNormalCollection = null;

            _databaseInstanceNormal?.Checkpoint();
            _databaseInstanceNormal?.Dispose();
            _databaseInstanceNormal = null;

            File.Delete(DatabasePath);
        }
コード例 #6
0
 public RelationshipRepositoryTest()
 {
     this.liteDb                 = new LiteRepository(new MemoryStream());
     this.eventSource            = this.mocks.Create <IChangedMessageBus <IRelationship> >();
     this.entityRepository       = new EntityRepository(this.liteDb, this.mocks.Create <IChangedMessageBus <IEntity> >(MockBehavior.Loose).Object);
     this.tagRepository          = new TagRepository(this.liteDb, this.mocks.Create <IChangedMessageBus <ITag> >(MockBehavior.Loose).Object);
     this.categoryRepository     = new CategoryRepository(this.liteDb);
     this.relationshipRepository = new RelationshipRepository(this.liteDb, this.eventSource.Object);
     this.relationships          = this.liteDb.Database.GetCollection("relationships");
 }
コード例 #7
0
ファイル: LiteDbStockRepository.cs プロジェクト: danh955/z001
        /// <summary>
        /// Initializes a new instance of the <see cref="LiteDbStockRepository"/> class.
        /// </summary>
        /// <param name="db">Lite database.</param>
        public LiteDbStockRepository(LiteDatabase db)
        {
            if (db == null)
            {
                throw new NoNullAllowedException();
            }

            this.stocks = db.GetCollection <Stock>("Stock");
            this.stocks.EnsureIndex(s => s.Symbol, unique: true);
        }
コード例 #8
0
        /// <summary>
        /// Index Question
        /// </summary>
        /// <param name="QuestionCollection">Question Collection</param>
        private void IndexQuestion(ILiteCollection <Question> QuestionCollection)
        {
            // Index on QuestionId
            QuestionCollection.EnsureIndex(x => x.QuestionId);



            // Index on QuestionNumber
            // QuestionCollection.EnsureIndex(x => x.QuestionNumber);
        }
コード例 #9
0
 protected virtual ILiteCollection <T> GetCollection(bool refresh = false)
 {
     if (this.collection == null || refresh)
     {
         this.collection = this.GetDatabase(refresh).GetCollection <T>();
         OnCollectionCreated(this.collection);
         OnCollectionCreated();
     }
     return(this.collection);
 }
コード例 #10
0
        /// <summary>
        /// パッケージ情報を更新します。
        /// </summary>
        /// <param name="new_pkginfo">新しいパッケージ情報</param>
        /// <returns></returns>
        public bool UpdatePackageInfo(PackageInfo new_pkginfo)
        {
            using (LiteDatabase db = new LiteDatabase(@"./database/packages.db"))
            {
                ILiteCollection <PackageInfo> pkginfo_col = db.GetCollection <PackageInfo>("package_info");
                pkginfo_col.Update(new_pkginfo);
            }

            return(true);
        }
コード例 #11
0
        /// <summary>
        /// 新しいパッケージ情報を登録します。
        /// </summary>
        /// <param name="package_info">新しいパッケージ情報</param>
        /// <returns></returns>
        public bool RegisterPackageInfo(PackageInfo package_info)
        {
            using (LiteDatabase db = new LiteDatabase(@"./database/packages.db"))
            {
                ILiteCollection <PackageInfo> pkginfo_col = db.GetCollection <PackageInfo>("package_info");
                pkginfo_col.Insert(package_info);
            }

            return(true);
        }
コード例 #12
0
        public void GlobalSetupCompoundIndexVariant()
        {
            DatabaseInstance    = new LiteDatabase(ConnectionString());
            _fileMetaCollection = DatabaseInstance.GetCollection <FileMetaBase>();
            _fileMetaCollection.EnsureIndex(COMPOUND_INDEX_NAME, $"$.{nameof(FileMetaBase.IsFavorite)};$.{nameof(FileMetaBase.ShouldBeShown)}");

            _fileMetaCollection.Insert(FileMetaGenerator <FileMetaBase> .GenerateList(DatasetSize));           // executed once per each N value

            DatabaseInstance.Checkpoint();
        }
コード例 #13
0
        public void GlobalIgnorePropertySetup()
        {
            File.Delete(DatabasePath);

            DatabaseInstance             = new LiteDatabase(ConnectionString());
            _fileMetaExclusionCollection = DatabaseInstance.GetCollection <FileMetaWithExclusion>();
            _fileMetaExclusionCollection.EnsureIndex(fileMeta => fileMeta.ShouldBeShown);

            _baseDataWithBsonIgnore = FileMetaGenerator <FileMetaWithExclusion> .GenerateList(DatasetSize);           // executed once per each N value
        }
コード例 #14
0
        public void GlobalSetup()
        {
            File.Delete(DatabasePath);

            DatabaseInstance    = new LiteDatabase(ConnectionString());
            _fileMetaCollection = DatabaseInstance.GetCollection <FileMetaBase>();

            _fileMetaCollection.Insert(FileMetaGenerator <FileMetaBase> .GenerateList(DatasetSize));           // executed once per each N value
            DatabaseInstance.Checkpoint();
        }
コード例 #15
0
        private MessageBoxContext()
        {
            var folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Shard");

            Directory.CreateDirectory(folder);
            db       = new LiteDatabase(Path.Combine(folder, "tracking.db"));
            messages = db.GetCollection <TrackedMessage>("trackedMessages");
            logs     = db.GetCollection <LogEntry>("logEntries");
            storage  = db.GetStorage <Guid>();
        }
コード例 #16
0
ファイル: DatabaseService.cs プロジェクト: zeppaman/jSOS
        public DatabaseService(ConfigService configService)
        {
            this.configService = configService;

            db = new LiteDatabase(this.configService.GetAppPath("data.db"));
            // Get customer collection
            this.PermissionCollection    = db.GetCollection <Permission>("Permission");
            this.AppPermissionCollection = db.GetCollection <AppPermission>("AppPermission");
            this.SettingsCollection      = db.GetCollection <Settings>("Settings");
        }
コード例 #17
0
        public static Account GetAccount(string accountId, bool showTransaction = false)
        {
            ILiteCollection <Account> accounts = DataContext.accounts;

            if (showTransaction)
            {
                accounts.Include(x => x.Transactions);
            }
            return(accounts.FindById(accountId));
        }
コード例 #18
0
 public void Deactivate()
 {
     SisbaseBot.Instance.Client.MessageReactionRemoved -= ReactionRemoved;
     SisbaseBot.Instance.Client.MessageReactionAdded   -= ReactionAdded;
     Database.Dispose();
     categoryCache = null;
     Name          = null;
     Status        = false;
     Timeout       = TimeSpan.Zero;
 }
コード例 #19
0
ファイル: GroupBy_Tests.cs プロジェクト: zamis/LiteDB
        public GroupBy_Tests()
        {
            local = DataGen.Person(1, 1000).ToArray();

            db         = new LiteDatabase(new MemoryStream());
            collection = db.GetCollection <Person>();

            collection.Insert(local);
            collection.EnsureIndex(x => x.Age);
        }
コード例 #20
0
 public SeriesDb()
 {
     if (!Debugger.IsAttached)
     {
         Directory.CreateDirectory(Path.Combine(PATH, APP_NAME));
     }
     db         = new LiteDatabase(Debugger.IsAttached ? FILE : Path.Combine(PATH, APP_NAME, FILE));
     collection = db.GetCollection <Series>(COLL_SERIES);
     collection.EnsureIndex(c => c.Name);
 }
コード例 #21
0
 public AnnoStorage()
 {
     if (db == null)
     {
         db  = AnnoDataBase.Db;
         col = db.GetCollection <AnnoData>();
         col.EnsureIndex(x => x.Id);
         col.EnsureIndex(x => x.App);
     }
 }
コード例 #22
0
 public TimingWriter(IMetaDatabaseHandler databaseHandler)
 {
     _spawnCollection      = databaseHandler.GetCollection <RunMeta <int> >("MetaSpawnTiming");
     _netherCollection     = databaseHandler.GetCollection <RunMeta <int> >("MetaNetherTiming");
     _fortressCollection   = databaseHandler.GetCollection <RunMeta <int> >("MetaFortressTiming");
     _blazeCollection      = databaseHandler.GetCollection <RunMeta <int> >("MetaBlazeTiming");
     _searchCollection     = databaseHandler.GetCollection <RunMeta <int> >("MetaSearchTiming");
     _strongholdCollection = databaseHandler.GetCollection <RunMeta <int> >("MetaStrongholdTiming");
     _endCollection        = databaseHandler.GetCollection <RunMeta <int> >("MetaEndTiming");
 }
コード例 #23
0
        public LayerService(IEnumerable <ILayer> layers, string targetRoot)
        {
            this.layers = layers.ToDictionary(layer => layer.Id);
            mapper      = new PathMapper("", targetRoot);
            var rand = new Random();

            database   = new LiteDatabase($"{DateTime.Now.Ticks}.{rand.Next()}.db");
            collection = database.GetCollection <EntryDataDto>("entry");
            collection.DeleteAll();
        }
コード例 #24
0
ファイル: KvStorage.cs プロジェクト: zjftuzi/Anno.Core
 public KvStorage()
 {
     if (db == null)
     {
         db  = AnnoDataBase.Db;
         col = db.GetCollection <AnnoKV>();
         col.EnsureIndex(x => x.Id);
         col.EnsureIndex(x => x.Value);
     }
 }
コード例 #25
0
 /// <summary>Get an item from the referenced collection.</summary>
 T ICollectionRef <T> .Get(Guid id)
 {
     try
     {
         using LiteDatabase _liteDB = new LiteDatabase(RefConfig.Location);
         ILiteCollection <T> _collection = _liteDB.GetCollection <T>(RefConfig.Collection);
         return(_collection.FindById(id));
     }
     catch (Exception ex)
     { throw ex; }
 }
コード例 #26
0
        public void InitCollections()
        {
            accountsCollection = database.GetCollection <AccountInfoLiteDb>("accounts");
            accountsCollection.EnsureIndex(a => a.Id, true);

            resetCodesCollection = database.GetCollection <PasswordResetDataLiteDb>("resetCodes");
            resetCodesCollection.EnsureIndex(a => a.Email, true);

            emailConfirmationCodesCollection = database.GetCollection <EmailConfirmationDataLiteDb>("emailConfirmationCodes");
            emailConfirmationCodesCollection.EnsureIndex(a => a.Email, true);
        }
コード例 #27
0
        public DatabaseMappingSource(YarnVersion yarnVersion, ILiteCollection <Mapping> classes, ILiteCollection <Mapping> fields, ILiteCollection <Mapping> methods)
        {
            YarnVersion = yarnVersion;
            _classes    = classes;
            _fields     = fields;
            _methods    = methods;

            _classes.EnsureIndex(mapping => mapping.IntermediaryName);
            _fields.EnsureIndex(mapping => mapping.IntermediaryName);
            _methods.EnsureIndex(mapping => mapping.IntermediaryName);
        }
コード例 #28
0
 /// <summary>
 /// Arrange db, controller, and collection
 /// </summary>
 public void SetUp()
 {
     context     = new LiteDBContext();
     genericRepo = new GenericRepo <TextureModel>(context);
     textures    = context.litedb.GetCollection <TextureModel>("textures");
     if (textures.Count() == 0)
     {
         context.LoadDefaultTextureDirectoryIntoDatabase(textures);
     }
     repo = new TextureRepo(context, genericRepo);
 }
コード例 #29
0
        public void GlobalSetup()
        {
            File.Delete(DatabasePath);

            DatabaseInstance    = new LiteDatabase(ConnectionString());
            _fileMetaCollection = DatabaseInstance.GetCollection <FileMetaBase>();
            _fileMetaCollection.EnsureIndex(file => file.IsFavorite);
            _fileMetaCollection.EnsureIndex(file => file.ShouldBeShown);

            _data = FileMetaGenerator <FileMetaBase> .GenerateList(DatasetSize);
        }
コード例 #30
0
        public ObjectId SaveWithoutUpdate(ConfigEntity config)
        {
            ILiteCollection <ConfigEntity> collection = db.GetCollection <ConfigEntity>();
            ObjectId result = null;

            if (!collection.Exists(x => x.ConfigName.Equals(config.ConfigName)))
            {
                result = collection.Insert(config);
            }
            return(result);
        }