Esempio n. 1
0
        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;
            }
        }