Ejemplo n.º 1
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();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks out article associated with _parent.ArticleDetails.ArticleGuid
        /// </summary>
        /// <returns></returns>
        public bool CheckOut(bool prompt = false)
        {
            Guid articleGuid = _parent.ArticleDetails.ArticleGuid;

            if (articleGuid == Guid.Empty)
            {
                MessageBox.Show
                    (@"No article associated with file.", @"Informa",
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }

            try
            {
                bool exists = SitecoreClient.DoesArticleExist(articleGuid);
                if (!exists)
                {
                    MessageBox.Show
                        (@"Article no longer exists on Sitecore", @"Informa",
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }
                ArticleNumber = _parent.ArticleDetails.ArticleNumber;
                //uxArticleNumberLabel.Text = ArticleNumber;


                PluginModels.CheckoutStatus checkedOut = SitecoreClient.GetLockedStatus(articleGuid);

                if (SitecoreClient.DoesArticleHaveText(articleGuid) && prompt)
                {
                    DialogResult dialogResult = MessageBox.Show
                                                    (@"This article already has some content uploaded. "
                                                    + @"If you choose to check out the article now and later upload, "
                                                    + @"you will overwrite that content. "
                                                    + @"Are you sure you wish to checkout this article?",
                                                    @"Informa",
                                                    MessageBoxButtons.YesNo,
                                                    MessageBoxIcon.Question);
                    if (dialogResult != DialogResult.Yes)
                    {
                        return(false);
                    }
                }
                if (!checkedOut.Locked)
                {
                    if (_parent.CloseOnSuccessfulLock)
                    {
                        if (DialogFactory.PromptAutoLock() == DialogResult.Yes)
                        {
                            SitecoreClient.CheckOutArticle(articleGuid, SitecoreUser.GetUser().Username);
                        }
                    }
                    else
                    {
                        SitecoreClient.CheckOutArticle(articleGuid, SitecoreUser.GetUser().Username);
                    }
                }
                SetCheckedOutStatus();
                if (_parent.CloseOnSuccessfulLock && IsCheckedOutByMe)
                {
                    return(true);
                }
                //establish link, regardless of lock status
                _parent.SetArticleDetails(SitecoreClient.ForceReadArticleDetails(articleGuid));
                _parent.UpdateFields();
                return(true);
            }
            catch (Exception ex)
            {
                Globals.SitecoreAddin.LogException("Error in article details when checking out article: " + articleGuid, ex);
                throw;
            }
        }