Пример #1
0
        /// <summary>
        /// 根据json查询条件查询
        /// </summary>
        /// <param name="self"></param>
        /// <param name="json"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static async ETTask <List <ComponentWithId> > Query <T>(this DBProxyComponent self, string json) where T : ComponentWithId
        {
            Session             session             = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress);
            DBQueryJsonResponse dbQueryJsonResponse = (DBQueryJsonResponse)await session.Call(new DBQueryJsonRequest { CollectionName = typeof(T).Name, Json = json });

            return(dbQueryJsonResponse.Components);
        }
Пример #2
0
        private static async ETVoid QueryInner <T>(this DBProxyComponent self, string json, string key) where T : ComponentWithId
        {
            try
            {
                Session             session             = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress);
                DBQueryJsonResponse dbQueryJsonResponse = (DBQueryJsonResponse)await session.Call(new DBQueryJsonRequest { CollectionName = typeof(T).Name, Json = json });

                var result = dbQueryJsonResponse.Components;

                object[] tcss = self.TcsQueue.GetAll(key);
                self.TcsQueue.Remove(key);

                foreach (ETTaskCompletionSource <List <ComponentWithId> > tcs in tcss)
                {
                    tcs.SetResult(result);
                }
            }
            catch (Exception e)
            {
                object[] tcss = self.TcsQueue.GetAll(key);
                self.TcsQueue.Remove(key);

                foreach (ETTaskCompletionSource <List <ComponentWithId> > tcs in tcss)
                {
                    tcs.SetException(e);
                }
            }
        }
Пример #3
0
        public static async Task <List <T> > QueryJson <T>(this DBProxyComponent self, string json) where T : ComponentWithId
        {
            List <T>            list                = new List <T>();
            Session             session             = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress);
            DBQueryJsonResponse dbQueryJsonResponse = (DBQueryJsonResponse)await session.Call(new DBQueryJsonRequest { CollectionName = typeof(T).Name, Json = json });

            foreach (ComponentWithId component in dbQueryJsonResponse.Components)
            {
                list.Add((T)component);
            }
            return(list);
        }
        /// <summary>
        /// 根据UId查询指定的日期的数据,查询数据库的字段是:UId,CreateTime
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="self"></param>
        /// <param name="userId"></param>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public static async Task <List <T> > QueryJsonCurrentDayByUid <T>(this DBProxyComponent self, long userId, DateTime dateTime) where T : ComponentWithId
        {
            List <T>            list                = new List <T>();
            string              json                = $"{{UId:{userId}, CreateTime:/^{dateTime.GetCurrentDay()}/}}";
            Session             session             = Game.Scene.GetComponent <NetInnerComponent>().Get(self.dbAddress);
            DBQueryJsonResponse dbQueryJsonResponse = (DBQueryJsonResponse)await session.Call(new DBQueryJsonRequest { CollectionName = typeof(T).Name, Json = json });

            foreach (ComponentWithId disposer in dbQueryJsonResponse.Components)
            {
                list.Add((T)disposer);
            }
            return(list);
        }