Beispiel #1
0
            private void Handle(IAcSession acSession, IMenuUpdateIo input, bool isCommand)
            {
                var       acDomain       = _set._acDomain;
                var       menuById       = _set._menuById;
                var       menuRepository = acDomain.RetrieveRequiredService <IRepository <Menu, Guid> >();
                MenuState bkState;

                if (!acDomain.MenuSet.TryGetMenu(input.Id, out bkState))
                {
                    throw new ValidationException("给定标识的菜单不存在" + input.Id);
                }
                Menu entity;
                var  stateChanged = false;

                lock (Locker)
                {
                    MenuState oldState;
                    if (!acDomain.MenuSet.TryGetMenu(input.Id, out oldState))
                    {
                        throw new ValidationException("给定标识的菜单不存在" + input.Id);
                    }
                    entity = menuRepository.GetByKey(input.Id);
                    if (entity == null)
                    {
                        throw new NotExistException();
                    }

                    entity.Update(input);

                    var newState = MenuState.Create(acDomain, entity);
                    stateChanged = newState != bkState;
                    if (stateChanged)
                    {
                        Update(newState);
                    }
                    if (isCommand)
                    {
                        try
                        {
                            menuRepository.Update(entity);
                            menuRepository.Context.Commit();
                        }
                        catch
                        {
                            if (stateChanged)
                            {
                                Update(bkState);
                            }
                            menuRepository.Context.Rollback();
                            throw;
                        }
                    }
                }
                if (isCommand && stateChanged)
                {
                    acDomain.MessageDispatcher.DispatchMessage(new MenuUpdatedEvent(acSession, entity, input, isPrivate: true));
                }
            }
Beispiel #2
0
 private void Init()
 {
     if (_initialized)
     {
         return;
     }
     lock (Locker)
     {
         if (_initialized)
         {
             return;
         }
         _acDomain.MessageDispatcher.DispatchMessage(new MemorySetInitingEvent(this));
         _menuById.Clear();
         var menus = _acDomain.RetrieveRequiredService <IOriginalHostStateReader>().GetAllMenus().OrderBy(a => a.SortCode);
         foreach (var menu in menus)
         {
             _menuById.Add(menu.Id, MenuState.Create(_acDomain, menu));
         }
         _initialized = true;
         _acDomain.MessageDispatcher.DispatchMessage(new MemorySetInitializedEvent(this));
     }
 }
Beispiel #3
0
            private void Handle(IAcSession acSession, IMenuCreateIo input, bool isCommand)
            {
                var acDomain       = _set._acDomain;
                var menuById       = _set._menuById;
                var menuRepository = acDomain.RetrieveRequiredService <IRepository <Menu, Guid> >();

                if (!input.Id.HasValue)
                {
                    throw new ValidationException("标识是必须的");
                }
                MenuState menu;

                if (acDomain.MenuSet.TryGetMenu(input.Id.Value, out menu))
                {
                    throw new ValidationException("给定标识的实体已经存在" + input.Id);
                }
                if (input.ParentId.HasValue)
                {
                    MenuState parentMenu;
                    if (!acDomain.MenuSet.TryGetMenu(input.ParentId.Value, out parentMenu))
                    {
                        throw new NotExistException("标识为" + input.ParentId.Value + "的父菜单不存在");
                    }
                    if (input.AppSystemId != parentMenu.AppSystemId)
                    {
                        throw new ValidationException("非法的数据,子菜单的应用系统必须和父菜单一致");
                    }
                }

                var entity = Menu.Create(input);

                lock (Locker)
                {
                    if (acDomain.MenuSet.TryGetMenu(input.Id.Value, out menu))
                    {
                        throw new ValidationException("给定标识的实体已经存在" + input.Id);
                    }
                    if (input.ParentId.HasValue)
                    {
                        MenuState parentMenu;
                        if (!acDomain.MenuSet.TryGetMenu(input.ParentId.Value, out parentMenu))
                        {
                            throw new NotExistException("标识为" + input.ParentId.Value + "的父菜单不存在");
                        }
                    }
                    var menuState = MenuState.Create(acDomain, entity);
                    if (!menuById.ContainsKey(entity.Id))
                    {
                        menuById.Add(entity.Id, menuState);
                    }
                    if (isCommand)
                    {
                        try
                        {
                            menuRepository.Add(entity);
                            menuRepository.Context.Commit();
                        }
                        catch
                        {
                            if (menuById.ContainsKey(entity.Id))
                            {
                                menuById.Remove(entity.Id);
                            }
                            menuRepository.Context.Rollback();
                            throw;
                        }
                    }
                }
                if (isCommand)
                {
                    acDomain.MessageDispatcher.DispatchMessage(new MenuAddedEvent(acSession, entity, input, isPrivate: true));
                }
            }