public void SaveArticleData() { Globals.SitecoreAddin.Log("Save and transferring"); SuspendLayout(); SitecoreAddin.ActiveDocument.Saved = false; _wordUtils = new WordUtils(); try { var metadataParser = new ArticleDocumentMetadataParser(SitecoreAddin.ActiveDocument, _wordUtils.CharacterStyleTransformer); if (PreSavePrompts(metadataParser)) { return; } SaveArticleToSitecoreUpdateUi(metadataParser); } catch (WebException wex) { AlertConnectionFailure(); Globals.SitecoreAddin.LogException("Web connection error when saving and transferring article!", wex); } catch (Exception ex) { Globals.SitecoreAddin.LogException("Error when saving and transferring article!", ex); MessageBox.Show(@"Error when saving and transferring article! Error recorded in logs.", @"Informa"); } finally { ResumeLayout(); } Document activeDocument = SitecoreAddin.ActiveDocument; var path = activeDocument.Path; if (!activeDocument.ReadOnly && !string.IsNullOrWhiteSpace(path)) { WordUtils.Save(activeDocument); } }
private void uxSaveAndTransfer_Click(object sender, EventArgs e) { var command = articleDetailsPageSelector.pageWorkflowControl.GetSelectedCommandState(); // Checking for Taxonomy is the workflow state is final if (command.SendsToFinal && articleDetailsPageSelector.GetTaxonomyCount() < 1) { MessageBox.Show(@"Select at least one taxonomy item for the article!", @"Informa", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } try { Cursor = Cursors.WaitCursor; if (articleDetailsPageSelector.pageWorkflowControl.uxUnlockOnSave.Enabled) { workflowChange_UnlockOnSave = articleDetailsPageSelector.pageWorkflowControl.uxUnlockOnSave.Checked; } var articleDate = articleDetailsPageSelector.GetDate(); //var timeUtc = DateTime.UtcNow; //TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); DateTime currentTime = DateTime.Now;// TimeZoneInfo.ConvertTimeFromUtc(timeUtc, easternZone); if (articleDate < currentTime) { var result = WantsToSetArticleDateToNow(command); if (result == DialogResult.Yes) { articleDetailsPageSelector.SetDate(DateTime.Now, true); } else if (result == DialogResult.Cancel) { MessageBox.Show("Save cancelled."); return; } } Globals.SitecoreAddin.Log("Save and transferring"); SuspendLayout(); SitecoreAddin.ActiveDocument.Saved = false; var metadataParser = new ArticleDocumentMetadataParser(SitecoreAddin.ActiveDocument, _wordUtils.CharacterStyleTransformer); if (PreSavePrompts(metadataParser)) { return; } SaveArticleToSitecoreUpdateUI(metadataParser); articleStatusBar1.RefreshWorkflowDetails(); } catch (WebException wex) { AlertConnectionFailure(); Globals.SitecoreAddin.LogException("Web connection error when saving and transferring article!", wex); } catch (Exception ex) { Globals.SitecoreAddin.LogException("Error when saving and transferring article!", ex); MessageBox.Show(@"Error when saving and transferring article! Error recorded in logs.", @"Informa"); } finally { ResumeLayout(); Cursor = Cursors.Default; workflowChange_UnlockOnSave = false; } Document activeDocument = SitecoreAddin.ActiveDocument; var path = activeDocument.Path; if (!activeDocument.ReadOnly && !string.IsNullOrWhiteSpace(path)) { WordUtils.Save(activeDocument); } }
private void uxSaveMetadata_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; var command = articleDetailsPageSelector.pageWorkflowControl.GetSelectedCommandState(); // Checking for Taxonomy is the workflow state is final if (command.SendsToFinal && articleDetailsPageSelector.GetTaxonomyCount() < 1) { MessageBox.Show(@"Select at least one taxonomy item for the article!", @"Informa", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } try { if (articleDetailsPageSelector.pageWorkflowControl.uxUnlockOnSave.Enabled) { workflowChange_UnlockOnSave = articleDetailsPageSelector.pageWorkflowControl.uxUnlockOnSave.Checked; } var articleDate = articleDetailsPageSelector.GetDate(); //var timeUtc = DateTime.UtcNow; //TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); DateTime currentTime = DateTime.Now;// TimeZoneInfo.ConvertTimeFromUtc(timeUtc, easternZone); if (articleDate < currentTime) { var result = WantsToSetArticleDateToNow(command); if (result == DialogResult.Yes) { articleDetailsPageSelector.SetDate(DateTime.Now, true); } else if (result == DialogResult.Cancel) { MessageBox.Show("Save cancelled."); return; } } SuspendLayout(); var isPublished = ArticleDetails.IsPublished; Guid guidCopy = ArticleDetails.ArticleGuid; ArticleDetails = articleDetailsPageSelector.GetArticleDetailsWithoutDocumentParsing(); ArticleDetails.ArticleGuid = guidCopy; ArticleDetails.IsPublished = isPublished; ArticleDetails.IsPublished = ArticleDetails.IsPublished; ArticleDetails.ArticleSpecificNotifications = articleDetailsPageSelector.pageWorkflowControl.GetNotifyList(); ArticleDetails.WordCount = SitecoreAddin.ActiveDocument.ComputeStatistics(0); ArticleDetails.CommandID = articleDetailsPageSelector.pageWorkflowControl.GetSelectedCommand(); ArticleDetails.NotificationText = articleDetailsPageSelector.pageWorkflowControl.GetNotificationText(); var lockStateBeforeSaveMetaData = SitecoreClient.GetLockedStatus(ArticleDetails.ArticleGuid); SitecoreClient.SaveMetadataToSitecore(ArticleDetails.ArticleNumber, _structConverter.GetServerStruct(ArticleDetails)); //I know the following checks are weird, but issue IIPP-1031 occurs sometimes only on UAT env. So had to hack around it. //On UAT after SaveMetadataToSitecore, the locked status becomes false for no apparent reason. var lockStateAfterSaveMetaData = SitecoreClient.GetLockedStatus(ArticleDetails.ArticleGuid); if (lockStateBeforeSaveMetaData.Locked && lockStateAfterSaveMetaData.Locked == false && workflowChange_UnlockOnSave == false) { SitecoreClient.CheckOutArticle(ArticleDetails.ArticleNumber, SitecoreUser.GetUser().Username); } if (articleDetailsPageSelector.pageWorkflowControl.uxUnlockOnSave.Checked) { articleDetailsPageSelector.pageArticleInformationControl.CheckIn(false); } articleDetailsPageSelector.pageWorkflowControl.UpdateFields(ArticleDetails.ArticleGuid != Guid.Empty ? SitecoreClient.GetWorkflowState(ArticleDetails.ArticleGuid) : SitecoreClient.GetWorkflowState(ArticleDetails.ArticleNumber), ArticleDetails); articleDetailsPageSelector.pageRelatedArticlesControl.PushSitecoreChanges(); articleDetailsPageSelector.UpdateFields(); articleDetailsPageSelector.ResetChangedStatus(true); UpdateFieldsAfterSave(); DocumentPropertyEditor.WritePublicationAndDate(SitecoreAddin.ActiveDocument, articleDetailsPageSelector.GetPublicationName(), articleDetailsPageSelector.GetProperDate()); //TamerM - 2016-03-22: Prompt and ReExport NLM FEED NLMFeedUtils.PromptAndReExportNLMFeed(ArticleDetails.ArticleNumber, ArticleDetails.IsPublished); if (workflowChange_UnlockOnSave) { EnablePreview(); uxCreateArticle.Visible = false; } articleStatusBar1.RefreshWorkflowDetails(); MessageBox.Show(@"Metadata saved!", @"Informa"); } catch (WebException wex) { AlertConnectionFailure(); Globals.SitecoreAddin.LogException("Web connection error when saving metadata!", wex); } catch (Exception ex) { Globals.SitecoreAddin.LogException("Error when saving meta data!", ex); MessageBox.Show(@"Error when saving metadata! Error recorded in logs.", @"Informa"); } finally { ResumeLayout(); Cursor = Cursors.Default; workflowChange_UnlockOnSave = false; } Document activeDocument = SitecoreAddin.ActiveDocument; var path = activeDocument.Path; if (!activeDocument.ReadOnly && !string.IsNullOrWhiteSpace(path)) { WordUtils.Save(activeDocument); } }
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; } }