/// <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); }
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); } }
/// <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 isPublish = ArticleDetails.IsPublished; var copy = ArticleDetails.ArticleGuid; ArticleDetails = articleDetailsPageSelector.GetArticleDetails(metadataParser); ArticleDetails.ArticleGuid = copy; ArticleDetails.IsPublished = isPublish; _Live = isPublish; //List<string> errors = _sitecoreArticle.SaveArticle(SitecoreAddin.ActiveDocument, ArticleDetails, new Guid(), new StaffStruct[0], GetArticleNumber(), body); //Uncomment this after workflow is tested properly. List <string> errors = _sitecoreArticle.SaveArticle(SitecoreAddin.ActiveDocument, ArticleDetails, articleDetailsPageSelector.pageWorkflowControl.GetSelectedCommand(), articleDetailsPageSelector.pageWorkflowControl.GetNotifyList(), GetArticleNumber(), body, articleDetailsPageSelector.pageWorkflowControl.GetNotificationText()); 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"); } } Cursor = Cursors.Arrow; return(false); } articleDetailsPageSelector.ResetChangedStatus(true); } } 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); }