本文整理汇总了C#中N2.Edit.Workflow.CommandContext类的典型用法代码示例。如果您正苦于以下问题:C# CommandContext类的具体用法?C# CommandContext怎么用?C# CommandContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandContext类属于N2.Edit.Workflow命名空间,在下文中一共展示了CommandContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
}
}
示例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);
}
}
}
示例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();
}
示例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");
}
示例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));
}
示例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");
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}
示例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"));
}
示例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));
}