/// <summary> /// Creates a new Sitecore Article Item based on the selected publication, /// date, issue, and title. Alerts the user of invalid input /// /// Be sure to catch WebException indicating if server cannot be contacted /// </summary> /// <returns>An ArticleStruct with relevant information if successful; otherwise null</returns> private ArticleStruct CreateSitecoreArticleItem() { var articleDetails = articleDetailsPageSelector.GetArticleDetails(); string title = articleDetails.Title.TrimEnd(); if (SitecoreClient.DoesArticleNameAlreadyExistInIssue(articleDetails)) { MessageBox.Show (@"This article title is already taken for this issue. Please choose another title or another issue.", @"Informa", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } //// Old Code (Ticket IIS-589) // string webPublishDate = articleDetails.WebPublicationDate.ToString(System.Globalization.CultureInfo.GetCultureInfo("en-US")); Guid pubGuid = articleDetails.Publication; if (string.IsNullOrEmpty(title)) { MessageBox.Show(@"Please enter an article title.", @"Informa", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } if (articleDetailsPageSelector.GetPublicationGuid().Equals(Guid.Empty)) { MessageBox.Show(@"Please select a publication.", @"Informa", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } SuspendLayout(); ArticleStruct astruct = _sitecoreArticle.SaveStubToSitecore(title, articleDetails.WebPublicationDate, pubGuid); if (string.IsNullOrEmpty(astruct.RemoteErrorMessage) == false) { Globals.SitecoreAddin.Log("SaveStubToSitecore returned astruct object with StatusCode/Error: " + astruct.RemoteErrorMessage); articleDetails.RemoteErrorMessage = astruct.RemoteErrorMessage; } else { articleDetails.ArticleNumber = astruct.ArticleNumber; articleDetails.ArticleGuid = astruct.ArticleGuid; SitecoreClient.SaveArticleDetailsByGuid(astruct.ArticleGuid, _structConverter.GetServerStruct(articleDetails)); } ResumeLayout(); return(articleDetails); }
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); } }
private void uxCreateArticle_Click(object sender, EventArgs e) { SuspendLayout(); Cursor = Cursors.WaitCursor; string body; try { XElement xbody = _wordUtils.GetWordDocTextWithStyles(SitecoreAddin.ActiveDocument); body = xbody.ToString(); } catch (InsecureIFrameException insecureIframe) { string message = String.Empty; foreach (string iframeURL in insecureIframe.InsecureIframes) { message += String.Format("\n{0}", iframeURL); } MessageBox.Show("The following multimedia content is not secure. Please correct and try to save again. " + message, "Non-secure Multimedia Content"); return; } catch (InvalidHtmlException) { return; } catch (Exception ex) { MessageBox.Show(@"The document could not be parsed to transfer to Sitecore! Details in logs.", @"Informa"); Globals.SitecoreAddin.LogException("Error when parsing article on creation!", ex); return; } finally { Cursor.Current = Cursors.Default; } try { Cursor.Current = Cursors.WaitCursor; var metadataParser = new ArticleDocumentMetadataParser(SitecoreAddin.ActiveDocument, _wordUtils.CharacterStyleTransformer); if (PreSavePrompts(metadataParser)) { return; } ArticleDetails = CreateSitecoreArticleItem(); if (ArticleDetails != null) { if (string.IsNullOrEmpty(ArticleDetails.ArticleNumber)) { if (ArticleDetails.RemoteErrorMessage == HttpStatusCode.Unauthorized.ToString()) { MessageBox.Show(Constants.SESSIONTIMEOUTERRORMESSAGE); return; } else { MessageBox.Show(@"The article number generator is busy! Please try again later.", @"Informa"); } } else { _documentCustomProperties.ArticleNumber = ArticleDetails.ArticleNumber; articleDetailsPageSelector.CheckOut(); _documentCustomProperties.ArticleNumber = GetArticleNumber(); articleStatusBar1.DisplayStatusBar(true, _documentCustomProperties.ArticleNumber); DocumentPropertyEditor.WritePublicationAndDate( SitecoreAddin.ActiveDocument, articleDetailsPageSelector.GetPublicationName(), articleDetailsPageSelector.GetProperDate()); PostLinkEnable(); SaveArticleToSitecoreUpdateUI(metadataParser, body); } } } catch (WebException wex) { AlertConnectionFailure(); Globals.SitecoreAddin.LogException("Web connection error when creating article!", wex); } catch (Exception ex) { Globals.SitecoreAddin.LogException("Error when creating article!", ex); MessageBox.Show(@"Error when creating article! Error recorded in logs.", @"Informa"); } finally { ResumeLayout(); Cursor = Cursors.Default; } }
/// <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); }
/// <summary> /// Sets the member ArticleStruct ArticleDetails to the inputted /// ArticleStruct articleStruct /// </summary> /// <param name="articleStruct"></param> public void SetArticleDetails(ArticleStruct articleStruct) { ArticleDetails = articleStruct; }