private Tuple <string, string, string, string, bool>[] GetWorkspaceActions(SPListItem li, out Dictionary <string, string> di) { bool success = true; di = new Dictionary <string, string> { { "Workspace Actions", true.ToString() } }; var actions = new List <Tuple <string, string, string, string, bool> >(); try { string url = string.Empty; try { url = li["WorkspaceUrl"].ToString(); } catch { } actions.Add(AT("Go To Workspace", "workspace", "/_layouts/images/STSICON.gif", !string.IsNullOrEmpty(url), "1")); string childitem = string.Empty; try { childitem = li["ChildItem"].ToString(); } catch { } bool allowed = ListCommands.GetGridGanttSettings(li.ParentList).EnableRequests&& string.IsNullOrEmpty(url) && (li.ModerationInformation == null || li.ModerationInformation.Status == SPModerationStatusType.Approved) && li.Web.ID == _spWeb.ID && string.IsNullOrEmpty(childitem); actions.Add(AT("Create Workspace", "createworkspace", "/_layouts/images/STSICON.gif", allowed, "1")); } catch (Exception e) { success = false; di.Add("Workspace Actions Exception", e.Message); } di.Add("Workspace Actions Success", success.ToString()); return(actions.ToArray()); }
public DataTable GetMenuItems(Guid siteId, Guid webId, Guid listId, int itemId, int userId, out Dictionary <string, string> diagnosticInfo) { var info = new Dictionary <string, string>(); var dataTable = new DataTable(); dataTable.Columns.Add("Title", typeof(string)); dataTable.Columns.Add("Command", typeof(string)); dataTable.Columns.Add("ImageUrl", typeof(string)); dataTable.Columns.Add("Kind", typeof(string)); SPSecurity.RunWithElevatedPrivileges(() => { using (var site = new SPSite(siteId)) { using (SPWeb web = site.OpenWeb(webId)) { info.Add("Web", web.Url); SPUser user = web.AllUsers.GetByID(userId); SPUserToken userToken = user.UserToken; info.Add("Username", user.LoginName); info.Add("User", user.Name); Task <object[]> t1 = Task.Factory.StartNew(() => { Dictionary <string, string> di; var result = new Tuple <string, string, string, string, bool>[] { }; try { using (var spSite = new SPSite(siteId, userToken)) { using (SPWeb spWeb = spSite.OpenWeb(webId)) { SPList list = spWeb.Lists.GetList(listId, true); GridGanttSettings gSettings = ListCommands.GetGridGanttSettings(list); result = GetGeneralActions(gSettings.UsePopup, list, gSettings.EnableFancyForms, out di); } } } catch (Exception e) { di = new Dictionary <string, string> { { "General Actions Exception", e.Message } }; } return(new object[] { result, di }); }); Task <object[]> t2 = Task.Factory.StartNew(() => { Dictionary <string, string> di; var result = new Tuple <string, string, string, string, bool>[] { }; try { using (var spSite = new SPSite(siteId, userToken)) { using (SPWeb spWeb = spSite.OpenWeb(webId)) { SPList list = spWeb.Lists.GetList(listId, true); result = GetPlannerActions(list, out di); } } } catch (Exception e) { di = new Dictionary <string, string> { { "Planner Actions Exception", e.Message } }; } return(new object[] { result, di }); }); Task <object[]> t3 = Task.Factory.StartNew(() => { Dictionary <string, string> di; var result = new Tuple <string, string, string, string, bool>[] { }; try { using (var spSite = new SPSite(siteId, userToken)) { using (SPWeb spWeb = spSite.OpenWeb(webId)) { SPList list = spWeb.Lists.GetList(listId, true); SPListItem item = list.GetItemById(itemId); result = GetSocialActions(item, ListCommands.GetGridGanttSettings(list), out di); } } } catch (Exception e) { di = new Dictionary <string, string> { { "Social Actions Exception", e.Message } }; } return(new object[] { result, di }); }); Task <object[]> t4 = Task.Factory.StartNew(() => { Dictionary <string, string> di; var result = new Tuple <string, string, string, string, bool>[] { }; try { using (var spSite = new SPSite(siteId, userToken)) { using (SPWeb spWeb = spSite.OpenWeb(webId)) { SPList list = spWeb.Lists.GetList(listId, true); SPListItem item = list.GetItemById(itemId); result = GetWorkspaceActions(item, out di); } } } catch (Exception e) { di = new Dictionary <string, string> { { "Workspace Actions Exception", e.Message } }; } return(new object[] { result, di }); }); Task <object[]> t5 = Task.Factory.StartNew(() => { Dictionary <string, string> di; var result = new Tuple <string, string, string, string, bool>[] { }; try { using (var spSite = new SPSite(siteId, userToken)) { using (SPWeb spWeb = spSite.OpenWeb(webId)) { SPList list = spWeb.Lists.GetList(listId, true); result = GetPFEActions(list, out di); } } } catch (Exception e) { di = new Dictionary <string, string> { { "PFE Actions Exception", e.Message } }; } return(new object[] { result, di }); }); var actions = new List <Tuple <string, string, string, string, bool> >(); foreach (var t in new[] { t1, t2, t3, t4, t5 }) { object[] result = t.Result; var et = new Tuple <string, string, string, string, bool>(null, null, null, null, false); var tuples = (Tuple <string, string, string, string, bool>[])(result[0] ?? new[] { et }); actions.AddRange(tuples); var di = result[1] as Dictionary <string, string>; if (di == null) { continue; } foreach (var pair in di) { info.Add(pair.Key, pair.Value); } } if (!actions.Any()) { return; } string lastTitle = string.Empty; Tuple <string, string, string, string, bool> lastAction = actions.Last(); string sepItem = lastAction.Item1; if (!string.IsNullOrEmpty(sepItem) && sepItem.Equals("--SEP--")) { actions.Remove(lastAction); } foreach (var action in actions) { if (!action.Item5) { continue; } if (action.Item1.Equals("--SEP--") && action.Item1.Equals(lastTitle)) { continue; } lastTitle = action.Item1; DataRow row = dataTable.NewRow(); row["Title"] = action.Item1; row["Command"] = action.Item2; row["ImageUrl"] = action.Item3; row["Kind"] = action.Item4; dataTable.Rows.Add(row); } } } }); diagnosticInfo = info; return(dataTable); }