コード例 #1
0
        public static void TreeEntityMove <T>(T t, MoveTreeModel model) where T : TreeEntity, new()
        {
            TreeLogic.FixRouteAndNames(t, model);
            t.Save();

            if (MixinDeclarations.IsDeclared(typeof(T), typeof(DisabledMixin)) && model.NewParent != null && model.NewParent.InDB(e => e.Mixin <DisabledMixin>().IsDisabled) && !t.Mixin <DisabledMixin>().IsDisabled)
            {
                t.Execute(DisableOperation.Disable);
            }
        }
コード例 #2
0
ファイル: TreeLogic.cs プロジェクト: sschoensee/extensions
        public static void RegisterOperations <T>(Func <T, MoveTreeModel, T>?copy) where T : TreeEntity, new()
        {
            Graph <T> .Construct.Untyped(TreeOperation.CreateRoot).Do(c =>
            {
                c.Construct = (_) => new T
                {
                    ParentOrSibling = null,
                    Level           = 1,
                    IsSibling       = false
                };
                c.Register();
            });

            Graph <T> .ConstructFrom <T> .Untyped(TreeOperation.CreateChild).Do(c =>
            {
                c.Construct = (t, _) => new T
                {
                    ParentOrSibling = t.ToLite(),
                    Level           = (short)(t.Level !+1),
                    IsSibling       = false
                                      //
                };
                c.Register();
            });

            Graph <T> .ConstructFrom <T> .Untyped(TreeOperation.CreateNextSibling).Do(c =>
            {
                c.Construct = (t, _) => new T
                {
                    ParentOrSibling = t.ToLite(),
                    Level           = t.Level,
                    IsSibling       = true
                                      //
                };
                c.Register();
            });

            new Graph <T> .Execute(TreeOperation.Save)
            {
                CanBeNew      = true,
                CanBeModified = true,
                Execute       = (t, _) =>
                {
                    if (t.IsNew)
                    {
                        t.Route = CalculateRoute(t);
                        if (MixinDeclarations.IsDeclared(typeof(T), typeof(DisabledMixin)) && t.ParentOrSibling != null)
                        {
                            t.Mixin <DisabledMixin>().IsDisabled = t.Parent() !.Mixin <DisabledMixin>().IsDisabled;
                        }
                    }

                    TreeLogic.FixName(t);
                }
            }
コード例 #3
0
        public static void TreeEntitySave <T>(T t) where T : TreeEntity, new()
        {
            if (t.IsNew)
            {
                t.Route = CalculateRoute(t);
                if (MixinDeclarations.IsDeclared(typeof(T), typeof(DisabledMixin)) && t.ParentOrSibling != null)
                {
                    t.Mixin <DisabledMixin>().IsDisabled = t.Parent() !.Mixin <DisabledMixin>().IsDisabled;
                }
            }

            TreeLogic.FixName(t);
        }
コード例 #4
0
        public static void RegisterOperations <T>(Func <T, MoveTreeModel, T>?copy) where T : TreeEntity, new()
        {
            Graph <T> .Construct.Untyped(TreeOperation.CreateRoot).Do(c =>
            {
                c.Construct = (_) => new T
                {
                    ParentOrSibling = null,
                    Level           = 1,
                    IsSibling       = false
                };
                c.Register();
            });

            Graph <T> .ConstructFrom <T> .Untyped(TreeOperation.CreateChild).Do(c =>
            {
                c.Construct = (t, _) => new T
                {
                    ParentOrSibling = t.ToLite(),
                    Level           = (short)(t.Level !+1),
                    IsSibling       = false
                                      //
                };
                c.Register();
            });

            Graph <T> .ConstructFrom <T> .Untyped(TreeOperation.CreateNextSibling).Do(c =>
            {
                c.Construct = (t, _) => new T
                {
                    ParentOrSibling = t.ToLite(),
                    Level           = t.Level,
                    IsSibling       = true
                                      //
                };
                c.Register();
            });

            new Graph <T> .Execute(TreeOperation.Save)
            {
                CanBeNew      = true,
                CanBeModified = true,
                Execute       = (t, _) =>
                {
                    TreeEntitySave(t);
                }
            }

            .Register();

            new Graph <T> .Execute(TreeOperation.Move)
            {
                Execute = (t, args) =>
                {
                    var model = args.GetArg <MoveTreeModel>();

                    TreeEntityMove(t, model);
                }
            }

            .Register();

            if (copy != null)
            {
                Graph <T> .ConstructFrom <T> .Untyped(TreeOperation.Copy).Do(c =>
                {
                    c.Construct = (t, args) =>
                    {
                        var model    = args.GetArg <MoveTreeModel>();
                        var newRoute = GetNewPosition <T>(model, t);

                        var descendants = t.Descendants().OrderBy(a => a.Route).ToList();

                        var hasDisabledMixin = MixinDeclarations.IsDeclared(typeof(T), typeof(DisabledMixin));
                        var isParentDisabled = hasDisabledMixin && model.NewParent != null && model.NewParent.InDB(e => e.Mixin <DisabledMixin>().IsDisabled);

                        var list = descendants.Select(oldNode =>
                        {
                            var newNode = copy !(oldNode, model);
                            if (hasDisabledMixin)
                            {
                                newNode.Mixin <DisabledMixin>().IsDisabled = oldNode.Mixin <DisabledMixin>().IsDisabled || isParentDisabled;
                            }

                            newNode.ParentOrSibling = model.NewParent;
                            newNode.Route           = oldNode.Route.GetReparentedValue(t.Route, newRoute);
                            newNode.SetFullName(newNode.Name);
                            return(newNode);
                        }).ToList();

                        list.SaveList();

                        foreach (T h in list)
                        {
                            CalculateFullName(h);
                            h.Save();
                        }

                        return(list.First());
                    };
                }).Register();
            }

            new Graph <T> .Delete(TreeOperation.Delete)
            {
                Delete = (f, args) =>
                {
                    TreeLogic.RemoveDescendants(f);
                }
            }

            .Register();
        }