public static ETTask <T> Create <T>(this DBComponent db, string collectionName, T entity) where T : ComponentWithId
        {
            ETTaskCompletionSource <T> tcs = new ETTaskCompletionSource <T>();
            DBCreateTask task = ComponentFactory.Create <DBCreateTask, string, T, ETTaskCompletionSource <T> >
                                    (collectionName, entity, tcs);

            db.tasks[(int)((ulong)task.Id % DBComponent.taskCount)].Add(task);
            return(tcs.Task);
        }
예제 #2
0
        //public static ETTask<List<T>> FindAllByIndex<T>(this DBComponent db, string collectionName, string indexName, T entity) where T : ComponentWithId
        //{
        //    ETTaskCompletionSource<List<T>> tcs = new ETTaskCompletionSource<List<T>>();
        //    var parameters = DBHelper.GetParameterList(typeof(T), indexName, entity);
        //    DBQueryAllWithIndexTask<T> task = ComponentFactory.Create<DBQueryAllWithIndexTask<T>, string, List<Tuple<PropertyInfo, object>>, ETTaskCompletionSource<List<T>>>
        //        (collectionName, parameters, tcs);
        //    db.tasks[(int)((ulong)task.Id % DBComponent.taskCount)].Add(task);
        //    return tcs.Task;
        //}

        public async ETTask <T> Create <T>(T entity, string collectionName = default) where T : ComponentWithId
        {
            if (string.IsNullOrEmpty(collectionName))
            {
                collectionName = typeof(T).Name.ToLower();
            }
            ETTaskCompletionSource <ComponentWithId> tcs = new ETTaskCompletionSource <ComponentWithId>();
            DBCreateTask task = ComponentFactory.Create <DBCreateTask, string, ComponentWithId, ETTaskCompletionSource <ComponentWithId> >
                                    (collectionName, entity, tcs);

            this.tasks[(int)((ulong)task.Id % taskCount)].Add(task);
            return((T)await tcs.Task);
        }
예제 #3
0
 public override void Awake(DBCreateTask self, string collectionName, ComponentWithId entity, ETTaskCompletionSource <ComponentWithId> tcs)
 {
     self.CollectionName = collectionName;
     self.Tcs            = tcs;
     self.entity         = entity;
 }