예제 #1
0
        public string GetEmailBody(string senderEmail, string senderName, string articleNumber, string message, string companyName, string phoneNumber)
        {
            string emailHtml = string.Empty;

            try
            {
                var htmlEmailTemplate = HtmlEmailTemplateFactory.Create("EmailAnalyst");

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

                var siteRoot = SiteRootContext.Item;
                emailHtml = htmlEmailTemplate.Html;
                var footerContent = GlobalService.GetItem <IEmail_Config>(Constants.ScripEmailConfig);
                var replacements  = new Dictionary <string, string>
                {
                    ["#Environment#"]       = SiteSettings.GetSetting("Env.Value", string.Empty),
                    ["#Date#"]              = DateTime.Now.ToString("dddd, d MMMM yyyy"),
                    ["#RSS_Link_URL#"]      = siteRoot?.RSS_Link.GetLink(),
                    ["#LinkedIn_Link_URL#"] = siteRoot?.LinkedIn_Link.GetLink(),
                    ["#Twitter_Link_URL#"]  = siteRoot?.Twitter_Link.GetLink(),
                    ["#sender_name#"]       = senderName,
                    ["#sender_email#"]      = senderEmail,
                    ["#company_name#"]      = companyName,
                    ["#phone_number#"]      = phoneNumber,
                    ["#Logo_URL#"]          = (siteRoot?.Email_Logo != null)
                                                                ? GetMediaURL(siteRoot.Email_Logo.MediaId.ToString())
                                                                : string.Empty,
                    ["#RssLogo#"] = (siteRoot?.RSS_Logo != null)
                                                                ? GetMediaURL(siteRoot.RSS_Logo.MediaId.ToString())
                                                                : string.Empty,
                    ["#LinkedinLogo#"] = (siteRoot?.Linkedin_Logo != null)
                                                                ? GetMediaURL(siteRoot.Linkedin_Logo.MediaId.ToString())
                                                                : string.Empty,
                    ["#TwitterLogo#"] = (siteRoot?.Twitter_Logo != null)
                                                                ? GetMediaURL(siteRoot.Twitter_Logo.MediaId.ToString())
                                                                : string.Empty,
                    ["#personal_message#"] = (!string.IsNullOrEmpty(message))
                                                                ? $"\"{message}\""
                                                                : string.Empty,
                    ["#Footer_Content#"] = GetValue(footerContent?.Email_A_Friend_Footer_Content)
                                           .ReplacePatternCaseInsensitive("#SENDER_EMAIL#", senderEmail),
                    ["#sender_name_message#"] = !string.IsNullOrEmpty(message)
                                                                ? TextTranslator.Translate("Search.Message").Replace("#SENDER_NAME#", senderName)
                                                                : string.Empty
                };
                emailHtml = emailHtml.ReplacePatternCaseInsensitive(replacements);
            }
            catch (Exception ex)
            {
                _logger.Warn($"Email failed to send: {senderEmail}:{senderName}:{articleNumber}:{message}", ex);
            }
            return(emailHtml);
        }
예제 #2
0
        private static Expression <Func <T, bool> > GetPredicate <T>(IGlobalSitecoreService service, IEnumerable <ITaxonomy_Item> allItems, Guid folder) where T : ITaxonomySearchResults
        {
            var predicate = PredicateBuilder.False <T>();

            var folderItem = service.GetItem <IFolder>(folder);

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

            var list = allItems.Where(b => b._Path.StartsWith(folderItem._Path));

            if (list == null || !list.Any())
            {
                return(null);
            }

            foreach (ITaxonomy_Item t in list)
            {
                var children = t._ChildrenWithInferType.OfType <ITaxonomy_Item>();
                if (children != null && children.Any())
                {
                    list = list.Concat(children);
                }
            }

            foreach (var l in list)
            {
                predicate = predicate.Or(p => p.Taxonomies.Contains(l._Id));
            }

            return(predicate);
        }
예제 #3
0
        public static IQueryable <T> FilterTaxonomies <T>(this IQueryable <T> source, ITaxonomySearchFilter filter, IItemReferences refs, IGlobalSitecoreService service)
            where T : ITaxonomySearchResults
        {
            if (source == null || filter == null || !filter.TaxonomyIds.Any())
            {
                return(source);
            }

            var taxItems = filter.TaxonomyIds.Select(a => service.GetItem <ITaxonomy_Item>(a));

            if (taxItems == null || !taxItems.Any())
            {
                return(source);
            }

            //breaking up the taxonomies by their respective folder to 'or' any within a folder and 'and' the folders together
            List <Guid> taxGuids = new List <Guid>()
            {
                refs.RegionsTaxonomyFolder,
                refs.SubjectsTaxonomyFolder,
                refs.TherapyAreasTaxonomyFolder,
                refs.DeviceAreasTaxonomyFolder,
                refs.IndustriesTaxonomyFolder
            };

            var predicate = PredicateBuilder.True <T>();

            taxGuids
            .Select(g => GetPredicate <T>(service, taxItems, g))
            .Where(p => p != null)
            .ToList()
            .ForEach(i => predicate = predicate.And(i));

            return(source.Filter(predicate));
        }
예제 #4
0
        public string GetMediaURL(string mediaId)
        {
            Item imageItem = GlobalService.GetItem <Item>(mediaId);

            if (imageItem == null)
            {
                return(string.Empty);
            }

            return($"{HttpContext.Current.Request.Url.Scheme}://{WebUtil.GetHostName()}{MediaManager.GetMediaUrl(imageItem)}");
        }
예제 #5
0
        public IArticleSearchResults SearchArticleByAuthorName(IArticleSearchFilter filter)
        {
            using (var context = SearchContextFactory.Create())
            {
                var query = context.GetQueryable <ArticleSearchResultItem>()
                            .Filter(i => i.TemplateId == IArticleConstants.TemplateId)
                            .FilterByAuthor(filter)
                            .ApplyDefaultFilters();
                if (filter.PageSize > 0)
                {
                    query = query.Page(filter.Page > 0 ? filter.Page - 1 : 0, filter.PageSize);
                }

                query = query.OrderByDescending(i => i.ActualPublishDate);

                var results = query.GetResults();

                return(new ArticleSearchResults
                {
                    Articles = results.Hits.Select(h => GlobalService.GetItem <IArticle>(h.Document.ItemId.Guid))
                });
            }
        }
예제 #6
0
        protected string BuildDownloadUrl(IArticle article)
        {
            if (article.Word_Document == null)
            {
                return(string.Empty);
            }

            Item wordDoc = GlobalService.GetItem <Item>(article.Word_Document.TargetId);

            if (wordDoc == null)
            {
                return(string.Empty);
            }

            string url = MediaManager.GetMediaUrl(wordDoc)
                         .Replace("/-/", "/~/")
                         .Replace("-", " ");

            return(url);
        }
        public IEnumerable <ISavedDocumentItem> Create(IEnumerable <ISavedDocument> savedDocuments)
        {
            var savedDocumentItems = new List <ISavedDocumentItem>();

            foreach (var savedDocument in savedDocuments)
            {
                Guid itemId;

                if (!Guid.TryParse(savedDocument.DocumentId, out itemId))
                {
                    continue;
                }

                var item = GlobalService.GetItem <IArticle>(itemId);

                if (item == null)
                {
                    continue;
                }

                var url           = item._Url ?? string.Empty;
                var isExternalUrl = !IsUrlCurrentSite.Check(url);

                savedDocumentItems.Add(new SavedDocumentItem
                {
                    DocumentId    = savedDocument.DocumentId,
                    Publication   = FindPublication.Find(savedDocument.Description),
                    PublishedOn   = item.Actual_Publish_Date,
                    SavedOn       = savedDocument.SaveDate,
                    Title         = item.Title ?? savedDocument.Name,
                    Url           = url,
                    IsExternalUrl = isExternalUrl
                });
            }

            return(savedDocumentItems);
        }
예제 #8
0
        public string GetSitemapXML_Old()
        {
            var    home   = SitecoreContext.GetHomeItem <IHome_Page>();
            string domain = $"{HttpContext.Current.Request.Url.Scheme}://{HttpContext.Current.Request.Url.Host}";

            IEnumerable <I___BasePage> items = GetAllPages(home._Path);

            //start xml doc
            XmlDocument doc = new XmlDocument();
            //xml declaration
            XmlNode declarationNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);

            doc.AppendChild(declarationNode);
            //urlset
            XmlNode urlsetNode = doc.CreateElement("urlset");
            //xmlnls
            XmlAttribute xmlnsAttr = doc.CreateAttribute("xmlns");

            xmlnsAttr.Value = Xmlns;
            urlsetNode.Attributes.Append(xmlnsAttr);
            doc.AppendChild(urlsetNode);

            //append an xml node for each item
            foreach (I___BasePage itm in items)
            {
                if (itm == null)
                {
                    continue;
                }

                //create location
                string url = string.Empty;
                try
                {
                    url = itm.Canonical_Link?.Url;
                }
                catch (Exception ex)
                {
                }

                if (string.IsNullOrEmpty(url))
                {
                    try
                    {
                        var articleItem = GlobalService.GetItem <IArticle>(itm._Id);
                        if (articleItem != null)
                        {
                            url = "/" + articleItem.Article_Number + "/" + articleItem._Name;
                        }
                        else
                        {
                            url = itm._Url;
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }

                if (string.IsNullOrEmpty(url))
                {
                    continue;
                }

                string pageUrl = url;
                if (pageUrl.StartsWith("/"))
                {
                    pageUrl = $"{domain}{pageUrl}";
                }

                //set pointer
                XmlNode lastNode = doc.LastChild;

                //create new node
                XmlNode urlNode = MakeNode(doc, "url");
                lastNode.AppendChild(urlNode);
                urlNode.AppendChild(MakeNode(doc, "loc", pageUrl));
            }

            return(doc.OuterXml);
        }
예제 #9
0
        public string GetEmailBody(string senderEmail, string senderName, string articleNumber, string message)
        {
            string emailHtml = string.Empty;

            try
            {
                var htmlEmailTemplate = HtmlEmailTemplateFactory.Create("EmailFriend");

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

                var siteRoot = SiteRootContext.Item;
                emailHtml = htmlEmailTemplate.Html;
                var footerContent = GlobalService.GetItem <IEmail_Config>(Constants.ScripEmailConfig);
                var replacements  = new Dictionary <string, string>
                {
                    ["#Environment#"]       = SiteSettings.GetSetting("Env.Value", string.Empty),
                    ["#Date#"]              = DateTime.Now.ToString("dddd, d MMMM yyyy"),
                    ["#RSS_Link_URL#"]      = siteRoot?.RSS_Link.GetLink(),
                    ["#LinkedIn_Link_URL#"] = siteRoot?.LinkedIn_Link.GetLink(),
                    ["#Twitter_Link_URL#"]  = siteRoot?.Twitter_Link.GetLink(),
                    ["#sender_name#"]       = senderName,
                    ["#sender_email#"]      = senderEmail,
                    ["#Logo_URL#"]          = (siteRoot?.Email_Logo != null)
                                                                ? GetMediaURL(siteRoot.Email_Logo.MediaId.ToString())
                                                                : string.Empty,
                    ["#RssLogo#"] = (siteRoot?.RSS_Logo != null)
                                                                ? GetMediaURL(siteRoot.RSS_Logo.MediaId.ToString())
                                                                : string.Empty,
                    ["#LinkedinLogo#"] = (siteRoot?.Linkedin_Logo != null)
                                                                ? GetMediaURL(siteRoot.Linkedin_Logo.MediaId.ToString())
                                                                : string.Empty,
                    ["#TwitterLogo#"] = (siteRoot?.Twitter_Logo != null)
                                                                ? GetMediaURL(siteRoot.Twitter_Logo.MediaId.ToString())
                                                                : string.Empty,
                    ["#personal_message#"] = (!string.IsNullOrEmpty(message))
                                                                ? $"\"{message}\""
                                                                : string.Empty,
                    ["#Footer_Content#"] = GetValue(footerContent?.Email_A_Friend_Footer_Content)
                                           .ReplacePatternCaseInsensitive("#SENDER_EMAIL#", senderEmail),
                    ["#sender_name_message#"] = !string.IsNullOrEmpty(message)
                                                                ? TextTranslator.Translate("Search.Message").Replace("#SENDER_NAME#", senderName)
                                                                : string.Empty
                };

                // Article Body
                var article = GetArticle(articleNumber);
                replacements["#article_date#"]      = article?.Actual_Publish_Date.ToString("dd MMMM yyyy") ?? string.Empty;
                replacements["#article_mediatype#"] = article?.Media_Type?.Item_Name ?? string.Empty;
                replacements["#article_title#"]     = article?.Title ?? String.Empty;
                replacements["#article_titleURL#"]  = (article != null)
                                                ? $"{HttpContext.Current.Request.Url.Scheme}://{HttpContext.Current.Request.Url.Host}{article._Url}?utm_medium=email&utm_campaign=emailfriend"
                                                : string.Empty;
                replacements["#article_authorBy#"] = (article != null && article.Authors.Any())
                                                ? TextTranslator.Translate("Article.By")
                                                : string.Empty;
                replacements["#article_author#"] = (article != null && article.Authors.Any())
                                                ? string.Join(",", article.Authors.Select(a => $"{a.First_Name} {a.Last_Name}"))
                                                : string.Empty;
                replacements["#article_summary#"] = (article != null && !string.IsNullOrEmpty(article.Summary))
                                                ? ArticleService.GetArticleSummary(article)
                                                : string.Empty;

                emailHtml = emailHtml.ReplacePatternCaseInsensitive(replacements);
            }
            catch (Exception ex)
            {
                _logger.Warn($"Email failed to send: {senderEmail}:{senderName}:{articleNumber}:{message}", ex);
            }
            return(emailHtml);
        }
 public T Get <T>()
     where T : class, IGlassBase
 {
     return(RenderingContext.HasDataSource ? GlobalService.GetItem <T>(RenderingContext.GetDataSource()) : SitecoreContext.GetCurrentItem <T>());
 }
        private IEnumerable <IListable> GetRelatedArticles(IArticle article)
        {
            var relatedArticles = article
                                  .Related_Articles
                                  .Concat(article.Referenced_Articles)
                                  .DistinctBy(a => a._Id)
                                  .Take(10).ToList();

            if (relatedArticles.Count < 10)
            {
                var filter = Searcher.CreateFilter();
                filter.ReferencedArticle = article._Id;
                filter.PageSize          = 10 - relatedArticles.Count;
                filter.ExcludeManuallyCuratedItems.AddRange(relatedArticles.Select(a => a._Id));

                var results = Searcher.Search(filter);
                relatedArticles.AddRange(results.Articles);
            }
            return(relatedArticles.Where(r => r != null).Select(x => ArticleListableFactory.Create(GlobalService.GetItem <IArticle>(x._Id))).Cast <IListable>().OrderByDescending(x => x.ListableDate));
        }