예제 #1
0
        public static void Start()
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                Navigator.RegisterArea(typeof(IsolationClient));

                WidgetsHelper.GetWidget += ctx => ctx.Entity is Entity && MixinDeclarations.IsDeclared(ctx.Entity.GetType(), typeof(IsolationMixin)) ?
                                           IsolationWidgetHelper.CreateWidget(ctx) : null;

                Navigator.AddSetting(new EntitySettings <IsolationEntity> {
                    PartialViewName = _ => ViewPrefix.FormatWith("Isolation")
                });

                Constructor.ClientManager.GlobalPreConstructors += ctx =>
                                                                   (!MixinDeclarations.IsDeclared(ctx.Type, typeof(IsolationMixin)) || IsolationEntity.Current != null) ? null :
                                                                   Module["getIsolation"](ClientConstructorManager.ExtraJsonParams, ctx.Prefix,
                                                                                          IsolationMessage.SelectAnIsolation.NiceToString(),
                                                                                          GetIsolationChooserOptions(ctx.Type));

                //Unnecessary with the filter
                Constructor.Manager.PreConstructors += ctx =>
                                                       !MixinDeclarations.IsDeclared(ctx.Type, typeof(IsolationMixin)) ? null :
                                                       IsolationEntity.Override(GetIsolation(ctx.Controller.ControllerContext));

                MapClient.GetColorProviders += GetMapColors;
            }
        }
예제 #2
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);
            }
        }
예제 #3
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, _) =>
                {
                    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 Start(Func <Lite <IsolationEntity>, ImageSource> getIsolationIcon)
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                Constructor.Manager.PreConstructors += Constructor_PreConstructors;

                WidgetPanel.GetWidgets += (e, c) => e is Entity && MixinDeclarations.IsDeclared(e.GetType(), typeof(IsolationMixin)) ?
                                          new IsolationWidget().Set(Common.OrderProperty, -1.0) : null;

                List <Lite <IsolationEntity> > isolations = null;

                Server.OnOperation += context =>
                {
                    var iso = IsolationEntity.CurrentThreadVariable.Value;

                    if (iso != null)
                    {
                        var msg = new MessageHeader <string>(iso.Item1?.Let(i => i.KeyLong()))
                                  .GetUntypedHeader("CurrentIsolation", "http://www.signumsoftware.com/Isolation");
                        context.OutgoingMessageHeaders.Add(msg);
                    }
                };

                GetIsolationIcon = getIsolationIcon;

                SelectIsolationInteractively = (owner, isValid) =>
                {
                    if (isolations == null)
                    {
                        isolations = Server.RetrieveAllLite <IsolationEntity>();
                    }


                    var isos = isValid == null ? isolations : isolations.Where(i => isValid(i) == null).ToList();

                    if (SelectorWindow.ShowDialog(isos, out Lite <IsolationEntity> result,
                                                  elementIcon: getIsolationIcon,
                                                  elementText: iso => getIsolationIcon(iso) == null ? iso.ToString() : null,
                                                  title: IsolationMessage.SelectAnIsolation.NiceToString(),
                                                  message: IsolationMessage.SelectAnIsolation.NiceToString(),
                                                  owner: owner))
                    {
                        return(result);
                    }

                    return(null);
                };

                Async.OnShowInAnotherThread += Async_OnShowInAnotherThread;

                Finder.Manager.TaskSearchWindow += Manager_TaskSearchWindow;
            }
        }
예제 #5
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);
        }
예제 #6
0
        static List <TreeInfo> FindNodesGeneric <T>(FindNodesRequest request)
            where T : TreeEntity
        {
            var qd            = QueryLogic.Queries.QueryDescription(typeof(T));
            var userFilters   = request.userFilters.Select(f => f.ToFilter(qd, false)).ToList();
            var frozenFilters = request.frozenFilters.Select(f => f.ToFilter(qd, false)).ToList();


            var frozenQuery = QueryLogic.Queries.GetEntities(new QueryEntitiesRequest {
                QueryName = typeof(T), Filters = frozenFilters, Orders = new List <Order>()
            })
                              .Select(a => (T)a.Entity);

            var filteredQuery = QueryLogic.Queries.GetEntities(new QueryEntitiesRequest {
                QueryName = typeof(T), Filters = userFilters.Concat(frozenFilters).ToList(), Orders = new List <Order>()
            })
                                .Select(a => (T)a.Entity);

            var disabledMixin = MixinDeclarations.IsDeclared(typeof(T), typeof(DisabledMixin));
            var list          = filteredQuery
                                .SelectMany(t => t.Ascendants())
                                .Select(t => new TreeInfo
            {
                route         = t.Route,
                name          = t.Name,
                lite          = t.ToLite(),
                level         = t.Level(),
                disabled      = disabledMixin && t.Mixin <DisabledMixin>().IsDisabled,
                childrenCount = frozenQuery.Count(a => (bool)(a.Route.GetAncestor(1) == t.Route)),
            }).ToList();

            var expandedChildren = request.expandedNodes.IsNullOrEmpty() ? new List <TreeInfo>() :
                                   frozenQuery
                                   .Where(t => request.expandedNodes.Contains(t.Parent().ToLite()))
                                   .SelectMany(t => t.Ascendants())
                                   .Select(t => new TreeInfo
            {
                route         = t.Route,
                name          = t.Name,
                lite          = t.ToLite(),
                level         = t.Level(),
                disabled      = disabledMixin && t.Mixin <DisabledMixin>().IsDisabled,
                childrenCount = frozenQuery.Count(a => (bool)(a.Route.GetAncestor(1) == t.Route)),
            }).ToList();

            return(list.Concat(expandedChildren).ToList());
        }
예제 #7
0
        static IDisposable Constructor_PreConstructors(ConstructorContext ctx)
        {
            if (MixinDeclarations.IsDeclared(ctx.Type, typeof(IsolationMixin)))
            {
                Lite <IsolationEntity> isolation = GetIsolation(ctx, IsValid.TryGetC(ctx.Type));

                if (isolation == null)
                {
                    ctx.CancelConstruction = true;
                    return(null);
                }
                ctx.Args.Add(isolation);

                return(IsolationEntity.Override(isolation));
            }

            return(null);
        }
예제 #8
0
    public static void Start(SchemaBuilder sb)
    {
        if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
        {
            sb.Include <IsolationEntity>()
            .WithSave(IsolationOperation.Save)
            .WithQuery(() => iso => new
            {
                Entity = iso,
                iso.Id,
                iso.Name
            });

            Schema.Current.AttachToUniqueFilter += entity =>
            {
                var type = entity.GetType();
                var hasIsolationMixin = MixinDeclarations.IsDeclared(type, typeof(IsolationMixin));

                return(hasIsolationMixin == false ? null :
                       e => e.Mixin <IsolationMixin>().Isolation.Is(entity.Mixin <IsolationMixin>().Isolation));
            };

            sb.Schema.EntityEventsGlobal.PreSaving += EntityEventsGlobal_PreSaving;
            sb.Schema.SchemaCompleted        += AssertIsolationStrategies;
            OperationLogic.SurroundOperation += OperationLogic_SurroundOperation;

            Isolations = sb.GlobalLazy(() => Database.RetrieveAllLite <IsolationEntity>(),
                                       new InvalidateWith(typeof(IsolationEntity)));

            ProcessLogic.ApplySession += ProcessLogic_ApplySession;

            Validator.OverridePropertyValidator((IsolationMixin m) => m.Isolation).StaticPropertyValidation += (mi, pi) =>
            {
                if (strategies.GetOrThrow(mi.MainEntity.GetType()) == IsolationStrategy.Isolated && mi.Isolation == null)
                {
                    return(ValidationMessage._0IsNotSet.NiceToString(pi.NiceName()));
                }

                return(null);
            };
            IsStarted = true;
        }
    }
예제 #9
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();
        }