Ejemplo n.º 1
0
            public override TreeNode Clone(TreeEntityBase newTree, TreeNode newParentNode)
            {
                FakeTreeNode clone = new FakeTreeNode();

                this.CopyTo(clone, newTree, newParentNode);
                return(clone);
            }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加子节点
        /// </summary>
        /// <param name="parentId">父节点ID</param>
        /// <param name="propertyValues">待更新属性值队列</param>
        /// <returns>子节点ID</returns>
        protected virtual long AddChildNode(long parentId, IDictionary <string, object> propertyValues)
        {
            long result = Database.Sequence.Value;

            GetNode(parentId).AddChild(() => TreeEntityBase <TKernel> .New(Database, result, propertyValues));
            return(result);
        }
Ejemplo n.º 3
0
        Task <long> ITreeEntityGrain <TKernel> .AddChildNode(long parentId, params NameValue[] propertyValues)
        {
            long result = Database.Sequence.Value;

            GetNode(parentId).AddChild(() => TreeEntityBase <TKernel> .New(Database, result, propertyValues));
            return(Task.FromResult(result));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 添加子节点
        /// </summary>
        /// <param name="parentId">父节点ID</param>
        /// <param name="propertyValues">待更新属性值队列</param>
        /// <returns>子节点ID</returns>
        protected virtual long AddChildNode(long parentId, params NameValue[] propertyValues)
        {
            long result = Database.Sequence.Value;

            GetNode(parentId).AddChild(() => TreeEntityBase <TKernel> .New(Database, result, propertyValues));
            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 新增或更新根实体对象
        /// </summary>
        /// <param name="propertyValues">待更新属性值队列</param>
        /// <param name="throwIfFound">如果为 true, 则发现已存在时引发 InvalidOperationException,否则覆盖更新它</param>
        /// <param name="throwIfNotOwn">如果为 true, 则发现制单人不是自己时引发 InvalidOperationException,否则覆盖更新它</param>
        protected override Task PutKernel(IDictionary <string, object> propertyValues, bool throwIfFound = false, bool?throwIfNotOwn = null)
        {
            if (Kernel != null)
            {
                if (throwIfFound && !throwIfNotOwn.HasValue ||
                    throwIfNotOwn.HasValue && throwIfNotOwn.Value && (long)Kernel.GetValue("Originator") != User.Identity.Id)
                {
                    throw new System.ComponentModel.DataAnnotations.ValidationException("不允许重复新增!");
                }
                else
                {
                    OnKernelOperating(ExecuteAction.Update, out object tag);
                    Kernel.UpdateSelf(propertyValues);
                    OnKernelOperated(ExecuteAction.Update, tag);
                }
            }
            else if (this is IGrainWithIntegerKey)
            {
                OnKernelOperating(ExecuteAction.Insert, out object tag);
                TreeEntityBase <TKernel> .NewRoot(Database, propertyValues).InsertSelf(PrimaryKeyLong);

                OnKernelOperated(ExecuteAction.Insert, tag);
            }
            else
            {
                OnKernelOperating(ExecuteAction.Insert, out object tag);
                TreeEntityBase <TKernel> .NewRoot(Database, propertyValues).InsertSelf();

                OnKernelOperated(ExecuteAction.Insert, tag);
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 6
0
 Task <int> IEntityGrain <TKernel> .PatchKernel(params NameValue[] propertyValues)
 {
     return(Task.FromResult(Kernel != null
         ? Kernel.UpdateSelf(propertyValues)
         : this is IGrainWithIntegerKey
             ? TreeEntityBase <TKernel> .NewRoot(Database, Id, propertyValues).InsertSelf()
             : TreeEntityBase <TKernel> .NewRoot(Database, propertyValues).InsertSelf()));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 获取根实体对象
 /// </summary>
 /// <param name="autoNew">不存在则新增</param>
 /// <returns>根实体对象</returns>
 protected override Task <TKernel> FetchKernel(bool autoNew = false)
 {
     return(Task.FromResult(Kernel == null && autoNew
         ? this is IGrainWithIntegerKey
             ? TreeEntityBase <TKernel> .NewRoot(Database, NameValue.Set <TKernel>(p => p.PrimaryKeyLong, PrimaryKeyLong))
             : TreeEntityBase <TKernel> .NewRoot(Database)
         : Kernel));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 更新根实体对象(如不存在则新增)
 /// </summary>
 /// <param name="propertyValues">待更新属性值队列</param>
 protected override void PatchKernel(IDictionary <string, object> propertyValues)
 {
     if (Kernel != null)
     {
         Kernel.UpdateSelf(propertyValues);
     }
     else if (this is IGrainWithIntegerKey || this is IGrainWithIntegerCompoundKey)
     {
         TreeEntityBase <TKernel> .NewRoot(Database, Id, propertyValues).InsertSelf();
     }
     else
     {
         TreeEntityBase <TKernel> .NewRoot(Database, propertyValues).InsertSelf();
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Calculates the mean of the tree size of <see cref="TreeEntityBase"/> objects contained by the
        /// <paramref name="population"/>.
        /// </summary>
        /// <param name="population"><see cref="Population"/> from which to derive the metric.</param>
        /// <returns>Mean of the tree size of the <see cref="TreeEntityBase"/> objects.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="population"/> is null.</exception>
        public override object GetResultValue(Population population)
        {
            if (population == null)
            {
                throw new ArgumentNullException(nameof(population));
            }

            int sum = 0;

            for (int i = 0; i < population.Entities.Count; i++)
            {
                TreeEntityBase tree = (TreeEntityBase)population.Entities[i];
                sum += tree.GetSize();
            }

            return((double)sum / population.Entities.Count);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 添加子节点
        /// </summary>
        /// <param name="parentId">父节点ID</param>
        /// <param name="propertyValues">待更新属性值队列</param>
        /// <returns>子节点ID</returns>
        protected virtual long AddChildNode(long parentId, IDictionary <string, object> propertyValues)
        {
            TKernel childNode = GetNode(parentId).AddChild(() => TreeEntityBase <TKernel> .New(Database, propertyValues));

            return(childNode.Id);
        }