public void PopulateUserHierarchies() { const string QUERY_USER_HIERARCHIES_SIZE = @" SELECT DIMENSION_NAME AS TABLE_NAME, COLUMN_ID AS STRUCTURE_NAME, USED_SIZE AS USED_SIZE, TABLE_ID AS HIERARCHY_ID FROM $SYSTEM.DISCOVER_STORAGE_TABLE_COLUMN_SEGMENTS WHERE LEFT ( TABLE_ID, 2 ) = 'U$'"; var mapUserHierarchyNames = GetUserHierarchiesNames(); var cmd = new AdomdCommand(QUERY_USER_HIERARCHIES_SIZE, Connection) { CommandTimeout = CommandTimeout }; using (var rdr = cmd.ExecuteReader()) { // Reset size existing hierarchies foreach (var t in this.DaxModel.Tables) { foreach (var uh in t.UserHierarchies) { uh.UsedSize = 0; } } // Loop through the result of the DMV while (rdr.Read()) { string tableName = rdr.GetString(0); // string structureName = rdr.GetString(1); long usedSize = (long)rdr.GetDecimal(2); string userHierarchyFullId = rdr.GetString(3); string userHierarchyId = userHierarchyFullId.Substring(userHierarchyFullId.LastIndexOf('$') + 1); // Default for compatibility level < 1200 string userHierarchyName = userHierarchyId; // Search visible name for compatibility level >= 1200 var openIdBracket = userHierarchyId.LastIndexOf('('); var closeIdBracket = userHierarchyId.LastIndexOf(')'); if (openIdBracket >= 0 && closeIdBracket >= 0) { var stringDmv1200Id = userHierarchyId.Substring(openIdBracket + 1, closeIdBracket - (openIdBracket + 1)); if (int.TryParse(stringDmv1200Id, out int intDmv1200Id)) { mapUserHierarchyNames.TryGetValue(intDmv1200Id, out userHierarchyName); } } UserHierarchy daxUserHierarchy = GetDaxUserHierarchy(tableName, userHierarchyName); // We sum the size to the existing one // The DMV returns multiple structures for each hierarchy (MULTI_LEVEL_ID, PARENT_POS, FIRST_CHILD_POS, CHILD_COUNT) // UsedSize is reset to 0 before looping through DMV resuls daxUserHierarchy.UsedSize += usedSize; } } }
public override void Deserialize(KnetikJSONNode json) { base.Deserialize (json); Relationships = new Dictionary<String, UserHierarchy> (); foreach (KeyValuePair<string, KnetikJSONNode> kvp in (KnetikJSONClass)json) { UserHierarchy relationship = new UserHierarchy(Client); relationship.Deserialize(kvp.Value); Relationships.Add(kvp.Key, relationship); } }
//Method for Member in group by User /Owner public void joinInGroup(string Code, bool byUser, bool byOwner) { try { ManageAdminHelper manager = new ManageAdminHelper(); if (byUser) { long ownerId = manager.getCurrentUserPID(Code); using (UnitOfWork unitOfWork = new UnitOfWork()) { UserHierarchyRepository = unitOfWork.GetRepoInstance <UserHierarchy>(); UserHierarchy Uhierarchy = new UserHierarchy(); Uhierarchy.UserDetailPID = this.CurrentUserPID; Uhierarchy.ManagerUserDetailPID = ownerId; UserHierarchyRepository.Insert(Uhierarchy); //Update the Usser ManagerPId UserDetailRepository = unitOfWork.GetRepoInstance <UserDetail>(); UserDetail currentUser = UserDetailRepository.GetByID(this.CurrentUserPID); currentUser.ManagerPID = ownerId; currentUser.UserTypePID = (long)TradeBulk_Helper.WebAPIhelper.UserType.Manager; UserDetailRepository.Update(currentUser); unitOfWork.SaveChanges(); } } else if (byOwner) { long userId = manager.getCurrentUserPID(Code); using (UnitOfWork unitOfWork = new UnitOfWork()) { UserHierarchyRepository = unitOfWork.GetRepoInstance <UserHierarchy>(); UserHierarchy Uhierarchy = new UserHierarchy(); Uhierarchy.UserDetailPID = userId; Uhierarchy.ManagerUserDetailPID = this.CurrentUserPID; UserHierarchyRepository.Insert(Uhierarchy); //Update the Usser ManagerPId UserDetailRepository = unitOfWork.GetRepoInstance <UserDetail>(); UserDetail requiredUser = UserDetailRepository.GetByID(userId); requiredUser.ManagerPID = this.CurrentUserPID; UserDetailRepository.Update(requiredUser); unitOfWork.SaveChanges(); } } } catch (Exception ex) { throw ex; } }