Exemplo n.º 1
0
        public Task <bool> Add(ComponentWithId component, string collectionName = "")
        {
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();

            if (string.IsNullOrEmpty(collectionName))
            {
                collectionName = component.GetType().Name;
            }
            DBSaveTask task = ComponentFactory.CreateWithId <DBSaveTask, ComponentWithId, string, TaskCompletionSource <bool> >(component.Id, component, collectionName, tcs);

            this.tasks[(int)((ulong)task.Id % taskCount)].Add(task);

            return(tcs.Task);
        }
Exemplo n.º 2
0
        public void AddToCache(ComponentWithId component, string collectionName = "")
        {
            if (string.IsNullOrEmpty(collectionName))
            {
                collectionName = component.GetType().Name;
            }
            Dictionary <long, ComponentWithId> collection;

            if (!this.cache.TryGetValue(collectionName, out collection))
            {
                collection = new Dictionary <long, ComponentWithId>();
                this.cache.Add(collectionName, collection);
            }
            collection[component.Id] = component;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 添加组件到缓存中
        /// </summary>
        /// <param name="component"></param>
        /// <param name="collectionName"></param>
        public void AddToCache(ComponentWithId component, string collectionName = "")
        {
            if (string.IsNullOrEmpty(collectionName))
            {
                collectionName = component.GetType().Name;
            }
            Dictionary <long, ComponentWithId> collection;               //  保存组件ID 和组件

            if (!this.cache.TryGetValue(collectionName, out collection)) //如果字典中没有这个类型
            {
                collection = new Dictionary <long, ComponentWithId>();
                this.cache.Add(collectionName, collection);   //组件类型 和 嵌套的字典( 保存组件ID 和组件)
            }
            collection[component.Id] = component;             //写入字典
        }