• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Workflow.CommandContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中N2.Edit.Workflow.CommandContext的典型用法代码示例。如果您正苦于以下问题:C# CommandContext类的具体用法?C# CommandContext怎么用?C# CommandContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CommandContext类属于N2.Edit.Workflow命名空间,在下文中一共展示了CommandContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetPublishCommand

        /// <summary>Gets the command used to publish an item.</summary>
        /// <param name="context">The command context used to determine which command to return.</param>
        /// <returns>A command that when executed will publish an item.</returns>
		public virtual CompositeCommand GetPublishCommand(CommandContext context)
        {
			var item = context.Content;

            if (!item.IsPage)
                throw new ArgumentException("Publish requires item to be a page");

            if (item is IActiveContent)
				return Compose("Publish active content", Authorize(Permission.Publish), validate, updateObject, moveToPosition, saveActiveContent, updateReferences);
                
            // Editing
			if (!item.VersionOf.HasValue)
			{
                return Compose("Publish 1", Authorize(Permission.Publish), validate, 
                    (item.ID == 0) ? (CommandBase<CommandContext>) null : makeVersion, 
                    updateObject, // UPDATE
                    publishedState, moveToPosition, save, updateReferences);
			}

			// has been published before
			if (item.State == ContentState.Unpublished)
				 return Compose("Re-Publish", Authorize(Permission.Publish), validate, 
                     replaceMaster, useMaster, // REPLACE & USE
                     publishedState, moveToPosition, save, updateReferences);

			// has never been published before (remove old version)
			return Compose("Publish 2", Authorize(Permission.Publish), validate, 
                    updateObject, replaceMaster, delete, useMaster, // TODO check
                    publishedState, moveToPosition, save, updateReferences);
		}
开发者ID:grbbod,项目名称:drconnect-jungo,代码行数:33,代码来源:CommandFactory.cs


示例2: Execute

        /// <summary>Executes the supplied command</summary>
        /// <param name="command">The command to execute.</param>
        /// <param name="context">The context passed to the command</param>
        public virtual void Execute(CommandBase<CommandContext> command, CommandContext context)
        {
            var args = new CommandProcessEventArgs { Command = command, Context = context };
            if (CommandExecuting != null)
                CommandExecuting.Invoke(this, args);

            logger.Info(args.Command.Name + " processing " + args.Context);
            using (var tx = persister.Repository.BeginTransaction())
            {
                try
                {
                    args.Command.Process(args.Context);
                    tx.Commit();

                    if (CommandExecuted != null)
                        CommandExecuted.Invoke(this, args);
                }
                catch (StopExecutionException)
                {
                    tx.Rollback();
                }
                catch (Exception ex)
                {
                    tx.Rollback();
                    logger.Error(ex);
                    throw;
                }
                finally
                {
                    logger.Info(" -> " + args.Context);
                }
            }
        }
开发者ID:markalpine,项目名称:n2cms,代码行数:36,代码来源:CommandDispatcher.cs


示例3: Execute

 /// <summary>Executes the supplied command</summary>
 /// <param name="command">The command to execute.</param>
 /// <param name="context">The context passed to the command</param>
 public virtual void Execute(CommandBase<CommandContext> command, CommandContext context)
 {
     logger.Info(command.Name + " processing " + context);
     using (var tx = persister.Repository.BeginTransaction())
     {
         try
         {
             command.Process(context);
             tx.Commit();
         }
         catch (StopExecutionException)
         {
             tx.Rollback();
         }
         catch (Exception ex)
         {
             tx.Rollback();
             logger.Error(ex);
             throw;
         }
         finally
         {
             logger.Info(" -> " + context);
         }
     }
 }
开发者ID:GrimaceOfDespair,项目名称:n2cms,代码行数:29,代码来源:CommandDispatcher.cs


示例4: GetPublishCommand

        /// <summary>Gets the command used to publish an item.</summary>
        /// <param name="context">The command context used to determine which command to return.</param>
        /// <returns>A command that when executed will publish an item.</returns>
        public virtual CompositeCommand GetPublishCommand(CommandContext context)
        {
            var item = context.Content;

            if (item is IActiveContent)
                return Compose("Publish", Authorize(Permission.Publish), validate, updateObject, moveToPosition, saveActiveContent, updateReferences);
                
            // Editing
            if (!item.VersionOf.HasValue)
            {
                if(item.ID == 0)
                    return Compose("Publish", Authorize(Permission.Publish), validate, updateObject, publishedState, moveToPosition, save, updateReferences);

                return Compose("Publish", Authorize(Permission.Publish), validate, MakeVersionIfPublished(item), updateObject, publishedState, moveToPosition, ensurePublishedDate, save, updateReferences);
            }

            // has been published before
            if (item.State == ContentState.Unpublished)
                return Compose("Re-Publish", Authorize(Permission.Publish), validate, replaceMaster, useMaster, publishedState, moveToPosition, ensurePublishedDate, save, updateReferences);

            // has never been published before (remove old version)
            return Compose("Publish", Authorize(Permission.Publish), validate, updateObject, replaceMaster, delete, useMaster, publishedState, moveToPosition, ensurePublishedDate, save, updateReferences);
            
            throw new NotSupportedException();
        }
开发者ID:JohnsonYuan,项目名称:n2cms,代码行数:28,代码来源:CommandFactory.cs


示例5: CreatesVersion_OfVersionableItem

        public void CreatesVersion_OfVersionableItem()
        {
            var context = new CommandContext(definitions.GetDefinition(item.GetContentType()), item, Interfaces.Editing, CreatePrincipal("admin"), nullBinder, nullValidator);

            dispatcher.Execute(CreateCommand(context), context);

            Assert.That(repository.database.Values.Count(v => v.VersionOf.Value == item), Is.GreaterThan(0), "Expected version to be created");
        }
开发者ID:GrimaceOfDespair,项目名称:n2cms,代码行数:8,代码来源:CommandFactoryTestsBase.cs


示例6: MakesVersion_OfCurrent

        public void MakesVersion_OfCurrent()
        {
            var context = new CommandContext(definitions.GetDefinition(item.GetContentType()), item, Interfaces.Editing, CreatePrincipal("admin"), nullBinder, nullValidator);

            var command = CreateCommand(context);
            dispatcher.Execute(command, context);

            Assert.That(repository.database.Values.Count(v => v.VersionOf == item), Is.EqualTo(1));
        }
开发者ID:ztaff,项目名称:n2cms,代码行数:9,代码来源:CommandFactory_PublishingTests.cs


示例7: DoesntCreateVersion_OfNonVersionableItem

        public void DoesntCreateVersion_OfNonVersionableItem()
        {
            var unversionable = new UnversionableStatefulItem();
            var context = new CommandContext(definitions.GetDefinition(unversionable.GetContentType()), unversionable, Interfaces.Editing, CreatePrincipal("admin"), nullBinder, nullValidator);
            dispatcher.Execute(CreateCommand(context), context);

            dispatcher.Execute(CreateCommand(context), context);
            Assert.That(repository.database.Values.Count(v => v.VersionOf.Value == unversionable), Is.EqualTo(0), "Expected no version to be created");
        }
开发者ID:GrimaceOfDespair,项目名称:n2cms,代码行数:9,代码来源:CommandFactoryTestsBase.cs


示例8: DoesntMakeVersion_OfUnsavedItem

        public void DoesntMakeVersion_OfUnsavedItem()
        {
            var context = new CommandContext(definitions.GetDefinition(typeof(StatefulItem)), new StatefulItem(), Interfaces.Editing, CreatePrincipal("admin"), nullBinder, nullValidator);

            var command = CreateCommand(context);
            dispatcher.Execute(command, context);

            Assert.That(repository.database.Values.Count(v => v.VersionOf.Value == item), Is.EqualTo(0));
        }
开发者ID:GrimaceOfDespair,项目名称:n2cms,代码行数:9,代码来源:CommandFactoryTestsBase.cs


示例9: DoesntMakeVersion_OfUnsavedItem

        public void DoesntMakeVersion_OfUnsavedItem()
        {
            var context = new CommandContext(definitions.GetDefinition(typeof(StatefulPage)), new StatefulPage(), Interfaces.Editing, CreatePrincipal("admin"), nullBinder, nullValidator);

            var command = CreateCommand(context);
            dispatcher.Execute(command, context);

            versions.Repository.Repository.Count().ShouldBe(0);
        }
开发者ID:JohnsonYuan,项目名称:n2cms,代码行数:9,代码来源:CommandFactoryTestsBase.cs


示例10: MakesVersion_OfCurrent

        public void MakesVersion_OfCurrent()
        {
			var context = new CommandContext(definitions.GetDefinition(item.GetContentType()), item, Interfaces.Editing, CreatePrincipal("admin"), nullBinder, nullValidator);

            var command = CreateCommand(context);
            dispatcher.Execute(command, context);

			versions.Repository.Repository.Count().ShouldBe(1);
        }
开发者ID:nagarjunachallapalli,项目名称:n2cms,代码行数:9,代码来源:CommandFactory_PublishingTests.cs


示例11: Clears_PublishedDate

        public void Clears_PublishedDate()
        {
            var item = new StatefulItem();
            var context = new CommandContext(definitions.GetDefinition(item.GetContentType()), item, Interfaces.Editing, CreatePrincipal("admin"), nullBinder, nullValidator);

            var command = CreateCommand(context);
            dispatcher.Execute(command, context);

            Assert.That(item.Published, Is.Null);
        }
开发者ID:Jobu,项目名称:n2cms,代码行数:10,代码来源:CommandFactory_SavingTests.cs


示例12: OnInit

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            ContentItem previewedItem = Selection.SelectedItem;

            var context = new CommandContext(Engine.Definitions.GetDefinition(previewedItem), previewedItem, Interfaces.Viewing, Page.User);
            Engine.Resolve<CommandDispatcher>().Publish(context);

            Response.Redirect(context.Content.Url);
        }
开发者ID:AnonymousRetard,项目名称:n2cms,代码行数:11,代码来源:PublishPreview.aspx.cs


示例13: PreviouslyPublishedVersion_CausesNewVersion_FromView

        public void PreviouslyPublishedVersion_CausesNewVersion_FromView()
        {
            var version = MakeVersion(item);

			var context = new CommandContext(definitions.GetDefinition(version.GetContentType()), version, Interfaces.Viewing, CreatePrincipal("admin"), nullBinder, nullValidator);

            var command = CreateCommand(context);
            dispatcher.Execute(command, context);

            Assert.That(versions.GetVersionsOf(item).Count, Is.EqualTo(3));
        }
开发者ID:nagarjunachallapalli,项目名称:n2cms,代码行数:11,代码来源:CommandFactory_PublishingTests.cs


示例14: Version_MakesVersion_OfCurrentMaster

        public void Version_MakesVersion_OfCurrentMaster()
        {
            var version = MakeVersion(item);
            var context = new CommandContext(version, Interfaces.Editing, CreatePrincipal("admin"), nullBinder, nullValidator);

            var command = CreateCommand(context);
            dispatcher.Execute(command, context);

            Assert.That(repository.database.Values.Count(v => v.VersionOf == item), Is.EqualTo(1));
            Assert.That(item.Title, Is.EqualTo("version"));
        }
开发者ID:spmason,项目名称:n2cms,代码行数:11,代码来源:CommandFactory_PublishingTests.cs


示例15: CanMoveItem_ToBefore_Item

        public void CanMoveItem_ToBefore_Item()
        {
            var child2 = CreateOneItem<StatefulItem>(0, "child2", item);
            var context = new CommandContext(definitions.GetDefinition(child2.GetContentType()), child2, Interfaces.Editing, CreatePrincipal("admin"), nullBinder, nullValidator);
            context.Parameters["MoveBefore"] = child.Path;
            var command = CreateCommand(context);
            dispatcher.Execute(command, context);

            Assert.That(item.Children.Count, Is.EqualTo(2));
            Assert.That(item.Children[0], Is.EqualTo(child2));
            Assert.That(item.Children[1], Is.EqualTo(child));
        }
开发者ID:ztaff,项目名称:n2cms,代码行数:12,代码来源:CommandFactory_PublishingTests.cs


示例16: Version_Replaces_MasterVersion

        public void Version_Replaces_MasterVersion()
        {
            var version = MakeVersion(item);
            version.Name = "tha masta";
			var context = new CommandContext(definitions.GetDefinition(version.GetContentType()), version, Interfaces.Editing, CreatePrincipal("admin"), nullBinder, nullValidator);

            var command = CreateCommand(context);
            dispatcher.Execute(command, context);

            Assert.That(context.Content.Name, Is.EqualTo("tha masta"));
            Assert.That(context.Content.VersionOf.HasValue, Is.False);
        }
开发者ID:nagarjunachallapalli,项目名称:n2cms,代码行数:12,代码来源:CommandFactory_PublishingTests.cs


示例17: OnInit

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            ContentItem previewedItem = Selection.SelectedItem;

            var context = new CommandContext(Engine.Definitions.GetDefinition(previewedItem.GetContentType()), previewedItem, Interfaces.Viewing, Page.User);
            var command = Engine.Resolve<ICommandFactory>().GetPublishCommand(context);
            Engine.Resolve<CommandDispatcher>().Execute(command, context);

            Response.Redirect(context.Content.Url);
        }
开发者ID:ztaff,项目名称:n2cms,代码行数:12,代码来源:PublishPreview.aspx.cs


示例18: IsCheckedForSecurity

        public void IsCheckedForSecurity(string userInterface, bool useVersion)
        {
            DynamicPermissionMap.SetRoles(item, Permission.Read, "None");
            if (useVersion)
                item = MakeVersion(item);
            var context = new CommandContext(definitions.GetDefinition(item.GetContentType()), item, userInterface, CreatePrincipal("someone"), new NullBinder<CommandContext>(), new NullValidator<CommandContext>());

            var command = CreateCommand(context);
            dispatcher.Execute(command, context);

            Assert.That(context.ValidationErrors.Count, Is.EqualTo(1));
            Assert.That(context.ValidationErrors.First().Name, Is.EqualTo("Unauthorized"));
        }
开发者ID:JohnsonYuan,项目名称:n2cms,代码行数:13,代码来源:CommandFactoryTestsBase.cs


示例19: GetPublishCommand

        /// <summary>Gets the command used to publish an item.</summary>
        /// <param name="context">The command context used to determine which command to return.</param>
        /// <returns>A command that when executed will publish an item.</returns>
        public virtual CompositeCommand GetPublishCommand(CommandContext context)
        {
            if (context.Interface == Interfaces.Editing)
            {
                if (context.Content is IActiveContent)
                    return Compose("Publish", Authorize(Permission.Publish), validate, updateObject, moveToPosition, saveActiveContent);

                // Editing
                if (!context.Content.VersionOf.HasValue)
                {
                    if(context.Content.ID == 0)
                        return Compose("Publish", Authorize(Permission.Publish), validate, updateObject, incrementVersionIndex, publishedState, moveToPosition/*, publishedDate*/, save);

                    if (context.Content.State == ContentState.Draft && context.Content.Published.HasValue == false)
                        return Compose("Publish", Authorize(Permission.Publish), validate, makeVersion, updateObject, incrementVersionIndex, publishedState, moveToPosition, publishedDate, save);

                    return Compose("Publish", Authorize(Permission.Publish), validate, makeVersion, updateObject, incrementVersionIndex, publishedState, moveToPosition/*, publishedDate*/, save);
                }

                // has been published before
                if (context.Content.State == ContentState.Unpublished)
                    return Compose("Publish", Authorize(Permission.Publish), validate, updateObject,/* makeVersionOfMaster,*/ replaceMaster, useMaster, incrementVersionIndex, publishedState, moveToPosition/*, publishedDate*/, save);

                // has never been published before (remove old version)
                return Compose("Publish", Authorize(Permission.Publish), validate, updateObject,/* makeVersionOfMaster,*/ replaceMaster, delete, useMaster, publishedState, moveToPosition/*, publishedDate*/, save);
            }
            else if (context.Interface == Interfaces.Viewing)
            {
                // Viewing
                if (!context.Content.VersionOf.HasValue)
                {
                    if (context.Content.ID == 0)
                        return Compose("Publish", Authorize(Permission.Publish), validate, updateObject, incrementVersionIndex, publishedState, moveToPosition/*, publishedDate*/, save);

                    if (context.Content.State == ContentState.Draft && context.Content.Published.HasValue == false)
                        return Compose("Publish", Authorize(Permission.Publish), validate, makeVersion, updateObject, incrementVersionIndex, publishedState, moveToPosition, publishedDate, save);

                    return Compose("Publish", Authorize(Permission.Publish), validate, makeVersion, updateObject, incrementVersionIndex, publishedState, moveToPosition/*, publishedDate*/, save);
                }

                if (context.Content.State == ContentState.Unpublished)
                    return Compose("Re-Publish", Authorize(Permission.Publish),/* makeVersionOfMaster,*/ replaceMaster, useMaster, incrementVersionIndex, publishedState, moveToPosition/*, publishedDate*/, save);

                if (context.Content.State == ContentState.Draft)
                    return Compose("Re-Publish", Authorize(Permission.Publish),/* makeVersionOfMaster,*/ replaceMaster, useMaster, incrementVersionIndex, publishedState, moveToPosition, publishedDate, save);

                return Compose("Publish", Authorize(Permission.Publish),/* makeVersionOfMaster,*/ replaceMaster, delete, useMaster, publishedState, moveToPosition/*, publishedDate*/, save);
            }

            throw new NotSupportedException();
        }
开发者ID:GrimaceOfDespair,项目名称:n2cms,代码行数:54,代码来源:CommandFactory.cs


示例20: Version_MakesVersion_OfCurrentMaster

        public void Version_MakesVersion_OfCurrentMaster()
        {
            var version = MakeVersion(item);
			version.State = ContentState.Draft;
			version.Title = "version";

			var context = new CommandContext(definitions.GetDefinition(version.GetContentType()), version, Interfaces.Editing, CreatePrincipal("admin"), nullBinder, nullValidator);

            var command = CreateCommand(context);
            dispatcher.Execute(command, context);

			versions.Repository.GetVersions(item).Count().ShouldBe(1);
            Assert.That(item.Title, Is.EqualTo("version"));
        }
开发者ID:nagarjunachallapalli,项目名称:n2cms,代码行数:14,代码来源:CommandFactory_PublishingTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Search.LuceneSearcher类代码示例发布时间:2022-05-26
下一篇:
C# Installation.DatabaseStatus类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap