示例#1
0
        /// <summary>
        /// 删除导航
        /// </summary>
        private void DeletePresentAreaNavigation(PresentAreaNavigation presentAreaNavigation)
        {
            if (presentAreaNavigation == null)
            {
                return;
            }

            List <PresentAreaNavigation> presentAreaNavigationsForDelete = new List <PresentAreaNavigation>();

            IEnumerable <PresentAreaNavigation> descendants = GetDescendants(presentAreaNavigation);

            if (descendants.Count() > 0)
            {
                presentAreaNavigationsForDelete.AddRange(descendants);
            }

            presentAreaNavigationsForDelete.Add(presentAreaNavigation);

            EventBus <PresentAreaNavigation> .Instance().OnBatchBefore(presentAreaNavigationsForDelete, new CommonEventArgs(EventOperationType.Instance().Delete(), presentAreaNavigation.ApplicationId));

            foreach (var presentAreaNavigationForDelete in presentAreaNavigationsForDelete)
            {
                presentAreaNavigationRepository.Delete(presentAreaNavigationForDelete);
            }
            EventBus <PresentAreaNavigation> .Instance().OnBatchAfter(presentAreaNavigationsForDelete, new CommonEventArgs(EventOperationType.Instance().Delete(), presentAreaNavigation.ApplicationId));
        }
示例#2
0
        /// <summary>
        /// 在呈现区域实例添加应用的导航
        /// </summary>
        /// <remarks>
        /// 在呈现区域实例添加应用时调用
        /// </remarks>
        /// <param name="presentAreaKey">呈现区域标识</param>
        /// <param name="ownerId">呈现区域实例OwnerId</param>
        /// <param name="applicationId">应用Id</param>
        /// <returns>返回安装的PresentAreaNavigation的Id集合</returns>
        public List <long> InstallPresentAreaNavigationsOfApplication(string presentAreaKey, long ownerId, int applicationId)
        {
            IEnumerable <PresentAreaNavigation> navigationOfPresentAreaOwner = presentAreaNavigationRepository.GetNavigations(presentAreaKey, ownerId).ToList();

            //首先判断已经已经存在该应用的导航,防止重复安装
            if (navigationOfPresentAreaOwner.Where(n => n.ApplicationId == applicationId).Count() == 0)
            {
                List <long> ids = new List <long>();
                IEnumerable <InitialNavigation> initialNavigationOfApplication = GetInitialNavigations(presentAreaKey).Where(n => n.ApplicationId == applicationId);
                foreach (var initialNavigation in initialNavigationOfApplication)
                {
                    PresentAreaNavigation presentAreaNavigation = initialNavigation.AsPresentAreaNavigation();
                    presentAreaNavigation.OwnerId = ownerId;
                    presentAreaNavigationRepository.Insert(presentAreaNavigation);

                    ids.Add(presentAreaNavigation.Id);
                }

                EntityData.ForType(typeof(PresentAreaNavigation)).RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", ownerId);
                EntityData.ForType(typeof(Navigation)).RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", ownerId);
                return(ids);
            }

            return(null);
        }
示例#3
0
        /// <summary>
        /// InitialNavigation转换成PresentAreaNavigation
        /// </summary>
        public PresentAreaNavigation AsPresentAreaNavigation()
        {
            PresentAreaNavigation presentAreaNavigation = new PresentAreaNavigation()
            {
                NavigationId       = this.NavigationId,
                ParentNavigationId = this.ParentNavigationId,
                Depth            = this.Depth,
                PresentAreaKey   = this.PresentAreaKey,
                ResourceName     = this.ResourceName,
                NavigationUrl    = this.NavigationUrl,
                UrlRouteName     = this.UrlRouteName,
                RouteDataName    = this.RouteDataName,
                ApplicationId    = this.ApplicationId,
                NavigationType   = this.NavigationType,
                NavigationText   = this.NavigationText,
                NavigationTarget = this.NavigationTarget,
                ImageUrl         = this.ImageUrl,
                DisplayOrder     = this.DisplayOrder,
                OnlyOwnerVisible = this.OnlyOwnerVisible,
                IsLocked         = this.IsLocked,
                IsEnabled        = this.IsEnabled,
                OwnerId          = 0,
                IconName         = this.IconName
            };

            return(presentAreaNavigation);
        }
示例#4
0
        /// <summary>
        /// 获取parentPresentAreaNavigation的后代
        /// </summary>
        /// <param name="parentPresentAreaNavigation">PresentAreaNavigation</param>
        /// <returns>返回parentPresentAreaNavigation的所有后代集合</returns>
        public IEnumerable <PresentAreaNavigation> GetDescendants(PresentAreaNavigation parentPresentAreaNavigation)
        {
            List <PresentAreaNavigation>        descendants = new List <PresentAreaNavigation>();
            IEnumerable <PresentAreaNavigation> presentAreaNavigationsOfPresentArea = GetPresentAreaNavigations(parentPresentAreaNavigation.PresentAreaKey, parentPresentAreaNavigation.OwnerId);

            RecursiveGetChildren(presentAreaNavigationsOfPresentArea, parentPresentAreaNavigation, ref descendants);

            return(descendants);
        }
示例#5
0
        /// <summary>
        /// 创建呈现区域实例时初始化导航(不包括应用的导航)
        /// </summary>
        /// <param name="presentAreaKey">呈现区域标识</param>
        /// <param name="ownerId">呈现区域实例OwnerId</param>
        public void InitializePresentAreaNavigationsOfPresentAreaOwner(string presentAreaKey, long ownerId)
        {
            IEnumerable <InitialNavigation> initialNavigationOfPresentArea = GetInitialNavigations(presentAreaKey);

            foreach (var initialNavigation in initialNavigationOfPresentArea)
            {
                if (initialNavigation.ApplicationId == 0)
                {
                    PresentAreaNavigation presentAreaNavigation = initialNavigation.AsPresentAreaNavigation();
                    presentAreaNavigation.OwnerId = ownerId;
                    presentAreaNavigationRepository.Insert(presentAreaNavigation);
                }
            }
        }
示例#6
0
        /// <summary>
        /// 添加呈现区域实例导航
        /// </summary>
        /// <param name="presentAreaNavigation">PresentAreaNavigation</param>
        /// <exception cref="ArgumentNullException">presentAreaNavigation为空时</exception>
        /// <exception cref="ArgumentException">presentAreaNavigation的NavigationType不是<see cref="NavigationType"/>.AddedByOwner时</exception>
        /// <exception cref="ArgumentException">该PresentAreaNavigation此呈现区域实例已经创建时</exception>
        /// <returns>返回创建的PresentAreaNavigation的Id</returns>
        public long CreatePresentAreaNavigation(PresentAreaNavigation presentAreaNavigation)
        {
            if (presentAreaNavigation == null)
            {
                throw new ArgumentNullException("presentAreaNavigation不能为null");
            }

            if (presentAreaNavigation.NavigationType != NavigationType.AddedByOwner)
            {
                throw new ArgumentException("仅能处理NavigationType为Application或PresentAreaInitial的navigation");
            }

            IEnumerable <PresentAreaNavigation> presentAreaNavigations = GetPresentAreaNavigations(presentAreaNavigation.PresentAreaKey, presentAreaNavigation.OwnerId);

            if (presentAreaNavigations.Where(n => n.NavigationId == presentAreaNavigation.NavigationId).Count() > 0)
            {
                throw new ArgumentException("NavigationId不允许重复");
            }

            presentAreaNavigation.NavigationType = NavigationType.AddedByOwner;

            if (presentAreaNavigation.ParentNavigationId > 0)
            {
                InitialNavigation parentNavigation = GetInitialNavigation(presentAreaNavigation.ParentNavigationId);
                if (parentNavigation == null)
                {
                    throw new ApplicationException(string.Format("initialNavigation的父级 {0} 不存在", presentAreaNavigation.ParentNavigationId));
                }

                presentAreaNavigation.Depth = parentNavigation.Depth + 1;
            }
            else
            {
                presentAreaNavigation.Depth = 0;
            }
            EventBus <PresentAreaNavigation> .Instance().OnBefore(presentAreaNavigation, new CommonEventArgs(EventOperationType.Instance().Create(), presentAreaNavigation.ApplicationId));

            var id = Convert.ToInt64(presentAreaNavigationRepository.Insert(presentAreaNavigation));

            EventBus <PresentAreaNavigation> .Instance().OnAfter(presentAreaNavigation, new CommonEventArgs(EventOperationType.Instance().Create(), presentAreaNavigation.ApplicationId));

            //移除缓存(分布式缓存情况下,本机缓存会有一定延迟)
            string        cacheKey     = GetCacheKey_NavigationOfPresentAreaOwner(presentAreaNavigation.PresentAreaKey, presentAreaNavigation.OwnerId);
            ICacheService cacheService = DIContainer.Resolve <ICacheService>();

            cacheService.Remove(cacheKey);

            return(id);
        }
示例#7
0
        /// <summary>
        /// 更新导航
        /// </summary>
        /// <param name="presentAreaNavigation">PresentAreaNavigation</param>
        public void UpdatePresentAreaNavigation(PresentAreaNavigation presentAreaNavigation)
        {
            if (presentAreaNavigation == null)
            {
                return;
            }

            EventBus <PresentAreaNavigation> .Instance().OnBefore(presentAreaNavigation, new CommonEventArgs(EventOperationType.Instance().Update(), presentAreaNavigation.ApplicationId));

            presentAreaNavigationRepository.Update(presentAreaNavigation);
            EventBus <PresentAreaNavigation> .Instance().OnAfter(presentAreaNavigation, new CommonEventArgs(EventOperationType.Instance().Update(), presentAreaNavigation.ApplicationId));

            EntityData.ForType(typeof(PresentAreaNavigation)).RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", presentAreaNavigation.OwnerId);
            EntityData.ForType(typeof(Navigation)).RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", presentAreaNavigation.OwnerId);
        }
示例#8
0
        /// <summary>
        /// 添加呈现区域实例导航
        /// </summary>
        /// <param name="presentAreaNavigation">PresentAreaNavigation</param>
        /// <exception cref="ArgumentNullException">presentAreaNavigation为空时</exception>
        /// <exception cref="ArgumentException">presentAreaNavigation的NavigationType不是<see cref="NavigationType"/>.AddedByOwner时</exception>
        /// <exception cref="ArgumentException">该PresentAreaNavigation此呈现区域实例已经创建时</exception>
        /// <returns>返回创建的PresentAreaNavigation的Id</returns>
        public long CreatePresentAreaNavigation(PresentAreaNavigation presentAreaNavigation)
        {
            if (presentAreaNavigation == null)
            {
                throw new ArgumentNullException("presentAreaNavigation不能为null");
            }

            if (presentAreaNavigation.NavigationType != NavigationType.AddedByOwner)
            {
                throw new ArgumentException("仅能处理NavigationType为Application或PresentAreaInitial的navigation");
            }

            IEnumerable <PresentAreaNavigation> presentAreaNavigations = GetPresentAreaNavigations(presentAreaNavigation.PresentAreaKey, presentAreaNavigation.OwnerId);

            if (presentAreaNavigations.Where(n => n.NavigationId == presentAreaNavigation.NavigationId).Count() > 0)
            {
                throw new ArgumentException("NavigationId不允许重复");
            }

            presentAreaNavigation.NavigationType = NavigationType.AddedByOwner;

            if (presentAreaNavigation.ParentNavigationId > 0)
            {
                InitialNavigation parentNavigation = GetInitialNavigation(presentAreaNavigation.ParentNavigationId);
                if (parentNavigation == null)
                {
                    throw new ApplicationException(string.Format("initialNavigation的父级 {0} 不存在", presentAreaNavigation.ParentNavigationId));
                }

                presentAreaNavigation.Depth = parentNavigation.Depth + 1;
            }
            else
            {
                presentAreaNavigation.Depth = 0;
            }
            EventBus <PresentAreaNavigation> .Instance().OnBefore(presentAreaNavigation, new CommonEventArgs(EventOperationType.Instance().Create(), presentAreaNavigation.ApplicationId));

            var id = Convert.ToInt64(presentAreaNavigationRepository.Insert(presentAreaNavigation));

            EventBus <PresentAreaNavigation> .Instance().OnAfter(presentAreaNavigation, new CommonEventArgs(EventOperationType.Instance().Create(), presentAreaNavigation.ApplicationId));

            EntityData.ForType(typeof(PresentAreaNavigation)).RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", presentAreaNavigation.OwnerId);
            EntityData.ForType(typeof(Navigation)).RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", presentAreaNavigation.OwnerId);

            return(id);
        }
示例#9
0
        /// <summary>
        /// 更新导航
        /// </summary>
        /// <param name="presentAreaNavigation">PresentAreaNavigation</param>
        public void UpdatePresentAreaNavigation(PresentAreaNavigation presentAreaNavigation)
        {
            if (presentAreaNavigation == null)
            {
                return;
            }

            EventBus <PresentAreaNavigation> .Instance().OnBefore(presentAreaNavigation, new CommonEventArgs(EventOperationType.Instance().Update(), presentAreaNavigation.ApplicationId));

            presentAreaNavigationRepository.Update(presentAreaNavigation);
            EventBus <PresentAreaNavigation> .Instance().OnAfter(presentAreaNavigation, new CommonEventArgs(EventOperationType.Instance().Update(), presentAreaNavigation.ApplicationId));

            //移除缓存(分布式缓存情况下,本机缓存会有一定延迟)
            string        cacheKey     = GetCacheKey_NavigationOfPresentAreaOwner(presentAreaNavigation.PresentAreaKey, presentAreaNavigation.OwnerId);
            ICacheService cacheService = DIContainer.Resolve <ICacheService>();

            cacheService.Remove(cacheKey);
        }
示例#10
0
        /// <summary>
        /// 删除导航
        /// </summary>
        /// <param name="id">PresentAreaNavigation实体Id</param>
        public void DeletePresentAreaNavigation(long id)
        {
            PresentAreaNavigation presentAreaNavigation = presentAreaNavigationRepository.Get(id);

            if (presentAreaNavigation == null)
            {
                throw new ArgumentNullException(string.Format("id为{0}的PresentAreaNavigation不存在", id));
            }

            if (presentAreaNavigation.IsLocked)
            {
                throw new ApplicationException("锁定状态的PresentAreaNavigation不允许删除");
            }

            DeletePresentAreaNavigation(presentAreaNavigation);

            EntityData.ForType(typeof(PresentAreaNavigation)).RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", presentAreaNavigation.OwnerId);
            EntityData.ForType(typeof(Navigation)).RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", presentAreaNavigation.OwnerId);
        }
示例#11
0
        /// <summary>
        /// 删除导航
        /// </summary>
        /// <param name="id">PresentAreaNavigation实体Id</param>
        public void DeletePresentAreaNavigation(long id)
        {
            PresentAreaNavigation presentAreaNavigation = presentAreaNavigationRepository.Get(id);

            if (presentAreaNavigation == null)
            {
                throw new ArgumentNullException(string.Format("id为{0}的PresentAreaNavigation不存在", id));
            }

            if (presentAreaNavigation.IsLocked)
            {
                throw new ApplicationException("锁定状态的PresentAreaNavigation不允许删除");
            }

            DeletePresentAreaNavigation(presentAreaNavigation);

            //移除缓存(分布式缓存情况下,本机缓存会有一定延迟)
            string        cacheKey     = GetCacheKey_NavigationOfPresentAreaOwner(presentAreaNavigation.PresentAreaKey, presentAreaNavigation.OwnerId);
            ICacheService cacheService = DIContainer.Resolve <ICacheService>();

            cacheService.Remove(cacheKey);
        }
示例#12
0
        /// <summary>
        /// 把PresentAreaNavigation解析成Navigation
        /// </summary>
        /// <remarks>
        /// NavigationType = NavigationType.Application的PresentAreaNavigation需要与相应的InitialNavigation合并
        /// </remarks>
        /// <param name="presentAreaNavigation">PresentAreaNavigation</param>
        protected Navigation ParseNavigation(PresentAreaNavigation presentAreaNavigation)
        {
            if (presentAreaNavigation == null)
            {
                return(null);
            }

            Navigation nav = new Navigation()
            {
                OwnerId          = presentAreaNavigation.OwnerId,
                NavigationText   = presentAreaNavigation.NavigationText,
                NavigationTarget = presentAreaNavigation.NavigationTarget,
                ImageUrl         = presentAreaNavigation.ImageUrl,
                IconName         = presentAreaNavigation.IconName,
                DisplayOrder     = presentAreaNavigation.DisplayOrder
            };

            InitialNavigation initialNavigation = null;

            if (presentAreaNavigation.IsLocked)
            {
                initialNavigation = initialNavigationRepository.Get(presentAreaNavigation.NavigationId);
                if (initialNavigation == null)
                {
                    return(null);
                }

                nav.NavigationId       = initialNavigation.NavigationId;
                nav.ParentNavigationId = initialNavigation.ParentNavigationId;
                nav.Depth            = initialNavigation.Depth;
                nav.PresentAreaKey   = initialNavigation.PresentAreaKey;
                nav.ApplicationId    = initialNavigation.ApplicationId;
                nav.ResourceName     = initialNavigation.ResourceName;
                nav.IconName         = initialNavigation.IconName;
                nav.NavigationUrl    = initialNavigation.NavigationUrl;
                nav.UrlRouteName     = initialNavigation.UrlRouteName;
                nav.RouteDataName    = initialNavigation.RouteDataName;
                nav.OnlyOwnerVisible = initialNavigation.OnlyOwnerVisible;
                nav.NavigationType   = initialNavigation.NavigationType;
                nav.IsLocked         = true;
            }
            else
            {
                nav.NavigationId       = presentAreaNavigation.NavigationId;
                nav.ParentNavigationId = presentAreaNavigation.ParentNavigationId;
                nav.Depth            = presentAreaNavigation.Depth;
                nav.PresentAreaKey   = presentAreaNavigation.PresentAreaKey;
                nav.ApplicationId    = presentAreaNavigation.ApplicationId;
                nav.ResourceName     = presentAreaNavigation.ResourceName;
                nav.IconName         = presentAreaNavigation.IconName;
                nav.NavigationUrl    = presentAreaNavigation.NavigationUrl;
                nav.UrlRouteName     = presentAreaNavigation.UrlRouteName;
                nav.RouteDataName    = presentAreaNavigation.RouteDataName;
                nav.OnlyOwnerVisible = presentAreaNavigation.OnlyOwnerVisible;
                nav.NavigationType   = presentAreaNavigation.NavigationType;
                nav.IsLocked         = presentAreaNavigation.IsLocked;
            }

            #region 设置IsEnabled
            if (presentAreaNavigation.NavigationType == NavigationType.Application)
            {
                ApplicationBase app = ApplicationService.Get(presentAreaNavigation.ApplicationId);
                if (app == null)
                {
                    return(null);
                }

                if (!app.IsEnabled)
                {
                    nav.IsEnabled = false;
                    return(nav);
                }
            }

            if (presentAreaNavigation.NavigationType == NavigationType.Application || presentAreaNavigation.NavigationType == NavigationType.PresentAreaInitial)
            {
                if (initialNavigation != null && !initialNavigation.IsEnabled)
                {
                    nav.IsEnabled = false;
                    return(nav);
                }
            }

            nav.IsEnabled = presentAreaNavigation.IsEnabled;
            return(nav);

            #endregion
        }
示例#13
0
        /// <summary>
        /// 递归获取parentInitialNavigation所有子InitialNavigation
        /// </summary>
        private void RecursiveGetChildren(IEnumerable <PresentAreaNavigation> allPresentAreaNavigations, PresentAreaNavigation parentPresentAreaNavigation, ref List <PresentAreaNavigation> allDescendants)
        {
            IEnumerable <PresentAreaNavigation> children = allPresentAreaNavigations.Where(n => n.ParentNavigationId == parentPresentAreaNavigation.NavigationId);

            if (children.Count() > 0)
            {
                allDescendants.AddRange(children);
                foreach (var child in children)
                {
                    RecursiveGetChildren(allPresentAreaNavigations, child, ref allDescendants);
                }
            }
        }