public object ComputeFieldValue(Sitecore.ContentSearch.IIndexable indexable)
        {
            var item = IndexingUtility.ValidIndexableItem(indexable, this);

            if (item == null)
            {
                return(null);
            }

            string documentPath = null;

            Sitecore.Data.Fields.FileField fileField = item.GetField(Constants.Documents.Templates.DocumentBase.Sections.Document.Name, Constants.Documents.Templates.DocumentBase.Sections.Document.Fields.File);

            if (fileField != null && fileField.MediaItem != null)
            {
                documentPath = item.GetImageURL(Constants.Documents.Templates.DocumentBase.Sections.Document.Name, Constants.Documents.Templates.DocumentBase.Sections.Document.Fields.File, string.Empty);
                // Sitecore incremental re-indexing issue on retrieving media url that could include the /sitecore/shell prefix string before the correct relative URL.
                if (documentPath.IndexOf("/~/") > 0)
                {
                    Sitecore.Diagnostics.Log.Warn("Indexing Media Url for item [" + item.Paths.FullPath + "] returns incorrect Url. Trimming incorrect parts: from [" + documentPath + "] to [" + documentPath.Substring(documentPath.IndexOf("/~/")) + "]", this);
                    documentPath = documentPath.Substring(documentPath.IndexOf("/~/"));
                }
            }

            return(documentPath);
        }
Exemple #2
0
 public static Sitecore.Data.Fields.FileField getFileField(Item parentItem, string fieldName)
 {
     try
     {
         Sitecore.Data.Fields.FileField iFld = parentItem.Fields[fieldName];
         return(iFld);
     }
     catch { return(null); }
 }
        private bool mapMediaItemToSharedContent(Sitecore.Data.Database database, Item allocationItem, string title, MediaItem mediaItem, out ID itemId)
        {
            bool bOk = false;

            itemId = null;

            try
            {
                Item docs = allocationItem.Children["Documents"];
                if (docs == null)
                {
                    Sitecore.Data.Items.TemplateItem docsTemplateItem = database.GetItem("/sitecore/templates/Genworth/Folder Types/Investment Folders/Investment Document Folder");
                    docs = allocationItem.Add("Documents", docsTemplateItem);
                }

                Item performanceItem = docs.Children[title];
                if (performanceItem == null)
                {
                    Sitecore.Data.Items.TemplateItem performanceTemplateItem = database.GetItem("/sitecore/templates/Genworth/Document Types/Investments/Portfolio Information/Monthly Strategist Performance Report");
                    performanceItem = docs.Add(title, performanceTemplateItem);
                }

                itemId = performanceItem.ID;

                using (new Sitecore.SecurityModel.SecurityDisabler())
                {
                    performanceItem.Editing.BeginEdit();

                    Sitecore.Data.Fields.FileField fileField = performanceItem.Fields["File"];
                    fileField.MediaID = mediaItem.ID;
                    fileField.Src     = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem);

                    if (dictCategories.ContainsKey("Performance"))
                    {
                        performanceItem["Category"] = dictCategories["Performance"].ToString();
                    }

                    if (dictSources.ContainsKey("AssetMark"))
                    {
                        performanceItem["Source"] = dictSources["AssetMark"].ToString();
                    }

                    performanceItem["Date"] = Sitecore.DateUtil.ToIsoDate(DateTime.Now);

                    performanceItem.Editing.EndEdit();
                }

                bOk = true;
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Genworth.SitecoreExt.Importers.MonthlyPerformanceImporter:mapMediaItemToSharedContent, allocation: {1}, title {2}, exception: {3}", allocationItem["Title"], title, ex.ToString()), this);
            }

            return(bOk);
        }
        private bool mapMediaItemToSharedContent(Sitecore.Data.Database database, Item managerItem, string title, MediaItem mediaItem)
        {
            bool bOk = false;

            try
            {
                Item docs = managerItem.Children["Documents"];
                if (docs == null)
                {
                    Sitecore.Data.Items.TemplateItem docsTemplateItem = database.GetItem("/sitecore/templates/Genworth/Folder Types/Investment Folders/Investment Document Folder");
                    docs = managerItem.Add("Documents", docsTemplateItem);
                }

                Item commentaryItem = docs.Children[title];
                if (commentaryItem == null)
                {
                    Sitecore.Data.Items.TemplateItem commentaryTemplateItem = database.GetItem("/sitecore/templates/Genworth/Document Types/Investments/Product Commentary/Product Commentary");
                    commentaryItem = docs.Add(title, commentaryTemplateItem);
                }

                using (new Sitecore.SecurityModel.SecurityDisabler())
                {
                    commentaryItem.Editing.BeginEdit();

                    Sitecore.Data.Fields.FileField fileField = commentaryItem.Fields["File"];
                    fileField.MediaID = mediaItem.ID;
                    fileField.Src     = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem);

                    if (dictCategories.ContainsKey("Commentary"))
                    {
                        commentaryItem["Category"] = dictCategories["Commentary"].ToString();
                    }

                    if (dictSources.ContainsKey("AssetMark"))
                    {
                        commentaryItem["Source"] = dictSources["AssetMark"].ToString();
                    }

                    commentaryItem["Date"] = Sitecore.DateUtil.ToIsoDate(DateTime.Now);

                    commentaryItem.Editing.EndEdit();
                }

                bOk = true;
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Genworth.SitecoreExt.Importers.ExpenseRatioImporter:mapMediaItemToSharedContent, allocation: {1}, title {2}, exception: {3}", managerItem["Name"], title, ex.ToString()), this);
            }

            return(bOk);
        }
Exemple #5
0
        public ActionResult DownloadPDFDocument(string articleId)
        {
            var articleItem = Sitecore.Context.Database.GetItem(articleId);

            Sitecore.Data.Fields.FileField fileField = articleItem.Fields[Templates.ArticleBase.Fields.AttachmentFile];
            if (fileField != null && fileField.MediaItem != null)
            {
                var fileUrl = Sitecore.Resources.Media.MediaManager.GetMediaUrl(fileField.MediaItem);
                if (!string.IsNullOrEmpty(fileUrl))
                {
                    return(Content(Sitecore.Resources.Media.HashingUtils.ProtectAssetUrl(fileUrl)));
                }
            }

            return(Content(LinkManager.GetItemUrl(articleItem)));
        }
        public object ComputeFieldValue(Sitecore.ContentSearch.IIndexable indexable)
        {
            var item = IndexingUtility.ValidIndexableItem(indexable, this);

            if (item == null)
            {
                return(null);
            }

            string fileContent = null;

            Sitecore.Data.Fields.FileField fileField = item.GetField(Constants.Documents.Templates.DocumentBase.Sections.Document.Name, Constants.Documents.Templates.DocumentBase.Sections.Document.Fields.File);

            if (fileField != null && fileField.MediaItem != null)
            {
                fileContent = PDFExtractorHelper.GetContent(fileField.MediaItem);
            }

            return(fileContent);
        }
Exemple #7
0
        public object ComputeFieldValue(Sitecore.ContentSearch.IIndexable indexable)
        {
            var item = IndexingUtility.ValidIndexableItem(indexable, this);

            if (item == null)
            {
                return(null);
            }

            string fileExtension = null;

            Sitecore.Data.Fields.FileField fileField = item.GetField(Constants.Documents.Templates.DocumentBase.Sections.Document.Name, Constants.Documents.Templates.DocumentBase.Sections.Document.Fields.File);

            if (fileField != null && fileField.MediaItem != null)
            {
                Media mediaItem = MediaManager.GetMedia(fileField.MediaItem);
                fileExtension = mediaItem != null ? mediaItem.Extension : null;
            }

            return(fileExtension);
        }
        private bool mapMediaItemToSharedContent(Sitecore.Data.Database database, string strategist, Item allocationItem, string title, MediaItem mediaItem, out ID itemId)
        {
            bool bOk = false;

            itemId = null;
            string allocation = string.Empty;

            if (allocationItem != null)
            {
                allocation = allocationItem["Title"];
            }

            try
            {
                // Sitecore/content/Shared Content/Investments/Strategists/<strategist>/<allocation approach>/Documents/<fact sheet>
                string sharedPath     = "/sitecore/content/Shared Content/Investments/Strategists/" + strategist;
                Item   strategistItem = database.GetItem(sharedPath);

                if (strategistItem == null)
                {
                    Log.Error(String.Format("Genworth.SitecoreExt.Importers.StrategistCommentaryImporter:mapMediaItemToSharedContent, shared content folder for strategist {0} does not exist, skipping. Path: {1}", strategist, sharedPath), this);
                    return(false);
                }

                if (!String.IsNullOrEmpty(allocation))
                {
                    allocationItem = strategistItem.Children[allocation];
                    if (allocationItem == null)
                    {
                        Sitecore.Data.Items.TemplateItem docsTemplateItem = database.GetItem("/sitecore/templates/Genworth/Data/Strategy");
                        allocationItem = strategistItem.Add(allocation, docsTemplateItem);
                    }
                }
                else // GPS & GPS Select-only scenario (no allocation approach)
                {
                    allocationItem = strategistItem;
                }

                //Item docs = allocationItem.Children["Documents"];
                Item docs = strategistItem.Children["Documents"];
                if (docs == null)
                {
                    Sitecore.Data.Items.TemplateItem docsTemplateItem = database.GetItem("/sitecore/templates/Genworth/Folder Types/Investment Folders/Investment Document Folder");
                    //docs = allocationItem.Add("Documents", docsTemplateItem);
                    docs = strategistItem.Add("Documents", docsTemplateItem);
                }

                Item commentaryItem = docs.Children[title];
                if (commentaryItem == null)
                {
                    Sitecore.Data.Items.TemplateItem commentaryTemplateItem = database.GetItem("/sitecore/templates/Genworth/Document Types/Investments/Product Commentary/Product Commentary");
                    commentaryItem = docs.Add(title, commentaryTemplateItem);
                }

                itemId = commentaryItem.ID;

                using (new Sitecore.SecurityModel.SecurityDisabler())
                {
                    commentaryItem.Editing.BeginEdit();

                    Sitecore.Data.Fields.FileField fileField = commentaryItem.Fields["File"];
                    fileField.MediaID = mediaItem.ID;
                    fileField.Src     = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem);

                    if (dictCategories.ContainsKey("Commentary"))
                    {
                        commentaryItem["Category"] = dictCategories["Commentary"].ToString();
                    }

                    if (dictSources.ContainsKey("AssetMark"))
                    {
                        commentaryItem["Source"] = dictSources["AssetMark"].ToString();
                    }

                    commentaryItem["Date"] = Sitecore.DateUtil.ToIsoDate(DateTime.Now);

                    commentaryItem.Editing.EndEdit();
                }

                bOk = true;
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Genworth.SitecoreExt.Importers.StrategistCommentaryImporter:mapMediaItemToSharedContent, strategist: {0}, allocation: {1}, title {2}, exception: {3}", strategist, allocation, title, ex.ToString()), this);
            }

            return(bOk);
        }