Skip to content

Instantly share code, notes, and snippets.

@JakeGinnivan
Created January 19, 2012 03:22
Show Gist options
  • Save JakeGinnivan/1637534 to your computer and use it in GitHub Desktop.
Save JakeGinnivan/1637534 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Phoenix;
using Phoenix.ActionResults;
using Phoenix.Framework;
using Phoenix.Navigation;
namespace Rtio.Cafe.ModuleContracts
{
public interface IShortcut
{
Task Execute(INavigationFrame targetFrame);
}
public abstract class ControllerActionShortcut<TController> : IShortcut where TController : Controller
{
readonly IPhoenixApplication phoenixApplication;
protected ControllerActionShortcut(IPhoenixApplication phoenixApplication)
{
this.phoenixApplication = phoenixApplication;
}
/// <summary>
/// Gets/Sets the Controller Action which should be invoked when executing this shortcut
/// </summary>
public abstract Expression<Func<TController, ActionResult>> ControllAction { get; }
public Task Execute(INavigationFrame targetFrame)
{
return new InvokeActionBuilder<TController>(new ControllerActionContext(phoenixApplication))
.InvokeAction(targetFrame, ControllAction);
}
}
public abstract class ControllerActionShortcut : IShortcut
{
readonly IPhoenixApplication phoenixApplication;
protected ControllerActionShortcut(IPhoenixApplication phoenixApplication)
{
this.phoenixApplication = phoenixApplication;
}
/// <summary>
/// Gets/Sets the Controller Action which should be invoked when executing this shortcut
/// </summary>
public abstract ControllerAction ControllAction { get; }
/// <summary>
/// Gets/Sets the Entry Point arguments for the application.
/// </summary>
public virtual IEnumerable<object> ControllerActionArguments
{
get { return null; }
}
public Task Execute(INavigationFrame targetFrame)
{
return new InvokeActionBuilder(new ControllerActionContext(phoenixApplication))
.InvokeAction(targetFrame, ControllAction,
(ControllerActionArguments??Enumerable.Empty<object>()).ToArray());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment