예제 #1
0
        Windows.ActionDescriptor AddAction(Windows.WindowDescriptor window, String actionKey, String actionName, Log.LogicTransaction ltr)
        {
            var action = window.ChildActions.FirstOrDefault(act => act.ActionKey.Equals(actionKey, StringComparison.OrdinalIgnoreCase));

            if (action == null)
            {
                window.ChildActions.Add(action = new Windows.ActionDescriptor(this, actionKey, window)
                {
                    ActionName = actionName
                });
                if (ltr != null)
                {
                    ltr.AddCreatedObject(action, this);
                }
            }
            else if (!String.Equals(action.ActionName, actionName, StringComparison.Ordinal))
            {
                if (ltr != null)
                {
                    ltr.AddUpdatedObjectBefore(action, this);
                }
                action.ActionName = actionName;
                if (ltr != null)
                {
                    ltr.AddUpatedObjectAfter(action, this);
                }
            }
            return(action);
        }
예제 #2
0
        protected Windows.WindowDescriptor AddWindow(String windowId, String windowName, Windows.WindowDescriptor parentWindow, IEnumerable <Tuple <String, String> > actions, Log.LogicTransaction ltr)
        {
            var window = this.Windows.FirstOrDefault(wnd => wnd.Iid.Equals(windowId, StringComparison.OrdinalIgnoreCase));

            if (window == null)
            {
                window = this.Windows.Add(new Windows.WindowDescriptor(this, windowId, windowName)
                {
                    ChildActions = new List <Windows.ActionDescriptor>(),
                    ChildWindows = new List <Windows.WindowDescriptor>()
                });
                if (ltr != null)
                {
                    ltr.AddCreatedObject(window, this);
                }
            }
            else if (!window.Name.Equals(windowName, StringComparison.Ordinal) || window.ParentWindow != parentWindow)
            {
                if (ltr != null)
                {
                    ltr.AddUpdatedObjectBefore(window, this);
                }
                window.ParentWindow = parentWindow;
                if (parentWindow != null && !parentWindow.ChildWindows.Contains(window))
                {
                    parentWindow.ChildWindows.Add(window);
                }
                window.Name = windowName;
                if (ltr != null)
                {
                    ltr.AddUpatedObjectAfter(window, this);
                }
            }

            if (actions == null && window.ChildActions.Count > 0)
            {
                foreach (var action in window.ChildActions)
                {
                    action.RemoveObject(this, ltr);
                }
                window.ChildActions.Clear();
            }
            else if (actions != null)
            {
                var addedActions = new HashSet <String>(actions.Select(act =>
                {
                    AddAction(window, act.Item1, act.Item2, ltr);
                    return(act.Item1);
                }));

                foreach (var action in window.ChildActions.Where(act => !addedActions.Contains(act.ActionKey)))
                {
                    action.RemoveObject(this, ltr);
                    window.ChildActions.Remove(action);
                }
            }

            return(window);
        }
        public void SetRights(String securityEntityID, RightsActionEnum action, RightsEnum?rightsValue, BaseContext context, Log.LogicTransaction ltr = null)
        {
            var ace = context.AllRights.Where(r => r.SubjectId.Equals(this.Iid, StringComparison.OrdinalIgnoreCase) && r.ObjectId.Equals(securityEntityID, StringComparison.OrdinalIgnoreCase))
                      .ToList()
                      .FirstOrDefault(r => r.Action == action);

            if (rightsValue == null)
            {
                if (ace != null)
                {
                    ace.RemoveObject(context, ltr);
                }
                return;
            }
            if (ace == null)
            {
                ace = context.AllRights.Add(new Users.DbRights(context)
                {
                    Subject   = this,
                    SubjectId = this.Iid,
                    ObjectId  = securityEntityID,
                    Rights    = rightsValue.Value,
                    Action    = action
                });
                if (ltr != null)
                {
                    ltr.AddCreatedObject(ace, context);
                }
                return;
            }

            if (ace.Rights != rightsValue.Value)
            {
                if (ltr != null)
                {
                    ltr.AddUpdatedObjectBefore(ace, context);
                }
                ace.Rights = rightsValue.Value;
                if (ltr != null)
                {
                    ltr.AddUpatedObjectAfter(ace, context);
                }
            }
        }