internal static void SetMembership(SecurityContext context, string src) { // "U1:G1,G2|U2:G1" var membership = context.Cache.Membership; membership.Clear(); foreach (var userRecord in src.Split('|')) { var ur = userRecord.Split(':'); var userName = ur[0].Substring(1); var userId = TestUser.GetId(byte.Parse(userName)); var groupIds = ur[1].Split(',').Select(x => TestGroup.GetId(byte.Parse(x.Substring(1)))).ToList(); membership.Add(userId, groupIds); } }
public static int GetId(string name) { if (name[0] == 'G') { return(TestGroup.GetId(byte.Parse(name.Substring(1)))); } if (name[0] == 'U') { return(TestUser.GetId(byte.Parse(name.Substring(1)))); } if (name[0] == 'E') { return(TestEntity.GetId(byte.Parse(name.Substring(1)))); } throw new NotSupportedException("Invalid name: " + name); }