public ArticleStruct GetArticleDetailsWithoutDocumentParsing() { var articleDetails = new ArticleStruct(); try { articleDetails.ArticleNumber = pageArticleInformationControl.GetArticleNumber(); articleDetails.WebPublicationDate = pageArticleInformationControl.GetWebPublishDate(); articleDetails.Publication = pageArticleInformationControl.GetSelectedPublicationGuid(); articleDetails.Authors = pageArticleInformationControl.GetSelectedAuthors().ToList(); articleDetails.Label = pageArticleInformationControl.GetLabelGuid(); articleDetails.MediaType = pageArticleInformationControl.GetMediaTypeGuid(); articleDetails.NotesToEditorial = pageArticleInformationControl.GetNotes(); articleDetails.Taxonomoy = pageTaxonomyControl.TabController.GetSelected().ToList(); articleDetails.RelatedInlineArticles = pageRelatedArticlesControl.GetInlineReferences().ToList(); articleDetails.RelatedArticles = pageRelatedArticlesControl.GetRelatedArticles().ToList(); articleDetails.Embargoed = pageArticleInformationControl.GetEmbargoedState(); articleDetails.FeaturedImageCaption = pageFeaturedImageControl.GetFeaturedImageCaption(); articleDetails.FeaturedImageSource = pageFeaturedImageControl.GetFeaturedImageSource(); articleDetails.NotificationText = pageWorkflowControl.GetNotificationText(); articleDetails.CommandID = pageWorkflowControl.GetSelectedCommand(); if (pageFeaturedImageControl.GetFeaturedImage() != null) { articleDetails.FeaturedImage = pageFeaturedImageControl.GetFeaturedImage().MediaId; } } catch (Exception ex) { Globals.SitecoreAddin.Log("ArticleDetailsPageSelector:GetArticleDetailsWithoutDocumentParsing - Error :" + ex.Message); } return(articleDetails); }
public void UpdateFields(ArticleWorkflowState state, ArticleStruct articleStruct) { if (_staff == null) { _staff = SitecoreClient.GetStaffAndGroups(); } uxNotifyPicker.DataSource = _staff; uxNotifyPicker.DisplayMember = "Name"; uxNotifyPicker.ValueMember = "ID"; if (state == null) { return; } _ArticleStruct = articleStruct; uxCurrentWorkflowValue.Text = state.DisplayName; Commands = new List <ArticleWorkflowCommand>(); Commands.Insert(0, new ArticleWorkflowCommand { DisplayName = "Move in Workflow...", StringID = Guid.Empty.ToString() }); if (state.Commands != null) { Commands.AddRange(state.Commands); } else { Globals.SitecoreAddin.Log("No workflow actions were available."); uxWorkflowActions.Enabled = false; } uxWorkflowActions.DataSource = Commands; uxWorkflowActions.DisplayMember = "DisplayName"; uxWorkflowActions.ValueMember = "StringID"; uxUnlockOnSave.Checked = false; subjectLbl.Text = "Subject :"; }
public static ArticleStruct LazyReadArticleDetails(string articleNumber) { if (_articleDetails != null && _articleDetails.ArticleNumber == articleNumber) { return(_articleDetails); } return(_articleDetails = GetArticleDetails(articleNumber)); }
/// <summary> /// /// /// Be sure to catch WebException indicating server could not be contacted /// Saves a locked document (and unlocks the local document) /// </summary> public bool SaveArticle(ArticleDocumentMetadataParser metadataParser = null, string body = null) { var documentCustomProperties = new DocumentCustomProperties(SitecoreAddin.ActiveDocument); var articleNumber = GetArticleNumber(); if (!string.IsNullOrEmpty(documentCustomProperties.ArticleNumber) && !string.IsNullOrEmpty(articleNumber)) { if (articleNumber != documentCustomProperties.ArticleNumber) { string alertMessage = "Article numbers do not match, are you sure you would like to continue? " + "This can happen accidentally if you switching between documents quickly during saving."; DialogResult result = MessageBox.Show(alertMessage, "Article numbers do not match", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.No) { return(false); } } } try { if (HasArticleNumber()) { var copy = ArticleDetails.ArticleGuid; ArticleDetails = GetArticleDetails(articleNumber, metadataParser); //TamerM 2016-09-13: Removed the below since copy doesn't always contain the active document Guid and GetArticleDetails does return the ArticleGuid from the server //if (copy.Equals(new Guid()) == false) //ArticleDetails.ArticleGuid = copy; _sitecoreArticle = new SitecoreClient(); //TODO - Add workflow stuff here List <string> errors = _sitecoreArticle.SaveArticle(SitecoreAddin.ActiveDocument, ArticleDetails, new Guid(), new List <StaffStruct>(), GetArticleNumber(), body); if (errors != null && errors.Any()) { foreach (string error in errors) { if (!String.IsNullOrEmpty(error)) { MessageBox.Show(error, error.Contains("not secure") ? @" Non-Secure Multimedia Content" : @"Informa"); } } return(false); } } } catch (Exception ex) { Globals.SitecoreAddin.LogException("Error when saving article!", ex); throw; } //TamerM - 2016-03-22: Prompt and ReExport NLM FEED NLMFeedUtils.PromptAndReExportNLMFeed(ArticleDetails.ArticleNumber, ArticleDetails.IsPublished); return(true); }
public void UpdateFields(ArticleStruct articleDetails) { List <TaxonomyStruct> taxonomyItems = SitecoreClient.SearchTaxonomy("").ToList(); HDirectoryStruct taxonomyDirectory = SitecoreClient.GetHierarchyByGuid(new Guid(Constants.TAXONOMY_GUID)); TabController.InitializeSitecoreValues(taxonomyItems, taxonomyDirectory); _isLive = articleDetails.IsPublished; label4.Refresh(); }
public void SaveArticleDetails(string articleNumber, ArticleStruct articleStruct, bool saveDocumentSpecificData = false, bool addVersion = true) { ArticleItem article = _articleUtil.GetArticleByNumber(articleNumber); if (article == null) { throw new ApplicationException("Could not find article for number [" + articleNumber + "]"); } SaveArticleDetails(article, articleStruct, saveDocumentSpecificData, addVersion); }
public void SaveArticleDetails(Guid articleGuid, ArticleStruct articleStruct, bool saveDocumentSpecificData = false, bool addVersion = true) { //TODO: Add Roles ArticleItem article = _sitecoreMasterService.GetItem <ArticleItem>(articleGuid); if (article == null) { throw new ApplicationException("Could not find article with Guid " + articleGuid); } SaveArticleDetails(article, articleStruct, saveDocumentSpecificData, addVersion); }
public static bool DoesArticleNameAlreadyExistInIssue(ArticleStruct articleDetails) { TimezoneUtil.ConvertArticleDatesToServerTimezone(articleDetails); using (var client = new HttpClient(_handler, false)) { var response = client.GetAsync($"{$"{Constants.EDITOR_ENVIRONMENT_SERVERURL}" + "/api/"}DoesArticleNameAlreadyExistInIssue").Result; var flag = JsonConvert.DeserializeObject <bool>(response.Content.ReadAsStringAsync().Result); TimezoneUtil.ConvertArticleDatesToLocalTimezone(articleDetails); return(flag); } }
public void UpdateFields(ArticleStruct articleDetails) { List <TaxonomyStruct> subjects = SitecoreClient.SearchTaxonomy("").ToList(); HDirectoryStruct subjectDirectory = SitecoreClient.GetHierarchyByGuid(new Guid(Constants.SUBJECT_GUID)); TabController.InitializeSitecoreValues(subjects, subjectDirectory); _isLive = articleDetails.IsPublished; label8.Refresh(); }
/// <summary> /// /// </summary> public void EditAfterPublishSendNotification(ArticleStruct articleStruct) { if (articleStruct.Publication == Guid.NewGuid()) { return; } var siteConfigItem = _service.GetItem <ISite_Config>(articleStruct.Publication); if (siteConfigItem == null) { return; } var fromEmail = siteConfigItem.From_Email_Address; var title = siteConfigItem.Email_Title; var replyToEmail = Sitecore.Context.User.Profile.Email; if (string.IsNullOrEmpty(fromEmail) || string.IsNullOrEmpty(replyToEmail)) { return; } var workflowItem = _siteWorkflow.GetPublicationWorkflow(_service.GetItem <Item>(articleStruct.ArticleGuid)); //_service.GetItem<Informa.Models.Informa.Models.sitecore.templates.System.Workflow.IWorkflow>(_siteWorkflow.get _siteRootContext.Item.Workflow); if (workflowItem == null) { return; } var notificationList = workflowItem.Notified_After_Publishes; var staffItems = notificationList as IStaff_Item[] ?? notificationList.ToArray(); if (notificationList == null || !staffItems.Any()) { return; } var emailBody = CreateEditAfterPublishBody(articleStruct, title, siteConfigItem.Publication_Name); foreach (var eachEmail in staffItems) { if (string.IsNullOrEmpty(eachEmail.Email_Address)) { continue; } var email = new Email { To = eachEmail.Email_Address, Subject = title, From = fromEmail, Body = emailBody, IsBodyHtml = true }; EmailSender.SendWorkflowNotification(email, replyToEmail); } }
public void InitializeItems(ArticleStruct articleDetails) { if (articleDetails != null) { var featuredImage = articleDetails.FeaturedImageSource; var imageMediaItem = SitecoreClient.GetMediaLibraryItem(featuredImage); } var values = SitecoreClient.GetGraphicsRootNode(); AddRootNode(uxFeaturedImageTreeView, values[1], values[0]); }
public static void SaveMetadataToSitecore(string articleID, ArticleStruct articleData) { TimezoneUtil.ConvertArticleDatesToServerTimezone(articleData); using (var client = new HttpClient(_handler, false)) { var article = new SaveArticleDetails() { ArticleNumber = articleID, ArticleData = articleData }; var response = client.PostAsJsonAsync($"{$"{Constants.EDITOR_ENVIRONMENT_SERVERURL}" + "/api/"}SaveArticleDetails", article).Result; TimezoneUtil.ConvertArticleDatesToLocalTimezone(articleData); } }
public static void SaveArticleText(Guid articleGuid, string text, ArticleStruct articleStruct) { TimezoneUtil.ConvertArticleDatesToServerTimezone(articleStruct); using (var client = new HttpClient(_handler, false)) { var article = new SaveArticleTextByGuid() { ArticleGuid = articleGuid, ArticleData = articleStruct, WordText = text }; var response = client.PostAsJsonAsync($"{$"{Constants.EDITOR_ENVIRONMENT_SERVERURL}" + "/api/"}SaveArticleTextByGuid", article).Result; TimezoneUtil.ConvertArticleDatesToLocalTimezone(articleStruct); } }
public string CreateEditAfterPublishBody(ArticleStruct articleStruct, string emailTitle, string publication) { var htmlEmailTemplate = HtmlEmailTemplateFactory.Create("EditAfterPublishEmail"); if (htmlEmailTemplate == null) { return(null); } var article = _articleUtil.GetArticleItemByNumber(articleStruct.ArticleNumber); var authorString = string.Empty; foreach (var eachAuthor in articleStruct.Authors) { authorString = eachAuthor.Name + ","; } var emailHtml = htmlEmailTemplate.Html; var replacements = new Dictionary <string, string>(); replacements["#Email_Title#"] = emailTitle; replacements["#Article_Title#"] = articleStruct.Title; replacements["#Publish_Date#"] = articleStruct.WebPublicationDate.ToString(); replacements["#word_url#"] = GetWordURL(articleStruct); ArticleItem articleItem = _service.GetItem <ArticleItem>(article.ID.ToString()); if (articleItem != null) { var preview = _articleUtil.GetPreviewInfo(articleItem); if (preview != null) { replacements["#preview_url#"] = preview.PreviewUrl; } } replacements["#Authors#"] = string.IsNullOrEmpty(authorString) ? "No authors selected" : authorString; replacements["#Publication#"] = publication; replacements["#Body_Content#"] = articleStruct.NotificationText == null ? string.Empty : articleStruct.NotificationText; replacements["#content_editor#"] = Sitecore.Context.User.Profile.FullName; replacements["#current_time#"] = DateTime.Now.ToString(); List <WorkflowEvent> workflowHistory = GetWorkflowHistory(article); replacements["#history#"] = HistoryTableCreation(workflowHistory); return(emailHtml.ReplacePatternCaseInsensitive(replacements)); }
/// <summary> /// Sets the fields in the UI based on the inputted ArticleStruct /// </summary> /// <param name="articleDetails"></param> public void UpdateFields(ArticleStruct articleDetails) { pageArticleInformationControl.UpdateFields(articleDetails); pageRelatedArticlesControl.UpdateFields(articleDetails); pageFeaturedImageControl.UpdateFields(articleDetails); pageWorkflowControl.UpdateFields(articleDetails.ArticleWorkflowState, articleDetails); pageTaxonomyControl.UpdateFields(articleDetails); if (string.IsNullOrEmpty(articleDetails.ArticleNumber)) { return; } //pageSubjectsControl.TabController.UpdateFields(articleDetails.Subjects.ToList()); pageTaxonomyControl.TabController.UpdateFields(articleDetails.Taxonomoy.ToList()); pageWorkflowControl.UpdateFields(articleDetails.ArticleWorkflowState, articleDetails); }
public void UpdateFields(ArticleStruct articleDetails) { _inlineReferenceParser.ParseDocument(SitecoreAddin.ActiveDocument); uxSelectedLayout.MenuItem = MenuItem; uxSelectedLayout.UpdateMenuItem(); if (string.IsNullOrEmpty(articleDetails.ArticleNumber)) { return; } uxSelectedLayout.SitecoreReferencedArticles = articleDetails.ReferencedArticlesInfo.ToList(); uxSelectedLayout.SitecoreRelatedArticles = articleDetails.RelatedArticlesInfo.ToList(); uxSelectedLayout.LocalReferencedArticles = SitecoreClient.GetArticlePreviewInfo(_inlineReferenceParser.InlineReferenceGuids); uxSelectedLayout.PopulateTable(); _isLive = articleDetails.IsPublished; uxArticleInformationHeaderLabel.Refresh(); }
/// <summary> /// Builds the Article Details based on the the data entered in the UI /// /// Retrieve the relevant information from the UI /// </summary> /// <returns></returns> public ArticleStruct GetArticleDetails(ArticleDocumentMetadataParser metadataParser = null) { if (metadataParser == null) { metadataParser = new ArticleDocumentMetadataParser(SitecoreAddin.ActiveDocument, _parent.GetWordUtils().CharacterStyleTransformer); } string ExecutiveSummary = metadataParser.ExecutiveSummary; var articleDetails = new ArticleStruct(); try { articleDetails.ArticleGuid = pageArticleInformationControl.ArticleGuid; articleDetails.IsPublished = pageArticleInformationControl.IsPublished; articleDetails.ArticleNumber = pageArticleInformationControl.GetArticleNumber(); articleDetails.WebPublicationDate = pageArticleInformationControl.GetWebPublishDate(); articleDetails.Title = metadataParser.Title.Trim(); articleDetails.Summary = ExecutiveSummary; articleDetails.Subtitle = metadataParser.Subtitle; articleDetails.Publication = pageArticleInformationControl.GetSelectedPublicationGuid(); articleDetails.Authors = pageArticleInformationControl.GetSelectedAuthors().ToList(); articleDetails.Label = pageArticleInformationControl.GetLabelGuid(); articleDetails.MediaType = pageArticleInformationControl.GetMediaTypeGuid(); articleDetails.NotesToEditorial = pageArticleInformationControl.GetNotes(); articleDetails.Taxonomoy = pageTaxonomyControl.TabController.GetSelected().ToList(); articleDetails.RelatedInlineArticles = pageRelatedArticlesControl.GetInlineReferences().ToList(); articleDetails.RelatedArticles = pageRelatedArticlesControl.GetRelatedArticles().ToList(); articleDetails.ArticleSpecificNotifications = pageWorkflowControl.GetNotifyList().ToList(); articleDetails.Embargoed = pageArticleInformationControl.GetEmbargoedState(); articleDetails.FeaturedImageCaption = pageFeaturedImageControl.GetFeaturedImageCaption(); articleDetails.FeaturedImageSource = pageFeaturedImageControl.GetFeaturedImageSource(); articleDetails.NotificationText = pageWorkflowControl.GetNotificationText(); articleDetails.CommandID = pageWorkflowControl.GetSelectedCommand(); if (pageFeaturedImageControl.GetFeaturedImage() != null) { articleDetails.FeaturedImage = pageFeaturedImageControl.GetFeaturedImage().MediaId; } } catch (Exception ex) { Globals.SitecoreAddin.Log("ArticleDetailsPageSelector:GetArticleDetails - Error :" + ex.Message); } return(articleDetails); }
public static void ConvertArticleDatesToServerTimezone(ArticleStruct article) { if (article == null) { return; } if (article.PrintPublicationDate != DateTime.MinValue && article.PrintPublicationDate != DateTime.MaxValue) { article.PrintPublicationDate = TimeZoneInfo.ConvertTime(article.PrintPublicationDate, ServerTimezone); } if (article.WebPublicationDate != DateTime.MinValue && article.WebPublicationDate != DateTime.MaxValue) { article.WebPublicationDate = TimeZoneInfo.ConvertTime(article.WebPublicationDate, ServerTimezone); } article.WordDocLastUpdateDate = ConvertDateToServerTimezone(article.WordDocLastUpdateDate); }
public ArticleStruct GetArticleDetails(string articleNumber, ArticleDocumentMetadataParser metadataParser = null) { var sitecoreArticleDetails = SitecoreClient.ForceReadArticleDetails(articleNumber); if (metadataParser == null) { metadataParser = new ArticleDocumentMetadataParser(SitecoreAddin.ActiveDocument, _wordUtils.CharacterStyleTransformer); } string ExecutiveSummary = metadataParser.ExecutiveSummary; var articleDetails = new ArticleStruct { ArticleGuid = sitecoreArticleDetails.ArticleGuid, IsPublished = sitecoreArticleDetails.IsPublished, ArticleNumber = sitecoreArticleDetails.ArticleNumber, WebPublicationDate = sitecoreArticleDetails.WebPublicationDate, Title = metadataParser.Title.Trim(), Summary = ExecutiveSummary, Subtitle = metadataParser.Subtitle, Publication = sitecoreArticleDetails.Publication, Authors = sitecoreArticleDetails.Authors.ToList(), Label = sitecoreArticleDetails.Label, MediaType = sitecoreArticleDetails.MediaType, NotesToEditorial = sitecoreArticleDetails.NotesToEditorial, Taxonomoy = sitecoreArticleDetails.Taxonomoy, RelatedInlineArticles = sitecoreArticleDetails.RelatedInlineArticles, RelatedArticles = sitecoreArticleDetails.RelatedArticles, ArticleSpecificNotifications = sitecoreArticleDetails.GlobalNotifications, Embargoed = sitecoreArticleDetails.Embargoed, FeaturedImageCaption = sitecoreArticleDetails.FeaturedImageCaption, FeaturedImageSource = sitecoreArticleDetails.FeaturedImageSource, }; //RelatedInlineArticles = sitecoreArticleDetails.RelatedInlineArticles.ToList(), // RelatedArticles = sitecoreArticleDetails.RelatedArticles.ToList(), // ArticleSpecificNotifications = sitecoreArticleDetails.GlobalNotifications.ToList(), if (sitecoreArticleDetails.FeaturedImage != new Guid()) { articleDetails.FeaturedImage = sitecoreArticleDetails.FeaturedImage; } return(articleDetails); }
public ArticleStruct GetServerStruct(ArticleStruct articleStruct) { var articleDetails = new ArticleStruct { IsPublished = articleStruct.IsPublished, Publication = articleStruct.Publication, ArticleNumber = articleStruct.ArticleNumber, ArticleGuid = articleStruct.ArticleGuid, Title = articleStruct.Title, Label = articleStruct.Label, WebPublicationDate = articleStruct.WebPublicationDate, PrintPublicationDate = articleStruct.PrintPublicationDate, Embargoed = articleStruct.Embargoed, MediaType = articleStruct.MediaType, Authors = articleStruct.Authors.Select(r => new StaffStruct { ID = r.ID, Name = r.Name, Publications = r.Publications }) .ToList(), NotesToEditorial = articleStruct.NotesToEditorial, RelatedInlineArticles = articleStruct.RelatedInlineArticles, ArticleWorkflowState = articleStruct.ArticleWorkflowState, FeaturedImage = articleStruct.FeaturedImage, FeaturedImageCaption = articleStruct.FeaturedImageCaption, FeaturedImageSource = articleStruct.FeaturedImageSource, Taxonomoy = articleStruct.Taxonomoy, RelatedArticles = articleStruct.RelatedArticles, ReferencedDeals = articleStruct.ReferencedDeals, Subtitle = articleStruct.Subtitle, Summary = articleStruct.Summary, CommandID = articleStruct.CommandID, WordCount = articleStruct.WordCount, SupportingDocumentPaths = articleStruct.SupportingDocumentPaths, NotificationText = articleStruct.NotificationText, ArticleSpecificNotifications = articleStruct.ArticleSpecificNotifications. Select(n => new StaffStruct { Name = n.Name, ID = n.ID, }).ToList() }; return(articleDetails); }
protected void MoveArticleIfNecessary(ArticleItem article, ArticleStruct articleStruct) { var item = _sitecoreMasterService.GetItem <Item>(article._Id); using (new SecurityDisabler()) { var publicationItem = ArticleExtension.GetAncestorItemBasedOnTemplateID(item); if (publicationItem != null) { var publication = publicationItem.ID.Guid; var newParent = _articleUtil.GenerateDailyFolder(publication, articleStruct.WebPublicationDate); if (newParent != null) { _sitecoreMasterService.Move(article, newParent); } //TODO - Verify if this feautre needs to be there or not. //_wordDocToMediaLibrary.MoveWordDocIfNecessary(article, articleStruct, oldIssueID); } } }
public bool IsValidArticleDate(ArticleStruct articleDetails, ArticleWorkflowCommand command) { var articleDate = articleDetails.WebPublicationDate; if (articleDate < DateTime.Now) { var result = WantsToSetArticleDateToNow(command); if (result == DialogResult.Yes) { articleDetails.WebPublicationDate = DateTime.Now; return(true); } else if (result == DialogResult.Cancel) { MessageBox.Show("Save cancelled."); return(false); } } return(true); }
public void UpdateFields(ArticleStruct articleDetails) { sourceTxtBox.Text = articleDetails.FeaturedImageSource; captionTxtBox.Text = articleDetails.FeaturedImageCaption; SitecoreItemGetter.SitecoreMediaItem mediaItem = _siteCoreItemGetter.DownloadSiteCoreMediaItem(articleDetails.FeaturedImage.ToString()); if ((mediaItem == null) || !(mediaItem.Extension.ToLower().Contains("gif") || mediaItem.Extension.ToLower().Contains("jpg") || mediaItem.Extension.ToLower().Contains("png"))) { pictureBox1.Visible = false; filenameLblHeader.Visible = false; filenameLbl.Visible = false; alttextLblHeader.Visible = false; alttextLbl.Visible = false; return; } imageSelected = articleDetails.FeaturedImage.ToString(); pictureBox1.ImageLocation = mediaItem.FileName; filenameLbl.Text = mediaItem.Title; alttextLbl.Text = mediaItem.AltText; }
protected void RenameArticleItem(ArticleItem article, ArticleStruct articleStruct) { string title = articleStruct.Title; if (title == null) { return; } using (new SecurityDisabler()) { var articleItem = _sitecoreMasterService.GetItem <Item>(article._Id); articleItem.Editing.BeginEdit(); articleItem[I___BasePageConstants.TitleFieldName] = title; if (!article.IsPublished) { string trim = title.Length > 100 ? title.Substring(0, 100).Trim() : title.Trim(); articleItem["__Display name"] = trim; articleItem.Name = ItemUtil.ProposeValidItemName(trim); } articleItem.Editing.EndEdit(); } }
public string GetWordURL(ArticleStruct articleStruct) { string url = string.Empty; var article = _articleUtil.GetArticleItemByNumber(articleStruct.ArticleNumber); //Item article = _service.GetItem<Item>(articleStruct.ArticleGuid); LinkField wordDocument = article.Fields[IArticleConstants.Word_DocumentFieldId]; if (wordDocument == null) { return(url); } Item item = _service.GetItem <Item>(wordDocument.TargetID.Guid); if (item == null || !MediaManager.HasMediaContent(item)) { return(url); } string siteRoot = HttpContext.Current.Request.Url.Host; url = siteRoot + MediaManager.GetMediaUrl(item) + "?sc_mode=preview"; return(url); }
public List <string> SaveArticle(Document activeDocument, ArticleStruct articleDetails, Guid workflowCommand, List <StaffStruct> notifications, string articleNumber, string body = null, string notificationText = null) { string text; try { text = body ?? _wordUtils.GetWordDocTextWithStyles(activeDocument).ToString(); } catch (InsecureIFrameException insecureIframe) { string message = String.Empty; foreach (string iframeURL in insecureIframe.InsecureIframes) { message += $"\n{iframeURL}"; } return(new List <string> { "The following multimedia content is not secure. Please correct and try to save again. " + message }); } catch (InvalidHtmlException) { return(new List <string> { String.Empty }); } catch (Exception ex) { Globals.SitecoreAddin.LogException("Error when parsing article!", ex); return(new List <string> { "The document could not be parsed to transfer to Sitecore! Details in logs." }); } try { var documentCustomProperties = new DocumentCustomProperties(activeDocument); articleDetails.ArticleSpecificNotifications = notifications.ToList(); articleDetails.NotificationText = notificationText; articleDetails.WordCount = activeDocument.ComputeStatistics(0); articleDetails.ReferencedDeals = ReferencedDealParser.GetReferencedDeals(activeDocument).ToList(); articleDetails.CommandID = workflowCommand; articleDetails.SupportingDocumentPaths = _wordUtils.GetSupportingDocumentPaths().ToList(); if (articleDetails.RelatedArticles == null) { articleDetails.RelatedArticles = new List <Guid>(); } if (articleDetails.RelatedInlineArticles == null) { articleDetails.RelatedInlineArticles = new List <Guid>(); } Globals.SitecoreAddin.Log("Local document version before check: " + documentCustomProperties.WordSitecoreVersionNumber); var currentVersion = articleDetails.ArticleGuid != Guid.Empty ? GetWordVersionNumber(articleDetails.ArticleGuid) : GetWordVersionNumber(articleNumber); Globals.SitecoreAddin.Log("Sitecore document version before save: " + currentVersion); if (currentVersion != -1) { documentCustomProperties.WordSitecoreVersionNumber = currentVersion + 1; } else { documentCustomProperties.WordSitecoreVersionNumber = 1; } if (articleDetails.ArticleGuid != Guid.Empty) { SaveArticleText(articleDetails.ArticleGuid, text, _structConverter.GetServerStruct(articleDetails)); } else { SaveArticleText(articleNumber, text, _structConverter.GetServerStruct(articleDetails)); } Globals.SitecoreAddin.Log("Local document version after check: " + documentCustomProperties.WordSitecoreVersionNumber); SendWordDocumentToSitecore(activeDocument, documentCustomProperties, articleNumber, articleDetails); documentCustomProperties.WordSitecoreVersionNumber = articleDetails.ArticleGuid != Guid.Empty ? GetWordVersionNumber(articleDetails.ArticleGuid) : GetWordVersionNumber(articleNumber); Globals.SitecoreAddin.Log("Local document version after cautionary update: " + documentCustomProperties.WordSitecoreVersionNumber); var path = activeDocument.Path; if (!string.IsNullOrWhiteSpace(path) && WordUtils.FileExistsAndNotReadOnly(path, activeDocument.Name)) { WordUtils.Save(activeDocument); } return(_wordUtils.Errors); } catch (Exception ex) { Globals.SitecoreAddin.LogException("Error when saving article!", ex); throw; } }
protected void SendWordDocumentToSitecore(Document activeDocument, DocumentCustomProperties documentCustomProperties, string articleNumber, ArticleStruct articleDetails) { string extension = GetExtension(activeDocument); DocumentProtection.Protect(documentCustomProperties); byte[] data = _wordUtils.GetWordBytes(activeDocument); if (data == null) { throw new Exception("Error saving file to disk."); } DocumentProtection.Unprotect(documentCustomProperties); string uploader = SitecoreUser.GetUser().Username; int wordSitecoreVersionNumber = articleDetails.ArticleGuid != Guid.Empty ? this.SendDocumentToSitecoreByGuid(articleDetails.ArticleGuid, data, extension, uploader) : this.SendDocumentToSitecore(articleNumber, data, extension, uploader); documentCustomProperties.WordSitecoreVersionNumber = wordSitecoreVersionNumber; }
public void UpdateFields(ArticleStruct articleDetails) { _isLive = articleDetails.IsPublished; label1.Refresh(); }
/// <summary> /// /// </summary> public void SendNotification(ArticleStruct articleStruct, WorkflowInfo oldWorkflow) { Logger.SitecoreInfo("EmailUtil.SendNotification"); if (articleStruct.Publication == Guid.NewGuid()) { return; } var siteConfigItem = _service.GetItem <ISite_Config>(articleStruct.Publication); if (siteConfigItem == null) { return; } var fromEmail = siteConfigItem.From_Email_Address; var title = siteConfigItem.Email_Title; var replyToEmail = Sitecore.Context.User.Profile.Email; if (string.IsNullOrEmpty(fromEmail) || string.IsNullOrEmpty(replyToEmail)) { return; } var isAuthorInSenderList = false; var notificationList = !articleStruct.ArticleSpecificNotifications.Any() ? new List <StaffStruct>() : articleStruct.ArticleSpecificNotifications; Logger.SitecoreInfo($"EmailUtil.SendNotification: Notification List - {string.Join(",", notificationList.Select(a => GetStaffEmail(a.ID)))}"); //IIPP-1092 try { var stateItem = _service.GetItem <Informa.Models.Informa.Models.sitecore.templates.System.Workflow.ICommand>( articleStruct.CommandID.ToString()); if (stateItem != null) { var workflowitem = _service.GetItem <Informa.Models.Informa.Models.sitecore.templates.System.Workflow.IState>(stateItem.Next_State); var workflowBasednotificationList = workflowitem.Staffs; foreach (var eachUser in workflowBasednotificationList) { try { var toSender = new StaffStruct { ID = eachUser._Id }; notificationList.Add(toSender); } catch (Exception ex) { Logger.SitecoreError($"EmailUtil.SendNotification: {ex}"); } } } } catch (Exception ex) { Logger.SitecoreError($"EmailUtil.SendNotification: Failed to find the workflow item. {ex}"); } var emailBody = CreateBody(articleStruct, title, siteConfigItem.Publication_Name, oldWorkflow); foreach (var eachEmail in notificationList) { var staffEmail = GetStaffEmail(eachEmail.ID); if (string.IsNullOrEmpty(staffEmail)) { continue; } Email email = new Email { To = staffEmail, Subject = title, From = fromEmail, Body = emailBody, IsBodyHtml = true }; Logger.SitecoreInfo($"EmailUtil.SendNotification: notifying - {staffEmail}"); EmailSender.SendWorkflowNotification(email, replyToEmail); if (replyToEmail == staffEmail) { isAuthorInSenderList = true; } } if (isAuthorInSenderList) { return; } //Emailing the Content Author Email contentAuthorEmail = new Email { To = replyToEmail, Subject = title, From = fromEmail, Body = emailBody, IsBodyHtml = true }; Logger.SitecoreInfo($"EmailUtil.SendNotification: sending author - {contentAuthorEmail}"); EmailSender.SendWorkflowNotification(contentAuthorEmail, replyToEmail); }
public string CreateBody(ArticleStruct articleStruct, string emailTitle, string publication, WorkflowInfo oldWorkflow) { var htmlEmailTemplate = HtmlEmailTemplateFactory.Create("Workflow"); string siteRoot = HttpContext.Current.Request.Url.Host; if (htmlEmailTemplate == null) { return(null); } var article = _articleUtil.GetArticleItemByNumber(articleStruct.ArticleNumber); var authorString = string.Empty; foreach (var eachAuthor in articleStruct.Authors) { authorString = eachAuthor.Name + ","; } var emailHtml = htmlEmailTemplate.Html; var replacements = new Dictionary <string, string>(); replacements["#Email_Title#"] = emailTitle; replacements["#Article_Title#"] = string.IsNullOrEmpty(articleStruct.Title) ? article.Fields["Title"].Value : articleStruct.Title; replacements["#Publish_Date#"] = articleStruct.WebPublicationDate.ToString(); replacements["#word_url#"] = GetWordURL(articleStruct); ArticleItem articleItem = _service.GetItem <ArticleItem>(article.ID.ToString()); if (articleItem != null) { var preview = _articleUtil.GetPreviewInfo(articleItem); if (preview != null) { replacements["#preview_url#"] = preview.PreviewUrl; } } replacements["#Authors#"] = string.IsNullOrEmpty(authorString) ? "No authors selected" : authorString; replacements["#Publication#"] = publication; replacements["#show_notes#"] = "Notes: "; replacements["#Body_Content#"] = articleStruct.NotificationText; if (articleStruct.NotificationText == "") { replacements["#show_notes#"] = ""; replacements["#Body_Content#"] = ""; } replacements["#content_editor#"] = Sitecore.Context.User.Profile.FullName; replacements["#current_time#"] = DateTime.Now.ToString(); var oldState = _service.Database.WorkflowProvider.GetWorkflow(oldWorkflow.StateID); if (oldState != null) { //replacements["#old_state_image#"] = "https://" + siteRoot + oldState.Appearance.Icon; replacements["#old_state#"] = oldState.Appearance.DisplayName; } var newState = _service.Database.WorkflowProvider.GetWorkflow(articleStruct.CommandID.ToString()); if (newState != null) { //replacements["#new_state_image#"] = "https://" + siteRoot + newState.Appearance.Icon; replacements["#new_state#"] = newState.Appearance.DisplayName; } List <WorkflowEvent> workflowHistory = GetWorkflowHistory(article); replacements["#history#"] = HistoryTableCreation(workflowHistory); var eHtml = emailHtml.ReplacePatternCaseInsensitive(replacements); return(eHtml); }