private static void BuildCreatables(ApplicationsLinkProvider applicationsLinkProvider, Creatables creatables, string webUrl, Guid webId) { foreach (NavLink navLink in applicationsLinkProvider.GetLinks().Cast <NavLink>() .Where(navLink => !string.IsNullOrEmpty(navLink.ObjectId))) { creatables.collection.Add(new Creatables.Creatable { id = navLink.ObjectId, name = navLink.Title, url = string.Format("{0}/{1}?action=new&webid={2}&listid={3}", webUrl, PROXY_URL, webId, navLink.ObjectId) }); } }
public Creatables GetCreatables() { var creatables = new Creatables(); try { SPWeb contextWeb = SPContext.Current.Web; var applicationsLinkProvider = new ApplicationsLinkProvider(SPContext.Current.Site.ID, contextWeb.ID, contextWeb.CurrentUser.LoginName); var reportingLists = new DataTable(); var tasks = new[] { Task.Factory.StartNew( () => BuildCreatables(applicationsLinkProvider, creatables, contextWeb.Url, contextWeb.ID)), Task.Factory.StartNew(() => GetReportingListLibs(reportingLists, contextWeb)) }; Task.WaitAll(tasks); var toRemove = new List <Creatables.Creatable>(); EnumerableRowCollection <DataRow> listLibs = reportingLists.AsEnumerable(); Parallel.ForEach(creatables.collection, c => { bool keep = false; foreach (DataRow row in Enumerable.Where(listLibs, row => row["Id"].ToString().ToLower().Equals(c.id.ToLower()) && !SEUtils.IsIgnoredList(c.name, contextWeb))) { keep = true; object icon = row["icon"]; if (icon != DBNull.Value && icon != null) { c.icon = icon as string; } break; } if (!keep) { toRemove.Add(c); } }); foreach (Creatables.Creatable creatable in toRemove.Distinct()) { creatables.collection.Remove(creatable); } } catch (Exception exception) { if (exception is AggregateException) { exception = ((AggregateException)exception).Flatten(); } creatables.error = new Error { message = exception.Message, stackTrace = exception.StackTrace, kind = typeof(Exception).ToString() }; } return(creatables); }