Ejemplo n.º 1
0
        private static ItemInfo GetItemInfo(SPListItem pageItem)
        {
            log.Enter();
            log.TraceInformation(string.Format("Getting item information for {0}", pageItem.ParentList.DefaultDisplayFormUrl + "?ID=" + pageItem.ID));

            ItemInfo item = null;
            try
            {
                item = new ItemInfo()
                {
                    SiteId = pageItem.Web.Site.ID.ToString(),
                    WebId = pageItem.Web.ID.ToString(),
                    ListId = pageItem.ParentList.ID.ToString(),
                    Id = pageItem.ID,
                    Title = string.IsNullOrEmpty(pageItem.Title) ? pageItem.File.Name : pageItem.Title,
                    Url = GetItemUrl(pageItem),
                    IsDraft = IsFileInDraft(pageItem) || IsItemPending(pageItem),
                    ScheduledToPublish = GetScheduledDate(pageItem),
                    ExpirationDate = GetExpirationDate(pageItem),
                    CheckedOutTo = GetFileCheckedOutBy(pageItem.File),
                    FileType = pageItem.ContentType.Id.ToString().Contains("0x0101") ? "Static" : "Dynamic"
                };

                GetVersionInfo(pageItem, item);
            }
            catch (Exception ex)
            {
                log.TraceException(ex);
                RecordLastException(ex);

                if (item == null)
                {
                    item = new ItemInfo()
                    {
                        Id = -1,
                        Title = pageItem.Title,
                        Url = pageItem.ParentList.DefaultDisplayFormUrl + "?ID=" + pageItem.ID,
                        LastError = GetLastException()
                    };
                }
            }

            log.Leave();
            return item;
        }
        public ItemInfo GetDraftAssets(string loc, string siteId, string webId, string listId, string itemId = "")
        {
            ItemInfo itemInfo = new ItemInfo();
            List<DraftAsset> assets = null;
            Dictionary<string, List<DynamicAsset>> dynamicAssets = null;

            DraftChecker.SetDiagnosticsCategory("CenterPoint Integrity Check");
            DraftChecker.Location = loc;

            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    if (!string.IsNullOrEmpty(siteId) && !string.IsNullOrEmpty(webId))
                    {
                        using (SPSite site = new SPSite(new Guid(siteId)))
                        {
                            using (SPWeb web = site.OpenWeb(new Guid(webId)))
                            {
                                if (PublishingWeb.IsPublishingWeb(web))
                                {
                                    PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);

                                    //Check if the pageId is integer ID or page name
                                    int id = 0;
                                    SPListItem pageItem = null;
                                    SPList list = web.Lists[new Guid(listId)];

                                    if (int.TryParse(itemId, out id))
                                    {
                                        pageItem = list.GetItemById(id);
                                    }
                                    else
                                    {
                                        SPFile file = web.GetFile(SPUtility.ConcatUrls(pubWeb.PagesListName, itemId));
                                        if (file != null)
                                        {
                                            pageItem = file.Item;
                                        }
                                    }
                                    //Scan and return draft items referenced on the page
                                    assets = DraftChecker.GetDraftContent(site, pageItem);

                                    //Scan and return unapproved dynamic items
                                    dynamicAssets = DraftChecker.GetUnapprovedItems(site, pageItem);

                                    itemInfo.Url = SPUtility.ConcatUrls(web.ServerRelativeUrl, pageItem.Url);
                                    itemInfo.Title = pageItem.Title;
                                    itemInfo.Id = pageItem.ID;
                                    itemInfo.DraftAssets = assets;
                                    itemInfo.DynamicAssets = dynamicAssets;
                                    itemInfo.LastError = DraftChecker.GetLastException();
                                }
                            }
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                Recorder.Logger.TraceException(ex);
                itemInfo.LastError = ex.Message;
            }
            return itemInfo;
        }
Ejemplo n.º 3
0
        internal static List<ItemInfo> GetItems(SPWeb web, string listId, string[] itemIds)
        {
            log.Enter();
            List<ItemInfo> pages = new List<ItemInfo>();
            int id = 0;
            ItemInfo itemInfo = null;

            try
            {
                log.TraceInformation("Getting list: " + listId);
                SPList list = web.Lists[new Guid(listId)];
                log.TraceInformation("Error getting list: " + listId);

                if (list != null)
                {
                    foreach (string itemId in itemIds)
                    {
                        if (int.TryParse(itemId, out id))
                        {
                            SPQuery query = new SPQuery();
                            query.Query = "<Where><Eq><FieldRef Name=\"ID\"></FieldRef><Value Type=\"Integer\">" + id.ToString(CultureInfo.InvariantCulture) + "</Value></Eq></Where>";
                            query.ViewFields = string.Concat(
                                           "<FieldRef Name='ID' />",
                                           "<FieldRef Name='Title' />",
                                           "<FieldRef Name='" + list.Fields.GetField(Constants.FieldNames.ApprovalStatus).InternalName + "'/>",
                                           "<FieldRef Name='" + list.Fields.GetField(Constants.FieldNames.ScheduledStartDate).InternalName + "'/>",
                                           "<FieldRef Name='" + list.Fields.GetField(Constants.FieldNames.ScheduledEndDate).InternalName + "'/>",
                                           "<FieldRef Name='" + list.Fields.GetField(Constants.FieldNames.ContentType).InternalName + "'/>",
                                           "<FieldRef Name='" + list.Fields.GetField(Constants.FieldNames.Expiration).InternalName + "'/>",
                                           "<FieldRef Name='" + list.Fields.GetField(Constants.FieldNames.Audience).InternalName + "'/>",
                                           "<FieldRef Name='" + list.Fields.GetField(Constants.FieldNames.ServiceArea).InternalName + "'/>",
                                           "<FieldRef Name='LinkTitle' />");
                            query.ViewAttributes = "Scope=\"RecursiveAll\"";

                            log.TraceInformation("Getting item with query: " + query.Query);

                            SPListItem pageItem = null;

                            SPListItemCollection items = list.GetItems(query);
                            if (items != null && items.Count > 0)
                            {
                                pageItem = items[0];
                                itemInfo = GetItemInfo(pageItem);
                            }
                            else
                            {
                                itemInfo = new ItemInfo()
                                {
                                    Id = -1,
                                    Title = "Content not found",
                                    Url = list.DefaultDisplayFormUrl + "?ID=" + id,
                                    LastError = "Possible reason: Content might have been rejected by the approver."
                                };
                            }
                        }
                        pages.Add(itemInfo);
                    }
                }
            }
            catch (Exception ex)
            {
                log.TraceException(ex);
                RecordLastException(ex);
                itemInfo = new ItemInfo()
                {
                    Id = -1,
                    Title = "Content not found.",
                    Url = "List Id = " + listId + " ID = " + id,
                    LastError = ex.Message
                };
                pages.Add(itemInfo);
            }

            log.Leave();
            return pages;
        }