/// <summary> /// Lấy danh sách Role chứa userName /// </summary> /// <param name="userName">UserName cần lấy danh sách Role</param> /// <returns></returns> public RoleCollection GetRolesOfUser(string userName) { SqlParameter prmUerName = new SqlParameter("@UserName", SqlDbType.VarChar, 128); prmUerName.Direction = ParameterDirection.Input; prmUerName.Value = userName; RoleCollection collection = new RoleCollection(); try { using (IDataReader dr = Database.ExecuteReader("UspGetRolesOfUser", CommandType.StoredProcedure, prmUerName)) { while (dr.Read()) { Role role = Populate(dr); collection.Add(role); } } } catch (Exception ex) { throw ex; } return(collection); }
public RoleCollection GetRolesNotBelongTo() { PSCPortal.Framework.Database database = new PSCPortal.Framework.Database("PSCPortalConnectionString"); RoleCollection result = new RoleCollection(); using (DbConnection connection = database.GetConnection()) { DbCommand command = database.GetCommand(connection); #region SubDomainId DbParameter prId = database.GetParameter(System.Data.DbType.Guid, "@SubDomainId", _id); command.Parameters.Add(prId); #endregion command.CommandText = @"SELECT a.[RoleId], [RoleName], [RoleDescription] FROM dbo.[Role] a inner join SubDomainInRole b on a.RoleId = b.RoleId WHERE SubDomainId!=@SubDomainId" ; command.CommandType = System.Data.CommandType.Text; command.Connection = connection; connection.Open(); DbDataReader reader = command.ExecuteReader(); while (reader.Read()) { Role item = new Role(reader); result.Add(item); } } return(result); }
/// <summary> /// /// </summary> /// <param name="roleCode"></param> /// <returns></returns> public RoleCollection FindRolesByCode(string roleCode, int applicationID) { SqlParameter prmRoleCode = new SqlParameter("@RoleCode", SqlDbType.VarChar, 128); SqlParameter prmApplicationID = new SqlParameter("@ApplicationID", SqlDbType.Int, 4); prmRoleCode.Direction = ParameterDirection.Input; prmApplicationID.Direction = ParameterDirection.Input; prmRoleCode.Value = roleCode; prmApplicationID.Value = applicationID; RoleCollection collection = new RoleCollection(); try { using (IDataReader dr = Database.ExecuteReader("UspFindRolesByCode", CommandType.StoredProcedure, prmRoleCode, prmApplicationID)) { while (dr.Read()) { Role role = Populate(dr); collection.Add(role); } } } catch (Exception ex) { throw ex; } return(collection); }
/// <summary> /// Lay danh sach Role cua mot ung dung /// </summary> /// <param name="applicationID">ID cua Ung dung</param> /// <returns>tra ve danh sach dang RoleCollection</returns> public RoleCollection GetRoleInApplication(int applicationID) { SqlParameter prmApplicationID = new SqlParameter("@AppID", SqlDbType.Int, 4); prmApplicationID.Direction = ParameterDirection.Input; prmApplicationID.Value = applicationID; RoleCollection collection = new RoleCollection(); try { using (IDataReader dr = Database.ExecuteReader("UspGetRoles_In_App", CommandType.StoredProcedure, prmApplicationID)) { while (dr.Read()) { Role role = Populate(dr); collection.Add(role); } } } catch (Exception ex) { throw (ex); } return(collection); }
protected CollectionBase GenerateRoleCollectionFromReader(IDataReader returnData) { RoleCollection colRoles = new RoleCollection(); while (returnData.Read()) { Role newRole = new Role((int)returnData["RoleId"], (string)returnData["RoleName"]); colRoles.Add(newRole); } return(colRoles); }
public static RoleCollection SelectAll() { RoleCollection List = new RoleCollection(); using (IDataReader rd = SqlHelper.ExecuteReader(DAL.con(), CommandType.StoredProcedure, "sp_tblRole_Select_SelectAll_linhnx")) { while (rd.Read()) { List.Add(getFromReader(rd)); } } return(List); }
public RoleCollection GetRoles(RoleResolver resolver) { RoleCollection roles = new RoleCollection(); foreach (Role role in GetAllRoles()) { if (resolver(role)) { roles.Add(role); } } return(roles); }
public static RoleCollection SelectRoleByUsername(string Username) { var List = new RoleCollection(); var obj = new SqlParameter[1]; obj[0] = new SqlParameter("Username", Username); using (IDataReader rd = SqlHelper.ExecuteReader(DAL.con(), CommandType.StoredProcedure, "sp_tblRole_Select_SelectRoleByUsername_linhnx", obj)) { while (rd.Read()) { List.Add(getFromReader(rd)); } } return(List); }
public static RoleCollection GetCurrentRoles() { RoleCollection roleCollection = new RoleCollection(); StringBuilder stringBuilder = new StringBuilder(); foreach (Role role in RoleManager.Roles) { if (role.IsCurrent) { roleCollection.Add(role); stringBuilder.Append(role.RoleName); stringBuilder.Append(" "); } } TaskLogger.Log(Strings.CurrentRoles(stringBuilder.ToString())); return(roleCollection); }
internal static RoleCollection GetCollection(DataTable dataItems) { RoleCollection listCollection = new RoleCollection(); if (dataItems != null) { for (int i = 0; i < dataItems.Rows.Count; i++) { listCollection.Add(new Role(dataItems.Rows[i])); } } else { throw new Exception("You cannot create a RoleCollection from a null data table."); } return(listCollection); }
public void RoleCollection_can_add_skill() { // AAA - Arrange, Act, Assert // Arrange var sut = new RoleCollection(); IRole r1 = new Role { RoleID = 101, Name = "DEV" }; // Act sut.Add(r1); // Assert Assert.Multiple(() => { Assert.That(sut.Count, Is.EqualTo(1)); Assert.That(sut[0].RoleID, Is.EqualTo(101)); Assert.That(sut[0].Name, Is.EqualTo("DEV")); }); }
public RoleCollection InitRoleInformation(String[] RoleIndex) { RoleCollection Result = new RoleCollection(); if (RoleIndex == null || RoleIndex.Length == 0) { return(Result); } if (string.IsNullOrEmpty(string.Join("','", RoleIndex))) { return(Result); } StringBuilder Sql_Select = new StringBuilder(); //增加查询条件 Scdel=0 2013-10-17 Sql_Select.Append("select * from sys_auth_Roles where Scdel=0 and ID in "); Sql_Select.Append(string.Concat("('", string.Join("','", RoleIndex), "')")); DataTable Data = GetDataTable(Sql_Select.ToString()); foreach (DataRow row in Data.Rows) { String Index = row["ID"].ToString(); String Name = row["Name"].ToString(); String Code = row["Code"].ToString(); String IsAdministrator = row["IsAdministrator"].ToString(); String Permissions = row["Permissions"].ToString(); Role role = new Role(); role.Index = Index; role.Name = Name; role.Code = Code; role.IsAdministrator = Convert.ToBoolean(IsAdministrator); Result.Add(role); } return(Result); }
public RoleCollection GetRolesByAssociateID(int?id) { RoleCollection result = CreateNewRoleCollection(); if (id.HasValue && id >= 100) { var foundAssociateRoleIds = Context.AssociateRoleLinks .Where(e => e.AssociateID == id) .Select(e => e.RoleID); var foundAssociateRoles = Context.Roles .Where(e => foundAssociateRoleIds.Contains(e.RoleID)) .OrderBy(e => e.PresentationOrder) .ThenBy(e => e.Name); foreach (var foundRole in foundAssociateRoles) { result.Add(GetRoleByID(foundRole.RoleID)); } } return(result); }
public static bool Save(Role role) { if (role.Id < 0) { // Complete transaction if (repo.Insert(role)) { cache.Add(role); return(true); } else { // Do nothing // Transaction will be rolled back. } } else { return(repo.Update(role)); } return(false); }
public static RoleCollection TreeByUsername(string Username, string q, string ROLE_CQ_ID, string Sort) { RoleCollection List = new RoleCollection(); SqlParameter[] obj = new SqlParameter[4]; obj[0] = new SqlParameter("Username", Username); if (string.IsNullOrEmpty(q)) { obj[1] = new SqlParameter("q", DBNull.Value); } else { obj[1] = new SqlParameter("q", q); } if (string.IsNullOrEmpty(ROLE_CQ_ID)) { obj[2] = new SqlParameter("ROLE_CQ_ID", DBNull.Value); } else { obj[2] = new SqlParameter("ROLE_CQ_ID", ROLE_CQ_ID); } obj[3] = new SqlParameter("Sort", Sort); using (IDataReader rd = SqlHelper.ExecuteReader(DAL.con(), CommandType.StoredProcedure, "sp_tblRole_Select_TreeByUsername_linhnx", obj)) { while (rd.Read()) { CoQuan _item = new CoQuan(); _item.Ten = rd["CQ_Ten"].ToString(); Role item = new Role(); item = getFromReader(rd); item._CoQuan = _item; List.Add(item); } } return(List); }
/// <summary> /// /// </summary> /// <returns></returns> public RoleCollection GetAllRoles() { RoleCollection collection = new RoleCollection(); try { // Execute procedure to update role using (IDataReader dr = Database.ExecuteReader("UspGetAllRoles", CommandType.StoredProcedure)) { while (dr.Read()) { Role role = Populate(dr); collection.Add(role); } } return(collection); } catch (Exception ex) { throw ex; } }
public bool SaveSettings() { MessageDisplay msdDisplay = CreateMessageDisplay("name", "title", "requiredPoint", "level"); RoleCollection tempRoles = new RoleCollection(); RoleSettings settings = SettingManager.CloneSetttings<RoleSettings>(AllSettings.Current.RoleSettings); Role temp; Guid[] oldRoleids = _Request.GetList<Guid>("roleid", Method.Post, new Guid[00]); foreach (Guid r in oldRoleids) { temp = settings.GetRole(r); if (AllSettings.Current.BackendPermissions.Can(My, BackendPermissions.ActionWithTarget.Setting_Roles_Manager, temp)) { temp = temp == null ? CreateRole() : temp.Clone(); //不采用克隆的话可能会有些属性丢失掉 temp.Name = _Request.Get("Name." + r, Method.Post); temp.Title = _Request.Get("title." + r, Method.Post); temp.RequiredPoint = _Request.Get<int>("RequiredPoint." + r, Method.Post, 0); temp.Color = _Request.Get("Color." + r, Method.Post); temp.IconUrlSrc = _Request.Get("IconUrl." + r, Method.Post); temp.StarLevel = _Request.Get<int>("StarLevel." + r, Method.Post, 0); temp.Level = _Request.Get<int>("Level." + r, Method.Post, 0); temp.IsNew = _Request.Get<bool>("isnew." + r, Method.Post, false); temp.CanLoginConsole = _Request.Get<bool>("CanLoginConsole." + r, Method.Post, false) && temp.IsManager; temp.RoleID = r; if (temp.IsLevel) temp.Name = temp.Title; } else { if (temp == null) continue; } tempRoles.Add(temp); } //Nonsupport Javascript if (_Request.Get("newroleid", Method.Post, "").Contains("{0}")) { Role r = CreateRole(); r.Name = _Request.Get("name.new.{0}", Method.Post); r.Title = _Request.Get("title.new.{0}", Method.Post); r.StarLevel = _Request.Get<int>("starlevel.new.{0}", Method.Post, 0); r.RequiredPoint = _Request.Get<int>("RequiredPoint.new.{0}", Method.Post, 0); r.Color = _Request.Get("color.new.{0}", Method.Post); r.IconUrlSrc = _Request.Get("IconUrl.new.{0}", Method.Post); r.Level = _Request.Get<int>("Level.new.{0}", Method.Post, 0); r.CanLoginConsole = _Request.Get<bool>("CanLoginConsole.new.{0}", Method.Post, false) && r.IsManager; if (r.IsLevel) r.Name = r.Title; if (!string.IsNullOrEmpty(r.Name)) tempRoles.Add(r); } else { int[] newroleid = _Request.GetList<int>("newroleid", Method.Post, new int[0]); foreach (int i in newroleid) { Role r = CreateRole(); r.Name = _Request.Get("name.new." + i, Method.Post); r.Title = _Request.Get("title.new." + i, Method.Post); r.StarLevel = _Request.Get<int>("starlevel.new." + i, Method.Post, 0); r.RequiredPoint = _Request.Get<int>("RequiredPoint.new." + i, Method.Post, 0); r.Color = _Request.Get("color.new." + i, Method.Post); r.IconUrlSrc = _Request.Get("IconUrl.new." + i, Method.Post); r.Level = _Request.Get<int>("Level.new." + i, Method.Post, 0); r.CanLoginConsole = _Request.Get<bool>("CanLoginConsole.new." + i, Method.Post, false) && r.IsManager; if (r.IsLevel) r.Name = r.Title; tempRoles.Add(r); } } if (ValidateRoleDate(tempRoles, msdDisplay)) { foreach (Role r in tempRoles) { settings.SetRole(r); } if (BeforeSaveSettings(settings)) { SettingManager.SaveSettings(settings); m_RoleList = null; return true; } } m_RoleList = tempRoles; msdDisplay.AddError(new DataNoSaveError()); return false; }
/// <summary> /// Gets the collection of roles of a specified right. /// </summary> /// <param name="right">The right.</param> /// <returns></returns> public RoleCollection GetRoles(Right right) { RoleCollection roles = new RoleCollection(); //Checking whether that specified right is in each and every Role-Right-assignment object of RoleRightAssignments collection. //If it is there,find the role of that Role-Right-Assignment object and add that to RoleCollection-roles. foreach (RoleRightAssignment rra in this.RoleRightAssignments) { if (rra.Right.Id == right.Id) roles.Add(rra.Role); } //returns the RoleCollection. return roles; }
public bool SaveSettings() { MessageDisplay msdDisplay = CreateMessageDisplay("name", "title", "requiredPoint", "level"); RoleCollection tempRoles = new RoleCollection(); RoleSettings settings = SettingManager.CloneSetttings <RoleSettings>(AllSettings.Current.RoleSettings); Role temp; Guid[] oldRoleids = _Request.GetList <Guid>("roleid", Method.Post, new Guid[00]); foreach (Guid r in oldRoleids) { temp = settings.GetRole(r); if (AllSettings.Current.BackendPermissions.Can(My, BackendPermissions.ActionWithTarget.Setting_Roles_Manager, temp)) { temp = temp == null?CreateRole() : temp.Clone(); //不采用克隆的话可能会有些属性丢失掉 temp.Name = _Request.Get("Name." + r, Method.Post); temp.Title = _Request.Get("title." + r, Method.Post); temp.RequiredPoint = _Request.Get <int>("RequiredPoint." + r, Method.Post, 0); temp.Color = _Request.Get("Color." + r, Method.Post); temp.IconUrlSrc = _Request.Get("IconUrl." + r, Method.Post); temp.StarLevel = _Request.Get <int>("StarLevel." + r, Method.Post, 0); temp.Level = _Request.Get <int>("Level." + r, Method.Post, 0); temp.IsNew = _Request.Get <bool>("isnew." + r, Method.Post, false); temp.CanLoginConsole = _Request.Get <bool>("CanLoginConsole." + r, Method.Post, false) && temp.IsManager; temp.RoleID = r; if (temp.IsLevel) { temp.Name = temp.Title; } } else { if (temp == null) { continue; } } tempRoles.Add(temp); } //Nonsupport Javascript if (_Request.Get("newroleid", Method.Post, "").Contains("{0}")) { Role r = CreateRole(); r.Name = _Request.Get("name.new.{0}", Method.Post); r.Title = _Request.Get("title.new.{0}", Method.Post); r.StarLevel = _Request.Get <int>("starlevel.new.{0}", Method.Post, 0); r.RequiredPoint = _Request.Get <int>("RequiredPoint.new.{0}", Method.Post, 0); r.Color = _Request.Get("color.new.{0}", Method.Post); r.IconUrlSrc = _Request.Get("IconUrl.new.{0}", Method.Post); r.Level = _Request.Get <int>("Level.new.{0}", Method.Post, 0); r.CanLoginConsole = _Request.Get <bool>("CanLoginConsole.new.{0}", Method.Post, false) && r.IsManager; if (r.IsLevel) { r.Name = r.Title; } if (!string.IsNullOrEmpty(r.Name)) { tempRoles.Add(r); } } else { int[] newroleid = _Request.GetList <int>("newroleid", Method.Post, new int[0]); foreach (int i in newroleid) { Role r = CreateRole(); r.Name = _Request.Get("name.new." + i, Method.Post); r.Title = _Request.Get("title.new." + i, Method.Post); r.StarLevel = _Request.Get <int>("starlevel.new." + i, Method.Post, 0); r.RequiredPoint = _Request.Get <int>("RequiredPoint.new." + i, Method.Post, 0); r.Color = _Request.Get("color.new." + i, Method.Post); r.IconUrlSrc = _Request.Get("IconUrl.new." + i, Method.Post); r.Level = _Request.Get <int>("Level.new." + i, Method.Post, 0); r.CanLoginConsole = _Request.Get <bool>("CanLoginConsole.new." + i, Method.Post, false) && r.IsManager; if (r.IsLevel) { r.Name = r.Title; } tempRoles.Add(r); } } if (ValidateRoleDate(tempRoles, msdDisplay)) { foreach (Role r in tempRoles) { settings.SetRole(r); } if (BeforeSaveSettings(settings)) { SettingManager.SaveSettings(settings); m_RoleList = null; return(true); } } m_RoleList = tempRoles; msdDisplay.AddError(new DataNoSaveError()); return(false); }
public RoleCollection GetAllRoles(string userName) { //TODO RoleCollection collection = new RoleCollection(); using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(); command.Connection = connection; command.CommandText = "SP_Frank_TEST"; SqlParameter ColumnParam = command.Parameters.Add("@UserAccount", System.Data.SqlDbType.VarChar); ColumnParam.Value = userName; command.CommandType = System.Data.CommandType.StoredProcedure; connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { Role role = new Role(); role.RoleName = reader["Role_Name"].ToString(); collection.Add(role); } } reader.Close(); return collection; } }
public static void ConvertRoles() { RoleCollection newRoles = new RoleCollection(); string sql = @" --�����û������ݵĴ����� IF EXISTS(SELECT * FROM sysobjects WHERE [type]=N'TR' AND [name]=N'bx_UserRoles_AfterUpdate') DROP TRIGGER bx_UserRoles_AfterUpdate; --GO "; using (SqlConnection connection = new SqlConnection(Settings.Current.IConnectionString)) { connection.Open(); SqlCommand command = new SqlCommand(sql, connection); command.CommandTimeout = 60; try { command.ExecuteNonQuery(); } catch (Exception ex) { CreateLog(ex); throw new Exception("ɾ��������bx_UserRoles_AfterUpdateʧ��" + ex.Message + sql); } finally { connection.Close(); } } Guid vipRoleID = new Guid(new byte[] { 152, 198, 223, 228, 218, 198, 221, 78, 191, 59, 129, 195, 81, 168, 105, 207 }); //�����ο͡�everyone sql = @" IF EXISTS (SELECT * FROM sysobjects WHERE [type] = N'U' AND [name] = N'Max_Roles') AND EXISTS (SELECT * FROM [sysobjects] WHERE [type]='U' AND [name]='Max_UsersInRoles') BEGIN IF NOT EXISTS (SELECT [name] FROM syscolumns WHERE id = object_id('Max_Roles') AND [name] = 'NewRoleID') ALTER TABLE Max_Roles add [NewRoleID] uniqueidentifier NOT NULL DEFAULT(NEWID()); SELECT * FROM Max_Roles WHERE RoleID > 0; IF EXISTS (SELECT * FROM sysobjects WHERE [type] = N'U' AND [name] = N'bbsMax_PointLevels') SELECT * FROM bbsMax_PointLevels WHERE RequireRoleID = 0; END ELSE SELECT -9999 AS RoleID; "; using (SqlConnection connection = new SqlConnection(Settings.Current.IConnectionString)) { connection.Open(); SqlCommand command = new SqlCommand(sql, connection); command.CommandTimeout = 60; try { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { #region ������ int roleID = (int)reader["RoleID"]; //Max_Roles������ڣ��˳��û���ת�� if (roleID == -9999) return; Guid newRoleID = (Guid)reader["NewRoleID"]; string roleName = (string)reader["RoleName"]; string logoUrl = (string)reader["LogoUrl"]; string displayColor = (string)reader["DisplayColor"]; Role role; switch (roleID) { case 1: role = Role.Owners.Clone();//Role.CreateManagerRole(); //role.RoleID = newRoleID; role.Title = roleName; break; case 2: role = Role.Administrators.Clone(); //role.RoleID = newRoleID; role.Title = roleName; break; case 3: role = Role.SuperModerators.Clone(); //role.RoleID = newRoleID; role.Title = roleName; break; case 5: role = Role.CreateNormalRole(); role.RoleID = vipRoleID; role.Name = roleName; role.Title = roleName; break; default: if (roleID > 8) { role = Role.CreateNormalRole(); role.RoleID = newRoleID; role.Name = roleName; } else continue; break; } newRoles.Set(role); #endregion } if (reader.NextResult()) { while (reader.Read()) { Role role = Role.CreateLevelRole(); role.RequiredPoint = (int)reader["RequirePoints"]; role.RoleID = Guid.NewGuid(); role.Name = (string)reader["LevelName"]; role.Title = role.Name; role.StarLevel = (int)reader["Stars"]; newRoles.Add(role); } } newRoles.Sort(); } sql = @" UPDATE bx_Settings SET [Value] = @RolesString WHERE TypeName = 'MaxLabs.bbsMax.Settings.RoleSettings' AND [Key] = 'Roles'; IF @@ROWCOUNT = 0 INSERT INTO bx_Settings ([Key], [Value], [TypeName]) VALUES ('Roles', @RolesString, 'MaxLabs.bbsMax.Settings.RoleSettings'); IF EXISTS (SELECT * FROM [sysobjects] WHERE [type]='U' AND [name]='Max_UsersInRoles') BEGIN truncate table [bx_UserRoles]; UPDATE Max_Roles SET NewRoleID = @NewRoleID1 WHERE RoleID = 1; UPDATE Max_Roles SET NewRoleID = @NewRoleID2 WHERE RoleID = 2; UPDATE Max_Roles SET NewRoleID = @NewRoleID3 WHERE RoleID = 3; UPDATE Max_Roles SET NewRoleID = @NewRoleID5 WHERE RoleID = 5; INSERT INTO [bx_UserRoles] ([UserID] ,[RoleID] ,[BeginDate] ,[EndDate]) SELECT u.UserID,--(<UserID, int,> r.NewRoleID,--,<RoleID, uniqueidentifier,> u.EnabledDate,--,<BeginDate, datetime,> u.ExpiresDate--,<EndDate, datetime,>) FROM Max_UsersInRoles u WITH (NOLOCK) INNER JOIN Max_Roles r WITH (NOLOCK) ON u.RoleID = r.RoleID WHERE u.RoleID IN (1,2,3,5) OR u.RoleID > 8; DROP TABLE Max_UsersInRoles; END DROP TABLE Max_Roles; "; command.CommandTimeout = 3600; command.CommandText = sql; command.Parameters.AddWithValue("@NewRoleID1", Role.Owners.RoleID); command.Parameters.AddWithValue("@NewRoleID2", Role.Administrators.RoleID); command.Parameters.AddWithValue("@NewRoleID3", Role.SuperModerators.RoleID); command.Parameters.AddWithValue("@NewRoleID5", vipRoleID); SqlParameter param = new SqlParameter("@RolesString", SqlDbType.NText); param.Value = newRoles.GetValue(); command.Parameters.Add(param); command.ExecuteNonQuery(); } catch (Exception ex) { CreateLog(ex); throw new Exception("�����û�������ʧ��" + ex.Message + sql); } finally { connection.Close(); } } }
public RoleSettings() { string iconPath = Globals.GetRelativeUrl(SystemDirecotry.Assets_RoleIcon); Roles = new RoleCollection(); Roles.Add(Role.Everyone); Roles.Add(Role.Guests); Roles.Add(Role.Users); Roles.Add(Role.ForumBannedUsers); Roles.Add(Role.FullSiteBannedUsers); Roles.Add(Role.NewUsers); Roles.Add(Role.EmailNotProvedUsers); Roles.Add(Role.RealnameNotProvedUsers); //Roles.Add(Role.InviteLessUsers); Roles.Add(Role.JackarooModerators); Roles.Add(Role.Moderators); Roles.Add(Role.CategoryModerators); Roles.Add(Role.SuperModerators); Roles.Add(Role.Administrators); Roles.Add(Role.Owners); Roles.Add(Role.NoLevel); LevelLieOn = LevelLieOn.Post; /*-----------------------默认图标------------------------*/ Role.CategoryModerators.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips10.gif"); Role.Administrators.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips10.gif"); Role.SuperModerators.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips10.gif"); Role.Owners.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips10.gif"); Role.Moderators.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips9.gif"); Role.JackarooModerators.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips8.gif"); /*-------------------默认等级用户组------------------*/ Role levelRole = new Role(); levelRole.Name = "新手上路"; levelRole.RequiredPoint = 0; levelRole.RoleID = new Guid(new byte[] { 74, 115, 163, 71, 186, 53, 83, 71, 183, 179, 236, 16, 210, 32, 146, 103 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips1.gif"); levelRole.IsNew = false; Roles.Add(levelRole); levelRole = new Role(); levelRole.Name = "侠客"; levelRole.RequiredPoint = 50; levelRole.RoleID = new Guid(new byte[] { 248, 152, 64, 183, 181, 77, 53, 77, 182, 73, 89, 85, 162, 252, 146, 41 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips2.gif"); levelRole.IsNew = false; Roles.Add(levelRole); levelRole = new Role(); levelRole.Name = "圣骑士"; levelRole.RequiredPoint = 200; levelRole.RoleID = new Guid(new byte[] { 29, 40, 140, 204, 235, 17, 207, 73, 174, 43, 138, 98, 96, 82, 219, 68 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips3.gif"); levelRole.IsNew = false; Roles.Add(levelRole); levelRole = new Role(); levelRole.Name = "精灵"; levelRole.RequiredPoint = 500; levelRole.RoleID = new Guid(new byte[] { 26, 191, 38, 123, 38, 152, 103, 71, 171, 98, 16, 19, 63, 224, 29, 77 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips4.gif"); levelRole.IsNew = false; Roles.Add(levelRole); levelRole = new Role(); levelRole.Name = "精灵王"; levelRole.RequiredPoint = 1000; levelRole.RoleID = new Guid(new byte[] { 92, 96, 198, 205, 96, 80, 220, 66, 172, 38, 16, 150, 6, 184, 0, 251 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips5.gif"); levelRole.IsNew = false; Roles.Add(levelRole); levelRole = new Role(); levelRole.Name = "风云使者"; levelRole.RequiredPoint = 5000; levelRole.RoleID = new Guid(new byte[] { 165, 75, 133, 177, 234, 6, 16, 66, 162, 12, 235, 64, 5, 68, 248, 140 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips6.gif"); levelRole.IsNew = false; Roles.Add(levelRole); levelRole = new Role(); levelRole.Name = "光明使者"; levelRole.RequiredPoint = 10000; levelRole.RoleID = new Guid(new byte[] { 185, 185, 243, 95, 132, 73, 233, 67, 128, 221, 168, 188, 74, 206, 151, 196 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips7.gif"); levelRole.IsNew = false; Roles.Add(levelRole); levelRole = new Role(); levelRole.Name = "天使"; levelRole.RequiredPoint = 50000; levelRole.RoleID = new Guid(new byte[] { 164, 254, 210, 237, 225, 87, 214, 77, 171, 96, 92, 245, 221, 54, 78, 154 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips8.gif"); levelRole.IsNew = false; Roles.Add(levelRole); levelRole = new Role(); levelRole.Name = "法老"; levelRole.RequiredPoint = 100000; levelRole.RoleID = new Guid(new byte[] { 188, 159, 219, 20, 145, 63, 6, 67, 184, 52, 226, 115, 211, 207, 90, 98 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips9.gif"); levelRole.IsNew = false; Roles.Add(levelRole); /*-----------------------end-------------------------*/ Roles.Sort(); }
/// <summary> /// 获取指定条件的用户组(推荐使用匿名委托来指定条件) /// </summary> /// <param name="resolver"></param> /// <returns></returns> public RoleCollection GetRoles(RoleResolver resolver) { RoleCollection roles = new RoleCollection(); foreach (Role role in Roles) { if (resolver(role)) roles.Add(role); } return roles; }
/// <summary> /// 获取给后台作为自动加入的用户组列表。例如:作为任务奖励自动加入用户组,那么只能在这些用户组里面选择 /// </summary> /// <returns></returns> public RoleCollection GetRolesForAutoAdd() { RoleCollection roles = new RoleCollection(); foreach (Role r in Roles) { if ((r.Type & RoleType.Normal) == RoleType.Normal && (r.Type & RoleType.Virtual) != RoleType.Virtual && (r.Type & RoleType.System) != RoleType.System ) { roles.Add(r); } } return roles; }
/// <summary> /// 获取所有用户组,但排除掉指定的用户组 /// </summary> /// <param name="exceptRoleIds"></param> /// <returns></returns> public RoleCollection GetRoles(params Role[] exceptRoles) { RoleCollection roles = new RoleCollection(); foreach (Role role in Roles) { bool isExcept = false; foreach (Role exceptRole in exceptRoles) { if (role == exceptRole) { isExcept = true; break; } } if (isExcept == false) roles.Add(role); } return roles; }