예제 #1
0
        private static IList <IOrganization> InitAncestorOUsByParentID(IOguObject current)
        {
            List <IOrganization> result = new List <IOrganization>();

            string parentID = current.Properties.GetValue("PARENT_GUID", string.Empty);

            while (parentID.IsNotEmpty())
            {
                OguObjectCollection <IOrganization> parents =
                    OguMechanismFactory.GetMechanism().GetObjects <IOrganization>(SearchOUIDType.Guid, parentID);

                if (parents.Count > 0)
                {
                    result.Insert(0, parents[0]);
                    current  = parents[0];
                    parentID = current.Properties.GetValue("PARENT_GUID", string.Empty);
                }
                else
                {
                    break;
                }
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// 得到该部门的子成员
        /// </summary>
        /// <typeparam name="T">子成员的类型</typeparam>
        /// <param name="includeSideLine">是否包含兼职</param>
        /// <param name="searchLevel">是否递归</param>
        /// <returns>该部门的子成员</returns>
        protected override OguObjectCollection <T> GetChildren <T>(bool includeSideLine, SearchLevel searchLevel)
        {
            OguObjectCollection <T> children = base.GetChildren <T>(includeSideLine, searchLevel);

            List <T> list = new List <T>();

            foreach (T obj in children)
            {
                if (obj.ObjectType == SchemaType.Users)
                {
                    IUser user = (IUser)obj;

                    if (user.Rank >= this.AccessLevel)
                    {
                        list.Add(obj);
                    }
                }
                else
                {
                    list.Add(obj);
                }
            }

            return(new OguObjectCollection <T>(list));
        }
예제 #3
0
        /// <summary>
        /// 是否属于某些组
        /// </summary>
        /// <param name="groups"></param>
        /// <returns></returns>
        public bool IsInGroups(params IGroup[] groups)
        {
            if (groups == null)
            {
                throw new ArgumentNullException("groups");
            }

            bool bBelongTo = false;

            OguObjectCollection <IGroup> mof = MemberOf;

            for (int i = 0; i < groups.Length; i++)
            {
                foreach (IGroup group in mof)
                {
                    if (group.ID == groups[i].ID)
                    {
                        bBelongTo = true;
                        break;
                    }
                }
            }

            return(bBelongTo);
        }
예제 #4
0
        /// <summary>
        /// 得到该部门的子成员
        /// </summary>
        /// <typeparam name="T">子成员的类型</typeparam>
        /// <param name="includeSideLine">是否包含兼职</param>
        /// <param name="searchLevel">是否递归</param>
        /// <returns>该部门的子成员</returns>
        protected virtual OguObjectCollection <T> GetChildren <T>(bool includeSideLine, SearchLevel searchLevel) where T : IOguObject
        {
            OguObjectCollection <T> result = OguPermissionSettings.GetConfig().OguObjectImpls.GetChildren <T>(this, includeSideLine, searchLevel);

            NormalizeChildrenFullPath(this, result);

            return(result);
        }
예제 #5
0
 /// <summary>
 /// 填充子对象的FullPath属性。
 /// 有些情况下,子对象没有FullPath。当它没有时,可以根据父对象的FullPath和自身的名字拼接出来
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="parent"></param>
 /// <param name="children"></param>
 private static void NormalizeChildrenFullPath <T>(IOrganization parent, OguObjectCollection <T> children) where T : IOguObject
 {
     if (parent.FullPath.IsNotEmpty())
     {
         foreach (IOguObject obj in children)
         {
             if (obj is OguBaseImpl && obj.FullPath.IsNullOrEmpty() && obj.Name.IsNotEmpty())
             {
                 ((OguBaseImpl)obj).FullPath = parent.FullPath + "\\" + obj.Name;
             }
         }
     }
 }
예제 #6
0
        /// <summary>
        /// 得到ID唯一的记录集合。同一个对象仅出现一次。如果出现当前的和已删除的并存,仅保留当前的。如果只有
        /// 已经删除的,则保留已删除的。
        /// </summary>
        /// <returns></returns>
        internal OguObjectCollection <T> GetRemovedDuplicateDeletedObjectCollection()
        {
            OguObjectCollection <T> result = new OguObjectCollection <T>();

            foreach (T obj in Items)
            {
                if ((int)obj.Properties["STATUS"] == 3 &&
                    ExistsNotDeletedID(obj.ID, Items))
                {
                    continue;
                }

                result.Items.Add(obj);
            }

            return(result);
        }
예제 #7
0
        public OguObjectCollection <IOguObject> GetRolesObjects(RoleCollection roles, OguObjectCollection <IOrganization> depts, bool recursively)
        {
            OguObjectCollection <IOguObject> result = null;

            if (roles.Count > 0)
            {
                string roleIDs            = BuildRoleObjectIDs(roles);
                string deptFullPath       = BuildOguObjectFullPath(depts);
                bool   includeMatrixUsers = ServiceBrokerContext.Current.Context.GetValue("includeMatrixUsers", true);

                DataTable table = null;

                if (recursively)
                {
                    table = AppAdminServiceBroker.Instance.GetRolesUsers2(
                        deptFullPath,
                        roles[0].Application.CodeName,
                        roleIDs,
                        DelegationMaskType.All,
                        SidelineMaskType.All,
                        Common.DefaultAttrs,
                        includeMatrixUsers).Tables[0];
                }
                else
                {
                    table = AppAdminServiceBroker.Instance.GetChildrenInRoles2(
                        deptFullPath,
                        roles[0].Application.CodeName,
                        roleIDs,
                        false,
                        true,
                        true,
                        includeMatrixUsers).Tables[0];
                }

                result = new OguObjectCollection <IOguObject>(Common.BuildObjectsFromTable <IOguObject>(table));
            }
            else
            {
                result = new OguObjectCollection <IOguObject>(new List <IOguObject>());
            }

            return(result);
        }
예제 #8
0
        private static Dictionary <string, List <TObj> > GroupOguObjects <TObj>(OguObjectCollection <TObj> objs) where TObj : IOguObject
        {
            Dictionary <string, List <TObj> > result = new Dictionary <string, List <TObj> >(StringComparer.OrdinalIgnoreCase);

            foreach (TObj obj in objs)
            {
                List <TObj> list = null;

                if (result.TryGetValue(obj.ID, out list) == false)
                {
                    list = new List <TObj>();
                    result.Add(obj.ID, list);
                }

                list.Add(obj);
            }

            return(result);
        }
예제 #9
0
        public IOrganization GetRoot()
        {
            string rootPath = OguPermissionSettings.GetConfig().RootOUPath;

            OguObjectCollection <IOrganization> depts;

            if (string.IsNullOrEmpty(rootPath) == false)
            {
                depts = GetObjects <IOrganization>(SearchOUIDType.FullPath, rootPath);
            }
            else
            {
                DataTable table = OguReaderServiceBroker.Instance.GetRootDSE().Tables[0];

                depts = new OguObjectCollection <IOrganization>(Common.BuildObjectsFromTable <IOrganization>(table));
            }

            ExceptionHelper.FalseThrow(depts.Count > 0, Resource.CanNotFindRootOU, rootPath);
            return(depts[0]);
        }
예제 #10
0
        private IOrganization GetTopOUFromMapping(string mappedPath)
        {
            IOrganization dept = null;

            if (this.fullPath.IndexOf(mappedPath, StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (ObjectType == SchemaType.Organizations)
                {
                    dept = (IOrganization)this;
                }
                else
                {
                    dept = this.Parent;
                }

                while (dept != null)
                {
                    if (string.Compare(dept.FullPath, mappedPath, true) == 0)
                    {
                        break;
                    }

                    dept = dept.Parent;
                }
            }
            else
            {
                OguObjectCollection <IOrganization> objs = OguMechanismFactory.GetMechanism().GetObjects <IOrganization>(
                    SearchOUIDType.FullPath,
                    mappedPath);

                ExceptionHelper.FalseThrow(objs.Count > 0, Resource.CanNotFindObject, mappedPath);

                dept = objs[0];
            }

            return(dept);
        }
예제 #11
0
        private static IList <IOrganization> InitAncestorOUsByFullPath(IOguObject current)
        {
            string[] allFullPath = GetAncestorsFullPath(current.FullPath);

            List <IOrganization> result = null;

            if (allFullPath.Length > 0)
            {
                OguObjectCollection <IOrganization> organizations = OguMechanismFactory.GetMechanism().GetObjects <IOrganization>(
                    SearchOUIDType.FullPath,
                    allFullPath);

                organizations.Sort(OrderByPropertyType.FullPath, SortDirectionType.Ascending);

                result = organizations.ToList();
            }
            else
            {
                result = new List <IOrganization>();
            }

            return(result);
        }
예제 #12
0
        public OguObjectCollection <T> GetObjects <T>(SearchOUIDType idType, params string[] ids) where T : IOguObject
        {
            ExceptionHelper.FalseThrow <ArgumentNullException>(ids != null, "ids");

            SchemaType objType = OguObjectHelper.GetSchemaTypeFromInterface <T>();

            ExceptionHelper.TrueThrow(idType == SearchOUIDType.LogOnName &&
                                      (objType & ~(SchemaType.Users | SchemaType.Sideline)) != SchemaType.Unspecified, Resource.OnlyUserCanUserLogOnNameQuery);

            OguObjectCollection <T> result = null;

            if (ids.Length > 0)
            {
                string[]  notInCacheIds = null;
                IList <T> objsInCache   = null;

                if (ServiceBrokerContext.Current.UseLocalCache)
                {
                    objsInCache = OguObjectCacheBase.GetInstance(idType).GetObjectsInCache <T>(ids, out notInCacheIds);
                }
                else
                {
                    notInCacheIds = ids;
                    objsInCache   = new List <T>();
                }

                if (notInCacheIds.Length > 0)
                {
                    string multiIDString = BuildIDString(notInCacheIds);

                    DataSet ds = OguReaderServiceBroker.Instance.GetObjectsDetail(
                        SchemaTypeToString(objType),
                        multiIDString,
                        (int)idType,
                        string.Empty,
                        0,
                        Common.DefaultAttrs);

                    //RemoveDeletedObject(ds.Tables[0]); //原来有这句话,现在去掉,可以查询已经逻辑删除的对象

                    OguObjectCollection <T> queryResult = new OguObjectCollection <T>(Common.BuildObjectsFromTable <T>(ds.Tables[0]));

                    queryResult = queryResult.GetRemovedDuplicateDeletedObjectCollection();

                    if (ServiceBrokerContext.Current.UseLocalCache)
                    {
                        OguObjectCacheBase.GetInstance(idType).AddObjectsToCache <T>(queryResult);
                    }

                    foreach (T obj in queryResult)
                    {
                        objsInCache.Add(obj);
                    }
                }

                result = new OguObjectCollection <T>(objsInCache);
                result.Sort(OrderByPropertyType.GlobalSortID, SortDirectionType.Ascending);
            }
            else
            {
                result = new OguObjectCollection <T>();
            }

            return(result);
        }