コード例 #1
0
        public override bool Perform()
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(() =>
                {
                    using (var spSite = new SPSite(Web.Site.ID))
                    {
                        using (SPWeb spWeb = spSite.OpenWeb())
                        {
                            LogTitle(GetWebInfo(spWeb), 1);

                            SPList spList = spWeb.Lists.TryGetList(LIST_NAME);

                            if (spList == null)
                            {
                                LogMessage("Downloading new " + LIST_NAME + " list", 2);

                                var catalog =
                                    (SPDocumentLibrary)Web.Site.GetCatalog(SPListTemplateType.ListTemplateCatalog);

                                const string TEMPLATE_NAME = LIST_NAME + " [5.5]";

                                using (var webClient = new WebClient())
                                {
                                    byte[] bytes =
                                        webClient.DownloadData(_storeUrl + "/Upgrade/" + LIST_NAME.ToLower() + ".stp");
                                    SPFile file   = catalog.RootFolder.Files.Add(LIST_NAME + "_55.stp", bytes, true);
                                    SPListItem li = file.GetListItem();
                                    li["Title"]   = TEMPLATE_NAME;
                                    li.SystemUpdate();
                                }

                                LogMessage("Creating the " + LIST_NAME + " list", 2);

                                SPListTemplateCollection listTemplates = spSite.GetCustomListTemplates(spWeb);
                                SPListTemplate template = listTemplates[TEMPLATE_NAME];

                                spWeb.Lists.Add(LIST_NAME, string.Empty, template);

                                SPList list = spWeb.Lists[LIST_NAME];
                                list.Title  = LIST_NAME;
                                list.Hidden = true;
                                list.Update();

                                LogMessage("Adding reporting groups", 2);

                                SPGroup owner = spWeb.SiteGroups["Administrators"];
                                SPUser user   = spWeb.CurrentUser;

                                AddGroup(spWeb, owner, user, "Report Viewers");
                                AddGroup(spWeb, owner, user, "Report Writers");

                                LogMessage("Processing reports", 2);

                                string error;
                                Reporting.ProcessIzendaReportsFromList(list, out error);

                                if (!string.IsNullOrEmpty(error))
                                {
                                    LogMessage(error, MessageKind.FAILURE, 3);
                                }
                                else
                                {
                                    LogMessage(null, MessageKind.SUCCESS, 3);
                                }

                                LogMessage("Updating Navigation link", 2);

                                string relativeUrl = spWeb.ServerRelativeUrl.ToLower();
                                string newUrl      = relativeUrl + "/_layouts/15/epmlive/reporting/landing.aspx";

                                SPList lst = spWeb.Lists.TryGetList("Installed Applications");
                                if (lst != null)
                                {
                                    var qry = new SPQuery
                                    {
                                        Query      = @"<Where><IsNotNull><FieldRef Name='QuickLaunch' /></IsNotNull></Where>",
                                        ViewFields = @"<FieldRef Name='QuickLaunch' />"
                                    };

                                    SPListItemCollection listItems = lst.GetItems(qry);

                                    foreach (SPListItem item in listItems)
                                    {
                                        foreach (SPNavigationNode navNode in
                                                 from node in item["QuickLaunch"].ToString().Split(',')
                                                 select Convert.ToInt32(node.Split(':')[0])
                                                 into i
                                                 select spWeb.Navigation.GetNodeById(i)
                                                 into navNode
                                                 where navNode != null
                                                 let url = navNode.Url.ToLower()
                                                           where
                                                           url.EndsWith(relativeUrl + "/reports.aspx") ||
                                                           url.EndsWith(relativeUrl + "/sitepages/report.aspx")
                                                           select navNode)
                                        {
                                            string message;
                                            MessageKind messageKind;

                                            UpgradeUtilities.UpdateNodeLink(newUrl, item.ID, navNode, spWeb, out message,
                                                                            out messageKind);

                                            LogMessage(message, messageKind, 3);
                                        }
                                    }
                                }
                                else
                                {
                                    LogMessage("The list Installed Applications does not exists.", MessageKind.FAILURE,
                                               3);
                                }

                                CacheStore.Current.RemoveSafely(spWeb.Url, new CacheStoreCategory(spWeb).Navigation);
                            }
                            else
                            {
                                LogMessage("Advance reporting is already configured.", MessageKind.SKIPPED, 2);
                            }
                        }
                    }
                });
            }
            catch (Exception e)
            {
                LogMessage(e.Message, MessageKind.FAILURE, 2);
            }

            return(true);
        }
コード例 #2
0
        public override bool Perform()
        {
            try
            {
                using (var spSite = new SPSite(Web.Site.ID))
                {
                    using (SPWeb spWeb = spSite.OpenWeb())
                    {
                        LogTitle(GetWebInfo(spWeb), 1);

                        SPList spList = spWeb.Lists.TryGetList("Installed Applications");
                        if (spList != null)
                        {
                            var qry = new SPQuery
                            {
                                Query =
                                    @"<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>My Workplace</Value></Eq></Where>",
                                ViewFields = @"<FieldRef Name='ID' />"
                            };

                            SPListItemCollection listItems = spList.GetItems(qry);

                            if (listItems.Count != 0)
                            {
                                try
                                {
                                    LogTitle("Changing My Workplace to Global My Workplace", 2);

                                    SPListItem item = spList.GetItemById(listItems[0].ID);

                                    item["Title"]    = "Global My Workplace";
                                    item["HomePage"] = new SPFieldUrlValue
                                    {
                                        Url         = spWeb.Url + "/SitePages/GlobalMyWorkplace.aspx",
                                        Description = "Global My Workplace"
                                    };

                                    item.SystemUpdate();

                                    LogTitle("Updating links", 2);

                                    string[] nodes = ((item["QuickLaunch"] ?? string.Empty).ToString()).Split(',');

                                    if (nodes.Any())
                                    {
                                        foreach (string nodeId in nodes)
                                        {
                                            try
                                            {
                                                string      message;
                                                MessageKind messageKind;

                                                int id = Convert.ToInt32(nodeId.Split(':')[0]);
                                                SPNavigationNode node = spWeb.Navigation.GetNodeById(id);

                                                if (node == null)
                                                {
                                                    continue;
                                                }

                                                if (node.Title.Equals("My Work"))
                                                {
                                                    string url = spWeb.ServerRelativeUrl +
                                                                 "/_layouts/15/epmlive/MyWork.aspx";

                                                    if (url.ToLower().Equals(node.Url.ToLower()))
                                                    {
                                                        continue;
                                                    }

                                                    UpgradeUtilities.UpdateNodeLink(url, item.ID, node, spWeb,
                                                                                    out message, out messageKind);

                                                    LogMessage(message, messageKind, 3);
                                                }
                                                else if (node.Title.Equals("Timesheet"))
                                                {
                                                    string url = spWeb.ServerRelativeUrl +
                                                                 "/_layouts/15/epmlive/MyTimesheet.aspx";

                                                    if (url.ToLower().Equals(node.Url.ToLower()))
                                                    {
                                                        continue;
                                                    }

                                                    UpgradeUtilities.UpdateNodeLink(url, item.ID, node, spWeb,
                                                                                    out message, out messageKind);

                                                    LogMessage(message, messageKind, 3);
                                                }
                                            }
                                            catch (Exception e)
                                            {
                                                LogMessage(e.Message, MessageKind.FAILURE, 3);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        LogMessage("No navigation nodes were found.", MessageKind.FAILURE, 3);
                                    }

                                    CacheStore.Current.RemoveSafely(spWeb.Url, new CacheStoreCategory(spWeb).Navigation);
                                }
                                catch (Exception e)
                                {
                                    LogMessage(e.Message, MessageKind.FAILURE, 3);
                                }
                            }
                            else
                            {
                                LogMessage("The My Workplace community was not found.", MessageKind.SKIPPED, 2);
                            }
                        }
                        else
                        {
                            LogMessage("The list Installed Applications does not exists.", MessageKind.FAILURE, 2);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogMessage(e.Message, MessageKind.FAILURE, 2);
            }

            return(true);
        }