Example #1
0
 /// <summary>
 ///
 /// </summary>
 /// <returns>Null if no article number has been set to the document;
 /// otherwise, the article number set to the document</returns>
 public string GetArticleNumber()
 {
     SitecoreAddin.TagActiveDocument();
     _documentCustomProperties    = new DocumentCustomProperties(SitecoreAddin.ActiveDocument);
     ArticleDetails.ArticleNumber = _documentCustomProperties.ArticleNumber;
     return(ArticleDetails.ArticleNumber);
 }
Example #2
0
        /// <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);
        }
Example #3
0
        void Application_BeforeDocumentClose(Word.Document doc, ref bool cancel)
        {
            var documentCustomProps = new DocumentCustomProperties(doc);

            Application.DocumentChange -= Application_DocumentChange_UpdateRibbon;

            if (documentCustomProps.ArticleNumber.IsNullOrEmpty())
            { // If this isn't an elsevier article, default to the normal process
                return;
            }

            if (!doc.Saved)
            {
                var dialog = new SaveDialog();
                dialog.ShowDialog();

                switch (dialog.SelectedChoice)
                {
                case SaveDialog.SaveChoice.SaveToSitecoreAndUnlock:
                    // at this point, there can be no metadata changes, only body text changes.
                    var _sitecoreClient = new SitecoreClient();
                    var errors          = _sitecoreClient.SaveArticle(doc, SitecoreClient.ForceReadArticleDetails(documentCustomProps.ArticleNumber),
                                                                      Guid.Empty, new List <StaffStruct>(), documentCustomProps.ArticleNumber);

                    if (errors.Count > 0)
                    {
                        MessageBox.Show
                            (@"There was an error saving the document to Sitecore. Please try again." + Environment.NewLine +
                            Environment.NewLine + @"If the problem persists, contact your system administrator.",
                            @"Informa",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                        cancel = true;
                    }
                    else
                    {
                        doc.Saved = true;
                        SitecoreClient.CheckInArticle(documentCustomProps.ArticleNumber);
                    }
                    break;

                case SaveDialog.SaveChoice.SaveLocal:
                    doc.Save();
                    break;

                case SaveDialog.SaveChoice.Cancel:
                    cancel = true;
                    break;

                case SaveDialog.SaveChoice.DontSave:
                    doc.Saved = true;
                    break;
                }
            }
        }
Example #4
0
        /// <summary>
        /// Get from sitecore checked out status, then set control accordingly
        ///
        /// Unprotects document if locked by current user
        /// </summary>
        public void SetCheckedOutStatus()
        {
            if (_parent == null || _parent.ArticleDetails == null)
            {
                return;
            }
            DocumentCustomProperties = new DocumentCustomProperties(SitecoreAddin.ActiveDocument);
            string articleNum = _parent.GetArticleNumber();

            if (!string.IsNullOrEmpty(_articleNumber))
            { //document is linked to an article
                SetArticleNumber(articleNum);
                CheckoutStatus checkedOut;
                if (_parent.ArticleDetails.ArticleGuid != Guid.Empty)
                {
                    checkedOut = SitecoreClient.GetLockedStatus(_parent.ArticleDetails.ArticleGuid);
                }
                else
                {
                    checkedOut = SitecoreClient.GetLockedStatus(articleNum);
                }
                _articleInformationControl.IsCheckedOut = checkedOut.Locked;
                if (_articleInformationControl.IsCheckedOut)
                {
                    if (SitecoreUser.GetUser().Username == checkedOut.User)
                    { //locked by me
                        IndicateCheckedOutByMe(checkedOut);
                        _parent.articleStatusBar1.ChangeLockButtonStatus(LockStatus.Locked);
                        _articleInformationControl.UpdateControlsForLockedStatus();
                    }
                    else
                    { //locked by other
                        IndicateCheckedOutByOther(checkedOut);
                        _parent.articleStatusBar1.ChangeLockButtonStatus(LockStatus.Locked);
                        _articleInformationControl.UpdateControlsForUnlockedStatus();
                    }
                    uxLockStatusLabel.Text = @"Locked";
                }
                else
                { //unlocked
                    IndicateUnlocked();
                    _articleInformationControl.UpdateControlsForUnlockedStatus();
                }
                uxRefreshStatus.Enabled = true;
            }
            else
            { //document is not linked to an article
                DocumentProtection.Unprotect(DocumentCustomProperties);
                _articleInformationControl.IsCheckedOutByMe = false;
                _articleInformationControl.IsCheckedOut     = false;
                _parent.PreLinkEnable();
            }
        }
Example #5
0
 private void ArticleInformationControl_Load(object sender, EventArgs e)
 {
     if (!DesignMode)
     {
         var wordApp = SitecoreAddin.ActiveDocument.Application;
         if (wordApp == null)
         {
             return;
         }
         bool currentSavedState = SitecoreAddin.ActiveDocument.Saved;
         SitecoreAddin.ActiveDocument.Saved = currentSavedState;
         _documentCustomProperties          = new DocumentCustomProperties(SitecoreAddin.ActiveDocument);
     }
 }
Example #6
0
        /// <summary>
        /// Get from sitecore checked out status, then set control accordingly
        ///
        /// Unprotects document if locked by current user
        /// </summary>
        public void SetCheckedOutStatus()
        {
            if (_parent == null || _parent.ArticleDetails == null)
            {
                return;
            }
            _documentCustomProperties = new DocumentCustomProperties(SitecoreAddin.ActiveDocument);
            string articleNum = _parent.GetArticleNumber();

            if (!articleNum.IsNullOrEmpty())
            { //document is linked to an article
                SetArticleNumber(articleNum);
                PluginModels.CheckoutStatus checkedOut;
                if (_parent.ArticleDetails.ArticleGuid != Guid.Empty)
                {
                    checkedOut = SitecoreClient.GetLockedStatus(_parent.ArticleDetails.ArticleGuid);
                }
                else
                {
                    checkedOut = SitecoreClient.GetLockedStatus(articleNum);
                }
                IsCheckedOut = checkedOut.Locked;
                if (IsCheckedOut)
                {
                    if (SitecoreUser.GetUser().Username == checkedOut.User)
                    { //locked by me
                        IndicateCheckedOutByMe(checkedOut);
                    }
                    else
                    { //locked by other
                        IndicateCheckedOutByOther(checkedOut);
                    }
                    //uxLockStatusLabel.Text = @"Locked";
                }
                else
                { //unlocked
                    IndicateUnlocked();
                }
                //uxRefreshStatus.Enabled = true;
            }
            else
            { //document is not linked to an article
                DocumentProtection.Unprotect(_documentCustomProperties);
                IsCheckedOutByMe = false;
                IsCheckedOut     = false;

                _parent.PreLinkEnable();
            }
        }
Example #7
0
        /// <summary>
        /// Initializes the fields based on the information associated with the document,
        /// or lack thereof
        /// </summary>
        private void InitializeFields()
        {
            _documentCustomProperties = new DocumentCustomProperties(SitecoreAddin.ActiveDocument);
            SetArticleNumber(_documentCustomProperties.ArticleNumber);
            string articleNumber = GetArticleNumber();

            if (!articleNumber.IsNullOrEmpty())
            {
                SetArticleDetails(SitecoreClient.LazyReadArticleDetails(GetArticleNumber()));
                PostLinkEnable();
            }
            else
            {
                PreLinkEnable();
            }
        }
        private void refreshState()
        {
            try
            {
                var documentCustomProperties = new DocumentCustomProperties(SitecoreAddin.ActiveDocument);
                using (ArticleDetailFieldsUpdateDisabler disabler = new ArticleDetailFieldsUpdateDisabler())
                {
                    var updatedArticleDetail = new ArticleDetail();

                    var localDocVersion    = documentCustomProperties.WordSitecoreVersionNumber;
                    var sitecoreDocVersion = SitecoreClient.GetWordVersionNumber(_parentForm.ArticleDetails.ArticleGuid);

                    if (sitecoreDocVersion > localDocVersion)
                    {
                        Color color = (Color) new ColorConverter().ConvertFromString("#F4CCCC");
                        this.BackColor = color;
                        lblTitle.Text  = "This document is Outdated";
                    }
                    else
                    {
                        Color color = (Color) new ColorConverter().ConvertFromString("#d9ead3");
                        this.BackColor = color;
                        lblTitle.Text  = "This document is Up to Date";
                    }

                    var user = SitecoreClient.GetFullNameAndEmail(updatedArticleDetail.ArticleDetails.WordDocLastUpdatedBy);

                    lblBy.Text = user[0];

                    DateTime dt;
                    if (updatedArticleDetail.ArticleDetails != null && DateTime.TryParse(updatedArticleDetail.ArticleDetails.WordDocLastUpdateDate, out dt))
                    {
                        lblUpdatedOn.Text = dt.ToLocalTime().ToString(CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        lblUpdatedOn.Text = _parentForm.ArticleDetails.WordDocLastUpdateDate.ToString(CultureInfo.InvariantCulture);
                    }
                }
            }
            catch (Exception ex)
            {
                Globals.SitecoreAddin.LogException("refreshState ex: " + ex.ToString());
            }
        }
Example #9
0
        protected void SendWordDocumentToSitecore(Document activeDocument, DocumentCustomProperties documentCustomProperties, string articleNumber, ArticleStruct articleDetails)
        {
            string extension = GetExtension(activeDocument);

            DocumentProtection.Protect(documentCustomProperties);

            byte[] data = _wordUtils.GetWordBytes(activeDocument);
            if (data == null)
            {
                throw new Exception("Error saving file to disk.");
            }

            DocumentProtection.Unprotect(documentCustomProperties);
            string uploader = SitecoreUser.GetUser().Username;
            int    wordSitecoreVersionNumber = articleDetails.ArticleGuid != Guid.Empty
                                                ? this.SendDocumentToSitecoreByGuid(articleDetails.ArticleGuid, data, extension, uploader)
                                                : this.SendDocumentToSitecore(articleNumber, data, extension, uploader);

            documentCustomProperties.WordSitecoreVersionNumber = wordSitecoreVersionNumber;
        }
Example #10
0
        void OpenArticleInformationWindowIfNeeded(Word.Document doc)
        {
            var props = new DocumentCustomProperties(doc);

            if (props.PluginName != Constants.InformaPluginName)
            {
                return;
            }
            string articleNumber = props.ArticleNumber;

            if (!string.IsNullOrEmpty(articleNumber))
            {
                Log("Document opened with article number: " + articleNumber);
                if (!SitecoreUser.GetUser().IsLoggedIn)
                {
                    ArticleDetail.Open(true);
                }
                else
                {
                    CheckoutStatus checkedOut = SitecoreClient.GetLockedStatus(articleNumber);
                    if (checkedOut.User == SitecoreUser.GetUser().Username)
                    {
                        DocumentProtection.Unprotect(props);
                        return;
                    }
                    if (!checkedOut.Locked)
                    {
                        if (DialogFactory.PromptAutoLock() == DialogResult.Yes &&
                            SitecoreClient.CheckOutArticle(articleNumber, SitecoreUser.GetUser().Username))
                        {
                            DocumentProtection.Unprotect(props);
                        }
                    }
                    else
                    {
                        ArticleDetail.Open();
                    }
                }
            }
        }
Example #11
0
        /// <summary>
        ///
        /// </summary>
        public ArticleDetail()
        {
            SitecoreAddin.TagActiveDocument();

            _sitecoreArticle             = new SitecoreClient();
            _documentCustomProperties    = new DocumentCustomProperties(SitecoreAddin.ActiveDocument);
            _structConverter             = new StructConverter();
            ArticleDetails.ArticleNumber = _documentCustomProperties.ArticleNumber;

            InitializeComponent();

            articleDetailsPageSelector.LinkToParent(this);


            articleStatusBar1.LinkToParent(this);
            if (!string.IsNullOrEmpty(_documentCustomProperties.ArticleNumber))
            {
                articleStatusBar1.DisplayStatusBar(true, _documentCustomProperties.ArticleNumber);
            }
            else
            {
                articleStatusBar1.DisplayStatusBar(false, _documentCustomProperties.ArticleNumber);
            }

            if (this.articleDetailsPageSelector.pageArticleInformationControl._isCheckedOut)
            {
                articleStatusBar1.ChangeLockButtonStatus(LockStatus.Unlocked);
            }
            else
            {
                articleStatusBar1.ChangeLockButtonStatus(LockStatus.Locked);
            }

            articleDetailsPageSelector.InitializePages();
            SitecoreUser.GetUser().ResetAuthenticatedSubscription();
            SitecoreUser.GetUser().Authenticated += PopulateFieldsOnAuthentication;
            InitializeLogin();
        }
Example #12
0
        /// <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);
        }
Example #13
0
        public ArticleDetails()
        {
            try
            {
                Globals.SitecoreAddin.Log("Initializing the article details window...");
                InitializeComponent();
                Opacity = 0;

                _scTree   = new SCTree();
                _scServer = new SCServer();

                // TEMPORARY code to deal with QA login
                var credCache = new CredentialCache();
                var netCred   =
                    new NetworkCredential("velir", "ebi3000");
                credCache.Add(new Uri(_scTree.Url), "Basic", netCred);
                credCache.Add(new Uri(_scServer.Url), "Basic", netCred);

                _scTree.PreAuthenticate = true;
                _scTree.Credentials     = credCache;

                _scServer.PreAuthenticate = true;
                _scServer.Credentials     = credCache;

                // end temporary

                _user = SitecoreUser.GetUser();

                _authors = _scTree.GetAuthors().Select(t => new StaffStruct()
                {
                    ID = t.ID, Name = t.Name, Publications = t.Publications
                }).ToArray().ToList();
                _editors = _scTree.GetEditors().Select(t => new StaffStruct()
                {
                    ID = t.ID, Name = t.Name, Publications = t.Publications
                }).ToArray().ToList();

                _sitecoreArticle          = new SitecoreArticle();
                _wordUtils                = new WordUtils();
                _wordApp                  = SitecoreAddin.WordApp;
                _documentCustomProperties = new DocumentCustomProperties(_wordApp, _wordApp.ActiveDocument);


                try
                {
                    InitializeDropdowms();
                    InitializeControllers();
                    Opacity = 1;

                    SetCheckedOutStatus();

                    _connectedAtStart = true;
                }
                catch
                (WebException e)
                {
                    AlertConnectionFailed();
                    Globals.SitecoreAddin.LogException("Error getting metadata or checked out status!", e);
                    throw new ApplicationException("Error getting metadata or checked out status!", e);
                }

                var deleteIcon = new ImageList();
                deleteIcon.Images.Add(Resources.delete_icon);
                uxSelectedAuthors.SmallImageList = deleteIcon;
                uxSelectedEditors.SmallImageList = deleteIcon;

                string articleNumber = GetArticleNumber();
                if (!articleNumber.IsNullOrEmpty())
                {
                    uxArticleNumber.Text = articleNumber;
                    GetArticeDetailsFromSitecore();
                }
                uxLockStatus.Refresh();
                Globals.SitecoreAddin.Log("Article details window initialized.");
            }
            catch (Exception ex)
            {
                Globals.SitecoreAddin.LogException("Error while loading article details!", ex);
            }
        }
Example #14
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;
            }
        }