当前位置: 首页>>代码示例>>C#>>正文


C# IContent.ChangePublishedState方法代码示例

本文整理汇总了C#中IContent.ChangePublishedState方法的典型用法代码示例。如果您正苦于以下问题:C# IContent.ChangePublishedState方法的具体用法?C# IContent.ChangePublishedState怎么用?C# IContent.ChangePublishedState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IContent的用法示例。


在下文中一共展示了IContent.ChangePublishedState方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PublishInternal

        /// <summary>
        /// Publishes a single piece of Content
        /// </summary>
        /// <param name="content"><see cref="IContent"/> to publish</param>
        /// <param name="userId">Id of the User issueing the publish operation</param>        
        internal Attempt<PublishStatus> PublishInternal(IContent content, int userId)
        {
            if (Publishing.IsRaisedEventCancelled(new PublishEventArgs<IContent>(content), this))
            {
                LogHelper.Info<PublishingStrategy>(
                        string.Format("Content '{0}' with Id '{1}' will not be published, the event was cancelled.", content.Name, content.Id));
                return new Attempt<PublishStatus>(false, new PublishStatus(content, PublishStatusType.FailedCancelledByEvent));
            }
                

            //Check if the Content is Expired to verify that it can in fact be published
            if (content.Status == ContentStatus.Expired)
            {
                LogHelper.Info<PublishingStrategy>(
                    string.Format("Content '{0}' with Id '{1}' has expired and could not be published.",
                                  content.Name, content.Id));
                return new Attempt<PublishStatus>(false, new PublishStatus(content, PublishStatusType.FailedHasExpired));
            }

            //Check if the Content is Awaiting Release to verify that it can in fact be published
            if (content.Status == ContentStatus.AwaitingRelease)
            {
                LogHelper.Info<PublishingStrategy>(
                    string.Format("Content '{0}' with Id '{1}' is awaiting release and could not be published.",
                                  content.Name, content.Id));
                return new Attempt<PublishStatus>(false, new PublishStatus(content, PublishStatusType.FailedAwaitingRelease));
            }

            //Check if the Content is Trashed to verify that it can in fact be published
            if (content.Status == ContentStatus.Trashed)
            {
                LogHelper.Info<PublishingStrategy>(
                    string.Format("Content '{0}' with Id '{1}' is trashed and could not be published.",
                                  content.Name, content.Id));
                return new Attempt<PublishStatus>(false, new PublishStatus(content, PublishStatusType.FailedIsTrashed));
            }

            content.ChangePublishedState(PublishedState.Published);

            LogHelper.Info<PublishingStrategy>(
                string.Format("Content '{0}' with Id '{1}' has been published.",
                              content.Name, content.Id));

            return new Attempt<PublishStatus>(true, new PublishStatus(content));
        }
开发者ID:CarlSargunar,项目名称:Umbraco-CMS,代码行数:50,代码来源:PublishingStrategy.cs

示例2: Publish

        /// <summary>
        /// Publishes a single piece of Content
        /// </summary>
        /// <param name="content"><see cref="IContent"/> to publish</param>
        /// <param name="userId">Id of the User issueing the publish operation</param>
        /// <returns>True if the publish operation was successfull and not cancelled, otherwise false</returns>
        public override bool Publish(IContent content, int userId)
        {
            if (Publishing.IsRaisedEventCancelled(new PublishEventArgs<IContent>(content), this))
                return false;

            //Check if the Content is Expired to verify that it can in fact be published
            if (content.Status == ContentStatus.Expired)
            {
                LogHelper.Info<PublishingStrategy>(
                    string.Format("Content '{0}' with Id '{1}' has expired and could not be published.",
                                  content.Name, content.Id));
                return false;
            }

            //Check if the Content is Awaiting Release to verify that it can in fact be published
            if (content.Status == ContentStatus.AwaitingRelease)
            {
                LogHelper.Info<PublishingStrategy>(
                    string.Format("Content '{0}' with Id '{1}' is awaiting release and could not be published.",
                                  content.Name, content.Id));
                return false;
            }

            //Check if the Content is Trashed to verify that it can in fact be published
            if (content.Status == ContentStatus.Trashed)
            {
                LogHelper.Info<PublishingStrategy>(
                    string.Format("Content '{0}' with Id '{1}' is trashed and could not be published.",
                                  content.Name, content.Id));
                return false;
            }

            content.ChangePublishedState(PublishedState.Published);

            LogHelper.Info<PublishingStrategy>(
                string.Format("Content '{0}' with Id '{1}' has been published.",
                              content.Name, content.Id));

            return true;
        }
开发者ID:Jeavon,项目名称:Umbraco-CMS,代码行数:46,代码来源:PublishingStrategy.cs

示例3: Save

        /// <summary>
        /// Saves a single <see cref="IContent"/> object
        /// </summary>
        /// <param name="content">The <see cref="IContent"/> to save</param>
        /// <param name="changeState">Boolean indicating whether or not to change the Published state upon saving</param>
        /// <param name="userId">Optional Id of the User saving the Content</param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events.</param>
        private void Save(IContent content, bool changeState, int userId = 0, bool raiseEvents = true)
        {
            if (raiseEvents)
            {
                if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IContent>(content), this))
                    return;
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateContentRepository(uow))
                {
                    content.WriterId = userId;

                    //Only change the publish state if the "previous" version was actually published or marked as unpublished
                    if (changeState && (content.Published || ((Content)content).PublishedState == PublishedState.Unpublished))
                        content.ChangePublishedState(PublishedState.Saved);

                    repository.AddOrUpdate(content);
                    uow.Commit();

                    //Preview Xml
                    var xml = content.ToXml();
                    CreateAndSavePreviewXml(xml, content.Id, content.Version, uow.Database);
                }

                if (raiseEvents)
                    Saved.RaiseEvent(new SaveEventArgs<IContent>(content, false), this);

                Audit.Add(AuditTypes.Save, "Save Content performed by user", userId, content.Id);
            }
        }
开发者ID:CarlSargunar,项目名称:Umbraco-CMS,代码行数:40,代码来源:ContentService.cs

示例4: Save

        /// <summary>
        /// Saves a single <see cref="IContent"/> object
        /// </summary>
        /// <param name="content">The <see cref="IContent"/> to save</param>
        /// <param name="changeState">Boolean indicating whether or not to change the Published state upon saving</param>
        /// <param name="userId">Optional Id of the User saving the Content</param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events.</param>
        private void Save(IContent content, bool changeState, int userId = 0, bool raiseEvents = true)
        {
            if (raiseEvents)
            {
                if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IContent>(content), this))
                    return;
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateContentRepository(uow))
                {
                    content.WriterId = userId;

                    //Only change the publish state if the "previous" version was actually published or marked as unpublished
                    if (changeState && (content.Published || ((Content)content).PublishedState == PublishedState.Unpublished))
                        content.ChangePublishedState(PublishedState.Saved);

                    repository.AddOrUpdate(content);
                    uow.Commit();

                    //Preview Xml
                    var xml = content.ToXml();
                    var previewPoco = new PreviewXmlDto
                    {
                        NodeId = content.Id,
                        Timestamp = DateTime.Now,
                        VersionId = content.Version,
                        Xml = xml.ToString(SaveOptions.None)
                    };
                    var previewExists =
                        uow.Database.ExecuteScalar<int>("SELECT COUNT(nodeId) FROM cmsPreviewXml WHERE nodeId = @Id AND versionId = @Version",
                                                                   new { Id = content.Id, Version = content.Version }) != 0;
                    int previewResult = previewExists
                                            ? uow.Database.Update<PreviewXmlDto>(
                                                "SET xml = @Xml, timestamp = @Timestamp WHERE nodeId = @Id AND versionId = @Version",
                                                new
                                                {
                                                    Xml = previewPoco.Xml,
                                                    Timestamp = previewPoco.Timestamp,
                                                    Id = previewPoco.NodeId,
                                                    Version = previewPoco.VersionId
                                                })
                                            : Convert.ToInt32(uow.Database.Insert(previewPoco));
                }

                if (raiseEvents)
                    Saved.RaiseEvent(new SaveEventArgs<IContent>(content, false), this);

                Audit.Add(AuditTypes.Save, "Save Content performed by user", userId, content.Id);
            }
        }
开发者ID:kjetilb,项目名称:Umbraco-CMS,代码行数:60,代码来源:ContentService.cs

示例5: UnPublish

        /// <summary>
        /// Unpublishes a single piece of Content
        /// </summary>
        /// <param name="content"><see cref="IContent"/> to unpublish</param>
        /// <param name="userId">Id of the User issueing the unpublish operation</param>
        /// <returns>True if the unpublish operation was successfull and not cancelled, otherwise false</returns>
        public override bool UnPublish(IContent content, int userId)
        {
            if (UnPublishing.IsRaisedEventCancelled(new PublishEventArgs<IContent>(content), this))
                return false;

            //If Content has a release date set to before now, it should be removed so it doesn't interrupt an unpublish
            //Otherwise it would remain released == published
            if (content.ReleaseDate.HasValue && content.ReleaseDate.Value <= DateTime.Now)
            {
                content.ReleaseDate = null;

                LogHelper.Info<PublishingStrategy>(
                    string.Format(
                        "Content '{0}' with Id '{1}' had its release date removed, because it was unpublished.",
                        content.Name, content.Id));
            }
            
            content.ChangePublishedState(PublishedState.Unpublished);

            LogHelper.Info<PublishingStrategy>(
                string.Format("Content '{0}' with Id '{1}' has been unpublished.",
                              content.Name, content.Id));
            return true;
        }
开发者ID:Jeavon,项目名称:Umbraco-CMS,代码行数:30,代码来源:PublishingStrategy.cs


注:本文中的IContent.ChangePublishedState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。