public static void ResetState() { TopSecurableObject = new SPSecurableObject(); bgwWorker = null; TotalWebCount = 0; CurrentWebCount = 0; StackCount = 0; BranchCount = 0; bAnalyzeListItems = false; bGetFullPermissionStructure = false; spSiteGroups = null; spSiteUsers = null; }
public object Clone() { SPSiteUsers cloneObject = (SPSiteUsers)this.MemberwiseClone(); cloneObject.SiteUsers = new List <SPUser>(); for (int i = 0; i < this.SiteUsers.Count; i++) { cloneObject.SiteUsers.Add((SPUser)this.SiteUsers[i].Clone()); } return(cloneObject); }
/// <summary> /// Preloads site groups and users /// </summary> /// <param name="Context">Client context</param> private static void LoadSiteGroups(ClientContext Context) { RaiseStatusUpdate("Preloading: Initiating", UpdateType.StatusUpdateOnly); spSiteGroups = new SPSiteGroups(); spSiteGroups.SiteGroups = new List <SPGroup>(); spSiteUsers = new SPSiteUsers(); spSiteUsers.SiteUsers = new List <SPUser>(); Site site = Context.Site; Web web = site.RootWeb; GroupCollection siteGroups = web.SiteGroups; Context.Load(site); Context.Load(web); Context.Load(siteGroups); Context.ExecuteQuery(); RaiseStatusUpdate("Preloading: Site Groups", UpdateType.StatusUpdateOnly); // Populate spSiteGroups object with all site groups foreach (Group group in siteGroups) { Context.Load(group); Context.Load(group.Users); Context.ExecuteQuery(); SPGroup spGroup = new SPGroup(); spGroup.GroupName = group.Title; spGroup.Users = new List <SPUser>(); RaiseStatusUpdate("Preloading: Group " + group.LoginName, UpdateType.StatusUpdateOnly); foreach (User usr in group.Users) { SPUser spUser = new SPUser { DisplayName = usr.Title, Email = usr.Email, LoginId = usr.LoginName }; spGroup.Users.Add(spUser); } spSiteGroups.SiteGroups.Add(spGroup); RaiseStatusUpdate("Preloading: Finished", UpdateType.StatusUpdateOnly); } RaiseStatusUpdate("Preloading: Finished Loading Site Groups", UpdateType.StatusUpdateOnly); RaiseStatusUpdate("Preloading: Site Users", UpdateType.StatusUpdateOnly); // Populate spSiteUsers object with all site users List userList = web.SiteUserInfoList; Context.Load(userList); CamlQuery query = new CamlQuery(); query.ViewXml = "<View><Query><Where><Eq><FieldRef Name='ContentType'/><Value Type='Text'>Person</Value></Eq></Where></Query></View>"; ListItemCollection collection = userList.GetItems(query); Context.Load(collection, pj => pj.Include( p => p["Name"], p => p["Title"], p => p["EMail"], p => p["IsSiteAdmin"], p => p["IsActive"])); Context.ExecuteQuery(); foreach (ListItem item in collection) { string loginId = (item["Name"] != null) ? item["Name"].ToString() : string.Empty; string displayName = (item["Title"] != null) ? item["Title"].ToString() : loginId; string email = (item["EMail"] != null) ? item["EMail"].ToString() : string.Empty; SPUser usr = new SPUser { DisplayName = displayName, Email = email, LoginId = loginId }; spSiteUsers.SiteUsers.Add(usr); } RaiseStatusUpdate("Preloading: Finished Loading Site Users", UpdateType.StatusUpdateOnly); RaiseStatusUpdate("Preloading Finished, Initiating main processing", UpdateType.StatusUpdateOnly); }