Example #1
0
        public override async ETTask Run()
        {
            DBEXComponent dbComponent = Game.Scene.GetComponent <DBEXComponent>();

            try
            {
                await dbComponent.GetCollection <ComponentWithId>(this.CollectionName).InsertOneAsync(entity);

                this.Tcs.SetResult(entity);
            }
            catch (Exception e)
            {
                this.Tcs.SetException(new Exception($"inserts document failed on collection = {CollectionName} with id = {entity.Id}", e));
            }
        }
        public override async ETTask Run()
        {
            DBEXComponent dbComponent = Game.Scene.GetComponent <DBEXComponent>();

            try
            {
                // 执行查询数据库任务
                var filter = CreateFilter();
                IAsyncCursor <ComponentWithId> cursor = await dbComponent.GetCollection <ComponentWithId>(this.CollectionName).FindAsync(filter);

                List <ComponentWithId> component = await cursor.ToListAsync();

                this.Tcs.SetResult(component);
            }
            catch (Exception e)
            {
                this.Tcs.SetException(new Exception($"查询数据库异常! {CollectionName} {Id}", e));
            }
        }
Example #3
0
        public override async ETTask Run()
        {
            DBEXComponent dbComponent = Game.Scene.GetComponent <DBEXComponent>();

            try
            {
                var filter = CreateFilter();
                IAsyncCursor <ComponentWithId> cursor = await dbComponent.GetCollection <ComponentWithId>(this.CollectionName).FindAsync(filter);

                ComponentWithId component = await cursor.FirstOrDefaultAsync();

                this.Tcs.SetResult(component);
            }
            catch (Exception e)
            {
                this.Tcs.SetException(new Exception($"find one failed on collection = {CollectionName} with" +
                                                    $" {GetCondition()}", e));
            }
        }