private void getMatters() { try { using (SPWeb web = new SPSite(_sourceSiteUrl).OpenWeb()) { SPWebCollection allAccessibleMatters = web.GetSubwebsForCurrentUser(); foreach (SPWeb matter in allAccessibleMatters) { //TODO - Put all matters in one list, then use Datatables.net to sort them. if (matter.AllProperties.ContainsKey("LMUserID")) { if (matter.AllProperties["LMUserID"].ToString() == getUserId()) { addEntry(matter, true); } else { addEntry(matter, false); } } else { addEntry(matter, false, false); } } } } catch (Exception ex) { HandleException(ex); } }
/// <summary> /// Assembles a list of favorites sites for use in the MacroView Desktop Client. /// Currently this is only implemented for the Litigation Management Site, but may be /// extended in the future. /// Favorite Sites are assembled in the following Groups: /// * Assigned To Current User /// * Shared with Current User /// * Sites Pending Close (Deprecated due to archival process implemented 3/2017.) /// /// Generation of site objects is performed using the SPWeb.GetSubwebsForCurrentUser method. /// Note that this method will only return subwebs for one level deep. /// </summary> /// <param name="UserName"></param> /// <param name="SiteUrl"></param> /// <returns>An XmlDocument object for processing by the client</returns> public XmlDocument GetFavorites(string UserName, string SiteUrl) { config.webAppUrl = SiteUrl; config.currentUser = sAMAccountName(UserName); string mattersUrl = config.webAppUrl + config.siteCollectionUrl + config.mattersWeb; string projectsUrl = config.webAppUrl + config.siteCollectionUrl + config.projectsWeb; // TODO - Extend this method to other users beyond litigation management by // retrieving their parent site from a custom user property. // Create Empty Matter Group and Empty Project Groups to populate Group grpMyMatters = createGroup("Litigation Matters"); Group grpMyProjects = createGroup("Project Sites"); #region Logic: Create Litigation Matters Group // Open the Site which contains Litigation Matters and retrieve the webs for the current user // add each to the matters group. using (SPWeb matterRootWeb = new SPSite(mattersUrl).OpenWeb()) { // Check if Site Has a Configuration Property for Limit. If so, set it. If not, use the default value. int siteFavoriteLimit = 0; try { siteFavoriteLimit = (int)matterRootWeb.AllProperties["MacroView_Favorite_Limit"]; } catch { } if (siteFavoriteLimit > 0) { config.maxFavorites = siteFavoriteLimit; } // Get a collection which contains all sites the user has access to. SPWebCollection webs = matterRootWeb.GetSubwebsForCurrentUser(); // initialize Limit Counter int max = (config.maxFavorites), count = 0; foreach (SPWeb web in webs) { if (count >= max + 1) { count++; continue; } if (count == max) { truncateGroup(config, grpMyMatters, mattersUrl); count++; continue; } else { addFavorite(web, grpMyMatters, false, false, false); count++; } } } #endregion #region Logic: Create Project Sites Group // Open the Site which contains Litigation Projects and retrieve the webs for the current user // add each to the projects group. using (SPWeb projectRootWeb = new SPSite(projectsUrl).OpenWeb()) { // Check if Site Has a Configuration Property for Limit. If so, set it. If not, use the default value. int siteFavoriteLimit = 0; try { siteFavoriteLimit = (int)projectRootWeb.AllProperties["MacroView_Favorite_Limit"]; } catch { } if (siteFavoriteLimit > 0) { config.maxFavorites = siteFavoriteLimit; } // Get a collection which contains all sites the user has access to. SPWebCollection webs = projectRootWeb.GetSubwebsForCurrentUser(); // initialize Limit Counter int max = (config.maxFavorites), count = 0; foreach (SPWeb web in webs) { if (count >= max + 1) { count++; continue; } if (count == max) { truncateGroup(config, grpMyProjects, projectsUrl); count++; continue; } else { addFavorite(web, grpMyProjects, false, false, true); count++; } } } #endregion // Create wrapper list to hold groups which should be displayed. List <Group> Groups = new List <Group>(); Groups.Add(grpMyMatters); Groups.Add(grpMyProjects); // Sort and Sanitize the groups, then serialize the object as XML to the client. return(generateXml(sanitize(Groups))); }
public Models.WebDetails <object, object>[] getSubwebs() { List <Models.WebDetails <object, object> > subwebs = new List <Models.WebDetails <object, object> >(); using (SPWeb rootWeb = new SPSite(subwebsRequest.Url).OpenWeb()) { string[] excludedKeys = { }; // initialize as blank so checks don't bomb below. if (subwebsRequest.ExcludeKeysWhichContain != null && subwebsRequest.ExcludeKeysWhichContain.Length > 0) { excludedKeys = subwebsRequest.ExcludeKeysWhichContain.Select(s => s.ToLower()).ToArray(); } SPWebCollection collWebsite = rootWeb.GetSubwebsForCurrentUser(); int i = 0; // used for index value of site. foreach (SPWeb subSite in collWebsite) { if (i == subwebsRequest.ResultLimit) { break; //Stop iterating sites if a specified limit is reached. } // Check first if the site matches any specified request values. int matchesRequired = 0; try { matchesRequired = subwebsRequest.PropertyValueQuery.Count; } catch { } if (matchesRequired > 0) { int matchesFound = 0; foreach (DictionaryEntry property in subwebsRequest.PropertyValueQuery) { try { // get value of property from the current subsite string webPropertyValue = subSite.AllProperties[property.Key].ToString(); // create a list to allow for the possibility of multiple value specifications. List <string> requestedPropertyValues = new List <string>(); if (property.Value is string) { if (property.Key.ToString() == "Litigation_Manager") // manipulate a known name value to standard format. { requestedPropertyValues.Add(Util.standardizedName(property.Value.ToString())); webPropertyValue = Util.standardizedName(webPropertyValue); } else { requestedPropertyValues.Add(property.Value.ToString()); } } else { // cast the request as a JArray to allow for the possibility of a nested string array. JArray requestedPropertyValue = (JArray)property.Value; int valueIterator = 0; while (valueIterator <= requestedPropertyValue.Count - 1) { if (property.Key.ToString() == "Litigation_Manager") // manipulate a known name value to standard format. { requestedPropertyValues.Add(Util.standardizedName(requestedPropertyValue[valueIterator].ToString())); webPropertyValue = Util.standardizedName(webPropertyValue); } else { requestedPropertyValues.Add(requestedPropertyValue[valueIterator].ToString()); } valueIterator++; } } int innerMatchCount = 0; foreach (string val in requestedPropertyValues) { if (Util.stringsMatch(webPropertyValue, val, subwebsRequest.MatchCaseOnQueryValues)) { innerMatchCount++; } } if (innerMatchCount > 0) { matchesFound++; } else { break; // bomb out if property mismatch. Don't return this site. } } catch (Exception) { break; //swallow exception - key not found automatic no match. Don't return this site. Don't be that guy. } } if (matchesFound < matchesRequired) { continue; } } // Site matched values requested, or none were specified. Models.WebDetails <object, object> subweb = new Models.WebDetails <object, object>(); int performedExclusions = 0; subweb.Add("ID", i); subweb.Add("Url", subSite.Url); subweb.Add("Title", subSite.Title); subweb.Add("LastModified", subSite.LastItemModifiedDate); foreach (DictionaryEntry property in subSite.AllProperties) { string key = property.Key.ToString(); if (excludedKeys.Any((key.ToLower()).Contains)) { performedExclusions++; continue; } // Exclude properties per request. // properly format a known name field. switch (key) { case "Litigation_Manager": subweb[key] = Util.standardizedName(property.Value.ToString()); break; default: subweb[key] = property.Value; break; } } if (performedExclusions > 0) { subweb.Add("Warning", performedExclusions + " properties matching pattern(s) in client request were excluded."); } subwebs.Add(subweb); i++; } } return(subwebs.ToArray() as Models.WebDetails <object, object>[]); }