Exemplo n.º 1
0
 private static DynamicAsset GetDynamicAssetFromDraftAsset(DraftAsset asset, SPListItem item)
 {
     return new DynamicAsset()
     {
         IsInternal = asset.IsInternal,
         SiteId = asset.SiteId,
         WebId = asset.WebId,
         ListId = item.ParentList.ID.ToString(),
         ItemId = item.ID,
         Title = asset.Title,
         Url = asset.Url,
         FileType = asset.FileType,
         IsDraft = asset.IsDraft,
         ScheduledToPublish = asset.ScheduledToPublish,
         ExpirationDate = asset.ExpirationDate
     };
 }
Exemplo n.º 2
0
        private static DraftAsset GetDraftAssetFromFile(SPFile file, DraftAsset asset)
        {
            if (ValidateFile(file))
            {
                if (file != null && file.Exists)
                {
                    asset.IsDraft = GetFilePublishingStatus(file);
                    asset.CheckedOutTo = GetFileCheckedOutBy(file);
                    //do not process draft files
                    if (!asset.IsDraft)
                        return null;

                    GetVersionInfo(file.Item, asset);
                    asset.ScheduledToPublish = GetScheduledDate(file.Item);
                    asset.ExpirationDate = GetExpirationDate(file.Item);
                    asset.Title = string.IsNullOrEmpty(file.Title) ? file.Name : file.Title;
                    switch (file.Item.ContentType.Name)
                    {
                        case "Page":
                        case "Article Page":
                        case "Welcome Page":
                        case "CNP Page":
                        case "CNP Article Page":
                        case "Catalog-Item Reuse":
                            asset.FileType = "Linked Page";
                            break;
                        default:
                            asset.FileType = file.Item.ContentType.Name;
                            break;
                    }
                    asset.SiteId = file.Web.Site.ID.ToString();
                    asset.WebId = file.Web.ID.ToString();

                    log.TraceInformation(string.Format("File ({0}) | Draft: {1} | Published: {2} | Content Type: {3}", asset.Url, asset.DraftVersion, asset.LastPublishedVersion, file.Item.ContentType.Name));
                }
            }
            else
                asset = null;

            return asset;
        }
Exemplo n.º 3
0
        private static List<DraftAsset> GetDraftContent(SPSite site, Hashtable links)
        {
            log.Enter();
            List<DraftAsset> assets = null;

            if (links.ContainsValue(true))
            {
                assets = new List<DraftAsset>();
                log.TraceInformation(string.Format("Looking for draft content"));

                foreach (DictionaryEntry entry in links)
                {
                    if ((bool)entry.Value == true)
                    {
                        string linkUrl = HttpUtility.HtmlDecode(entry.Key.ToString());
                        Uri originalUri = new Uri(linkUrl, UriKind.RelativeOrAbsolute);
                        DraftAsset asset = null;
                        if (!(originalUri.ToString().Contains('~') || originalUri.ToString().Contains("/_catalogs")))
                        {
                            if (originalUri.IsAbsoluteUri)
                            {
                                if (originalUri.PathAndQuery != "/")
                                {
                                    try
                                    {
                                        //Handle external URLs
                                        if (!originalUri.GetLeftPart(UriPartial.Authority).ToLower().Contains(Utility.GetPublishingUrl(site)))
                                        {
                                            log.TraceInformation(string.Format("Extenal valid link found (ignoring): {0}", originalUri));
                                        }
                                        else
                                        {
                                            if (originalUri.ToString().ToLower().Contains("fixupredirect.aspx"))
                                            {
                                                string qry = originalUri.Query.Substring(1);
                                                System.Collections.Specialized.NameValueCollection parameters = HttpUtility.ParseQueryString(qry);
                                                string termId = parameters["termid"];

                                                TaxonomySession session = new TaxonomySession(site, true);
                                                Term term = session.GetTerm(new Guid(termId));
                                                string url = "";
                                                if (term != null)
                                                {
                                                    if (term.LocalCustomProperties != null && term.LocalCustomProperties.Count > 0)
                                                    {
                                                        if (term.LocalCustomProperties.ContainsKey("_Sys_Nav_TargetUrl"))
                                                        {
                                                            term.LocalCustomProperties.TryGetValue("_Sys_Nav_TargetUrl", out url);
                                                            originalUri = new Uri(new Uri(Utility.GetPublishingUrl(site)), url);
                                                        }
                                                    }
                                                }
                                            }

                                            using (SPSite externalSite = new SPSite(originalUri.ToString()))
                                            {
                                                using (SPWeb web = externalSite.OpenWeb())
                                                {
                                                    string relativePathWithoutQueryParams = string.Format("/{0}",originalUri.GetComponents(UriComponents.Path, UriFormat.UriEscaped));
                                                    SPFile file = web.GetFile(relativePathWithoutQueryParams);
                                                    //If file does not exist at this url then check if file is a friendly URL of a publishing page
                                                    if (file == null || !file.Exists)
                                                    {
                                                        //Get physical publishing page URL from friendly url
                                                        file = GetFileFromFriendlyUrl(web, originalUri);
                                                    }

                                                    if (file != null && file.Exists)
                                                    {
                                                        asset = new DraftAsset();
                                                        asset.IsInternal = true;
                                                        asset.Url = file.ServerRelativeUrl;
                                                        asset = GetDraftAssetFromFile(file, asset);

                                                        if (asset != null && asset.FileType == "Linked Page")
                                                        {
                                                            //asset.Assets = GetDraftContent(externalSite, file.Item);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        asset = new DraftAsset();
                                                        asset.Url = originalUri.ToString();
                                                        asset.LastError = GetLastException();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        log.TraceException(ex, "SharePoint site does not exist");
                                        RecordLastException(ex);
                                        if (asset == null)
                                        {
                                            asset = new DraftAsset();
                                            asset.Url = originalUri.ToString();
                                        }
                                        asset.LastError = GetLastException();
                                    }

                                    if (asset != null)
                                    {
                                        assets.Add(asset);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            log.Leave();
            return assets;
        }
Exemplo n.º 4
0
 private static List<DraftAsset> GetContentFromForwardedLinks(SPSite site, SPListItem pageItem, Dictionary<string, string> itemProcessed)
 {
     List<DraftAsset> assets = new List<DraftAsset>();
     foreach (SPLink link in pageItem.ForwardLinks)
     {
         if (!(link.Url.Contains('~') || link.Url.Contains("/_catalogs")))
         {
             var asset = new DraftAsset()
             {
                 IsBroken = link.IsInternal && link.IsBroken,
                 Url = (link.IsInternal) ? link.ServerRelativeUrl: link.Url,
                 IsInternal = link.IsInternal
             };
             if (!link.IsToFolder)
             {
                 if (link.WebId != Guid.Empty)
                 {
                     using (var targetWeb = site.OpenWeb(link.WebId))
                     {
                         if (!link.IsBroken)
                         {
                             SPFile file = (link.IsInternal) ? targetWeb.GetFile(link.ServerRelativeUrl) : targetWeb.GetFile(link.Url);
                             asset = GetDraftAssetFromFile(file, asset);
                         }
                     }
                 }
             }
             if (asset != null && asset.IsDraft && !itemProcessed.ContainsKey(link.ServerRelativeUrl.ToLower()))
             {
                 assets.Add(asset);
                 itemProcessed.Add(link.ServerRelativeUrl.ToLower(), asset.Title);
             }
         }
     }
     return assets;
 }