public SaveSearchPopOutViewModel(IGlassBase model, IAuthenticatedUserContext userContext, ITextTranslator textTranslator, ISignInViewModel signInViewModel) { _textTranslator = textTranslator; IsAuthenticated = userContext.IsAuthenticated; IsSearch = model is ISearch; SignInViewModel = signInViewModel; TitleLabelText = textTranslator.Translate("Search.SavePopout.TitleLabelText"); ButtonLoggedInText = textTranslator.Translate("Search.SavePopout.ButtonLoggedInText"); ButtonLoggedOutText = textTranslator.Translate("Search.SavePopout.ButtonLoggedOutText"); }
public string GetLegacyPublicationText(IArticle article) { var legacyText = TextTranslator.Translate("Article.LegacyPublications"); var legacyPublicationsText = GetLegacyPublicationNames(article).JoinWithFinal(", ", "&"); return(legacyText.Replace("{Legacy Publications}", legacyPublicationsText)); }
private string GetTitleText(string title) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0} {1}", TextTranslator.Translate("Article.LatestFrom"), title); return(sb.ToString()); }
public void Translate(string gamePath, Language sourceLanguage, Language targetLanguage) { try { _languageSwitcher.GamePath = gamePath; if (_languageSwitcher.IsCompatible()) { var paywallReached = false; if (!_languageSwitcher.IsLanguageAvailable(targetLanguage)) { OnStatusChanged("Translating...", 0); var translatables = _languageSwitcher.GetTranslatables(); try { var translation = Task.Run(() => _textTranslator.Translate(translatables, sourceLanguage, targetLanguage)).Result; _languageSwitcher.WriteTranslations(translation.Source, translation.Target, translation.Translations); } catch (PaywallReachedException) { paywallReached = true; } } _languageSwitcher.SwitchLanguages(targetLanguage); var gameExecutablePath = Path.Combine(gamePath, "game.exe"); if (paywallReached) { OnTranslationComplete("Paywall reached; Partial transalation.", CompletionResult.Warn); } else { if (File.Exists(gameExecutablePath)) { Process.Start(gameExecutablePath); OnTranslationComplete("Translation complete.", CompletionResult.Success); } else { OnTranslationComplete("Translation complete. Game executable could not be found.", CompletionResult.Warn); } } } else { OnTranslationComplete("Data directory could not be found.", CompletionResult.Error); } } catch (Exception ex) { OnTranslationComplete("An exception occurred during translation. Message: " + ex.Message, CompletionResult.Error); File.AppendAllText(Path.Combine(Environment.CurrentDirectory, "log.log"), "Exception:\r\nMessage: " + ex.Message + "\r\nStackTrace: " + ex.StackTrace + "\r\n"); throw; } }
public IListableViewModel Create(IArticle article) { if (article == null) { return(null); } var image = article.Featured_Image_16_9?.Src; var curPage = PageItemContext.Get <I___BasePage>(); var model = new ArticleListItemModel(); model.DisplayImage = !string.IsNullOrWhiteSpace(image); model.ListableAuthorByLine = ByLineMaker.MakeByline(article.Authors); model.ListableDate = article.Actual_Publish_Date; model.ListableImage = image; model.ListableSummary = ArticleService.GetArticleSummary(article); model.ListableTitle = HttpUtility.HtmlDecode(article.Title); model.ListablePublication = ArticleService.GetArticlePublicationName(article); model.ListableTopics = ArticleService.GetLinkableTaxonomies(article); model.ListableType = ArticleService.GetMediaTypeIconData(article)?.MediaType; model.ListableUrl = new Link { Url = article._Url, Text = article.Title }; model.LinkableText = article.Content_Type?.Item_Name; model.LinkableUrl = article._Url; model.ID = article._Id; model.IsUserAuthenticated = AuthenticatedUserContext.IsAuthenticated; model.IsArticleBookmarked = IsSavedDocumentContext.IsSaved(article._Id); model.BookmarkText = TextTranslator.Translate("Bookmark"); model.BookmarkedText = TextTranslator.Translate("Bookmarked"); model.PageTitle = curPage?.Title; if (curPage._TemplateId.Equals(ICompany_PageConstants.TemplateId.Guid)) { var recordNumber = HttpContext.Current.Request.Url.Segments.Last(); var company = DcdReader.GetCompanyByRecordNumber(recordNumber); model.PageTitle = company.Title; } return(model); }
public ITopic_Alert_Options SetOptions(ITopic_Alert_Options options) { var a = AuthorService?.GetCurrentAuthor() ?? null; if (a == null) { return(options); } options.Search_Name = $"{TextTranslator.Translate("Author.TopicAlert.Prefix")} {a?.First_Name} {a?.Last_Name}" ?? string.Empty; options.Related_Search = $"?{Constants.QueryString.AuthorFullName}={AuthorNamesField.ToAuthorName(a)}"; return(options); }
public SavedSearchesViewModel( ITextTranslator translator, IAuthenticatedUserContext userContext, ISignInViewModel signInViewModel, IUserContentService <ISavedSearchSaveable, ISavedSearchDisplayable> savedSearchService, ISitePublicationNameContext publicationNameContext) { PublicationNameContext = publicationNameContext; SignInViewModel = signInViewModel; SavedSearches = savedSearchService.GetContent(); IsAuthenticated = userContext.IsAuthenticated; GeneralErrorText = translator.Translate("SavedSearches.GeneralError"); NullUserText = translator.Translate("SavedSearches.NullUserError"); RequestFailedText = translator.Translate("SavedSearches.RequestFailedError"); SourceText = translator.Translate("SavedSearches.SourceText"); TitleText = translator.Translate("SavedSearches.TitleText"); DateText = translator.Translate("SavedSearches.DateText"); EmailAlertText = translator.Translate("SavedSearches.EmailAlertText"); RemoveText = translator.Translate("SavedSearches.RemoveText"); ItemRemovedMessage = translator.Translate("SavedSearches.ItemRemovedMessage"); EmailAlertTooltipText = translator.Translate("IconTooltips.Email.EmailAlert"); }
private ISiteMaintenanceInfo BuildSiteMaintenanceInfo() { var siteRoot = SiteRootContext.Item; var from = siteRoot?.System_Maintenance_Start_Date ?? default(DateTime); var to = siteRoot?.System_Maintenance_End_Date ?? default(DateTime); var message = siteRoot?.System_Maintenance_Text ?? TextTranslator.Translate(DefaultMessageKey); var id = string.Concat(from.ToString("yyyyMMddHHmmss"), to.ToString("yyyyMMddHHmmss")); var show = (@from != default(DateTime) || to != default(DateTime)) && (@from <= DateTime.Now && to >= DateTime.Now); return(new SiteMaintenanceInfo { From = from, To = to, Message = message, Id = id, Show = show }); }
public IndividualRenewalMessageViewModel( ITextTranslator textTranslator, IIndividualSubscriptionRenewalMessageContext context, IAuthenticatedUserContext userContext, ISiteRootContext siteRootContext, IUserSubscriptionsContext userSubscriptionsContext, IUserProfileContext profileContext) { Context = context; SiteRootContext = siteRootContext; UserSubscriptionsContext = userSubscriptionsContext; ProfileContext = profileContext; ISubscription record = userContext.IsAuthenticated ? GetLatestExpiringRecord() : null; DismissText = textTranslator.Translate("Subscriptions.Renewals.Dismiss"); Display = DisplayMessage(record); Message = Display ? GetMessage(record, profileContext?.Profile?.FirstName ?? string.Empty) : string.Empty; Id = context.ID; RenewURL = context.RenewalLinkURL; RenewURLText = context.RenewalLinkText; }
public string GetNewsSitemapXML() { Stopwatch sw = Stopwatch.StartNew(); XmlDocument doc = new XmlDocument(); try { var home = SitecoreContext.GetHomeItem <IHome_Page>(); string publisherName = TextTranslator.Translate("Article.PubName"); string domain = $"{HttpContext.Current.Request.Url.Scheme}://{HttpContext.Current.Request.Url.Host}"; IEnumerable <IArticle> items = GetNewsPages(home._Path); //start xml doc //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); //xmnls:news XmlAttribute xmlnsNewsAttr = doc.CreateAttribute("xmlns:news"); xmlnsNewsAttr.Value = "http://www.google.com/schemas/sitemap-news/0.9"; urlsetNode.Attributes.Append(xmlnsNewsAttr); doc.AppendChild(urlsetNode); //append an xml node for each item foreach (IArticle itm in items) { //set pointer XmlNode lastNode = doc.LastChild; //create new node XmlNode urlNode = MakeNode(doc, "url"); lastNode.AppendChild(urlNode); //create location urlNode.AppendChild(MakeNode(doc, "loc", $"{domain}/{itm.Article_Number}/{itm._Name}")); //create news XmlNode newsNode = MakeNode(doc, "news:news"); urlNode.AppendChild(newsNode); //create publication XmlNode pubNode = MakeNode(doc, "news:publication"); newsNode.AppendChild(pubNode); //create name and langauge pubNode.AppendChild(MakeNode(doc, "news:name", publisherName)); pubNode.AppendChild(MakeNode(doc, "news:language", itm._Language.CultureInfo.TwoLetterISOLanguageName)); //create access, pub date, title and keywords newsNode.AppendChild(MakeNode(doc, "news:access", "Subscription")); newsNode.AppendChild(MakeNode(doc, "news:publication_date", itm.Actual_Publish_Date.ToString(DateFormat))); var encodedItemTitle = HttpUtility.HtmlEncode(itm.Title); newsNode.AppendChild(MakeNode(doc, "news:title", HttpUtility.HtmlDecode(encodedItemTitle))); newsNode.AppendChild(MakeNode(doc, "news:keywords", (itm.Taxonomies != null && itm.Taxonomies.Any()) ? string.Join(",", itm.Taxonomies.Select(a => a.Item_Name)) : string.Empty)); } StringExtensions.WriteSitecoreLogs("Reached GetNewsSitemapXML method End at :", sw, "SitemapService"); /* * <?xml version="1.0" encoding="UTF-8"?> * <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" * xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"> * <url> * <loc>http://www.example.org/business/article55.html</loc> * <news:news> * <news:publication> * <news:name>The Example Times</news:name> * <news:language>en</news:language> * </news:publication> * <news:access>Subscription</news:access> * <news:publication_date>2008-12-23</news:publication_date> * <news:title>Companies A, B in Merger Talks</news:title> * <news:keywords>business, merger, acquisition, A, B</news:keywords> * </news:news> * </url> * </urlset> */ } catch (Exception ex) { StringExtensions.WriteSitecoreLogs("GetNewsSitemapXML Exception :" + ex.Message, sw, "SitemapService"); } return(doc.OuterXml); }
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 LatestNewsViewModel(IGlassBase datasource, IRenderingContextService renderingParametersService, IArticleSearch articleSearch, IItemManuallyCuratedContent itemManuallyCuratedContent, IArticleListItemModelFactory articleListableFactory, ISiteRootContext rootContext, ITextTranslator textTranslator, IAuthorService authorService, IDCDReader dcdReader) { Datasource = datasource; ArticleSearch = articleSearch; ItemManuallyCuratedContent = itemManuallyCuratedContent; ArticleListableFactory = articleListableFactory; TextTranslator = textTranslator; AuthorService = authorService; DcdReader = dcdReader; Stopwatch sw = Stopwatch.StartNew(); StringExtensions.WriteSitecoreLogs("Reading rendering parameters at:", sw, "Latest News"); Authors = new List <string>(); Parameters = renderingParametersService.GetCurrentRenderingParameters <ILatest_News_Options>(); StringExtensions.WriteSitecoreLogs("Reading rendering parameters ends at:", sw, "Latest News"); if (Parameters == null) { return; } DisplayTitle = Parameters.Display_Title; ItemsToDisplay = Parameters.Number_To_Display?.Value ?? 6; SeeAllLink = Parameters.Show_See_All ? new Link { Text = TextTranslator.Translate("Article.LatestFrom.SeeAllLink") } : null; StringExtensions.WriteSitecoreLogs("Reading publicationNames at:", sw, "Latest News"); var publicationNames = Parameters.Publications.Any() ? Parameters.Publications.Select(p => p.Publication_Name) : new[] { rootContext.Item.Publication_Name }; StringExtensions.WriteSitecoreLogs("Reading publicationNames ends at:", sw, "Latest News"); StringExtensions.WriteSitecoreLogs("Reading Authers at:", sw, "Latest News"); Authors = Parameters.Authors?.Select(p => RemoveSpecialCharactersFromGuid(p._Id.ToString())).ToArray(); CompanyRecordNumbers = string.IsNullOrEmpty(Parameters.CompanyID) ? (IList <string>) new List <string>() : Parameters.CompanyID.Split(','); StringExtensions.WriteSitecoreLogs("Reading Authers ends at:", sw, "Latest News"); if (IsAuthorPage) { Author_Page(); if (!Parameters.Publications.Any()) // authors page shouldn't filter on the current publication { publicationNames = Enumerable.Empty <string>(); } } else if (datasource._TemplateId.ToString() == ICompany_PageConstants.TemplateIdString) { Company_Page(); if (!Parameters.Publications.Any()) // authors page shouldn't filter on the current publication { publicationNames = Enumerable.Empty <string>(); } } else { Other_Page(); } News = GetLatestNews(datasource._Id, Parameters.Subjects.Select(s => s._Id), publicationNames, Authors, CompanyRecordNumbers, ItemsToDisplay); }
public IEmail Create(IUserResetPassword userResetPassword) { var siteRootContext = SitecoreContext?.GetRootItem <ISite_Root>(); if (userResetPassword == null) { return(null); } var htmlEmailTemplate = HtmlEmailTemplateFactory.Create("ResetPassword"); if (htmlEmailTemplate == null) { return(null); } var email = EmailFactory.Create(); var siteRoot = siteRootContext; var resetPasswordHtml = htmlEmailTemplate.Html; var userProfile = FindUserProfile.Find(userResetPassword.Username); var emailTo = userResetPassword.Username; var resetPasswordReplacements = new Dictionary <string, string>(); resetPasswordReplacements["#Reset_Link_URL#"] = UrlFactory.Create(userResetPassword); resetPasswordReplacements["#Reset_Link_Text#"] = GetValue(siteRoot?.Reset_Password_Email_Link_Text, TextTranslator.Translate("Authentication.ResetPassword.Email.ResetLink")); resetPasswordReplacements["#Body_Content#"] = GetValue(siteRoot?.Reset_Password_Email_Body); resetPasswordReplacements["#Support_Text#"] = GetValue(siteRoot?.Customer_Support_Text); resetPasswordHtml = resetPasswordHtml.ReplacePatternCaseInsensitive(resetPasswordReplacements); var baseReplacements = new Dictionary <string, string>(); baseReplacements["#Body_Content#"] = resetPasswordHtml; baseReplacements["#Email#"] = emailTo; baseReplacements["#Envrionment#"] = SiteSettings.GetSetting("Env.Value", string.Empty); baseReplacements["#Page_Type#"] = "reset-password-email-in-inbox"; if (userProfile != null) { baseReplacements["#First_Name#"] = userProfile.FirstName; baseReplacements["#Last_Name#"] = userProfile.LastName; baseReplacements["#UserName#"] = userProfile.Email; } email.Body = email.Body.ReplacePatternCaseInsensitive(baseReplacements); email.To = emailTo; email.Subject = GetValue(siteRoot?.Reset_Password_Email_Subject); return(email); }