Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        private void SaveArticleToSitecoreUpdateUI(ArticleDocumentMetadataParser metadataParser, string body = null)
        {
            _documentCustomProperties.ArticleNumber = GetArticleNumber();
            InvalidStylesHighlighter highlighter = InvalidStylesHighlighter.GetParser();
            bool hasInvalidStyles = highlighter.HighlightAllInvalidStyles(Globals.SitecoreAddin.Application.ActiveDocument);

            if (hasInvalidStyles && !AskContinueInvalidStyle())
            {
                return;
            }
            if (!articleDetailsPageSelector.pageWorkflowControl.uxUnlockOnSave.Checked)
            {
                var saved = SaveArticle(metadataParser, body);

                if (!saved)
                {
                    return;
                }
            }
            else
            {
                var saved = articleDetailsPageSelector.pageArticleInformationControl.CheckIn();
                if (!saved)
                {
                    return;
                }
            }

            DocumentPropertyEditor.WritePublicationAndDate(SitecoreAddin.ActiveDocument, articleDetailsPageSelector.GetPublicationName(), articleDetailsPageSelector.GetProperDate());

            articleDetailsPageSelector.pageWorkflowControl.UpdateFields(ArticleDetails.ArticleGuid != Guid.Empty
                                            ? SitecoreClient.GetWorkflowState(ArticleDetails.ArticleGuid)
                                            : SitecoreClient.GetWorkflowState(ArticleDetails.ArticleNumber), ArticleDetails);

            articleDetailsPageSelector.pageRelatedArticlesControl.PushSitecoreChanges();
            UpdateFieldsAfterSave();
            articleDetailsPageSelector.ResetChangedStatus(true);
            MessageBox.Show(@"Article successfully saved to Sitecore!", @"Informa");
            return;
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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;
            }
        }