|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using CobaltSoftware.Foundation.ModelViewPresenter;
using System.ComponentModel;
namespace CobaltSoftware.Foundation.Web.Patterns.ModelViewPresenter
{
/// <summary>
/// The OrchestratorImplementation class is a dynamic substitute for the Orchestrator
/// that is strong-typed with the presenter and view contract types.
/// </summary>
/// <remarks>
/// <para>
/// <list>
/// <listheader>Version History</listheader>
/// <item>11 October, 2009 - Steve Gray - Initial Draft</item>
/// </list>
/// </para>
/// </remarks>
/// <typeparam name="TPresenterContract">Presenter contract interface</typeparam>
/// <typeparam name="TViewContract">View contract interface</typeparam>
[ParseChildren(true)]
[PersistChildren(true)]
public class OrchestratorImplementation<TPresenterContract, TViewContract> : Orchestrator
where TPresenterContract : IPresenter<TPresenterContract, TViewContract>
where TViewContract : IView<TViewContract, TPresenterContract>
{
#region ASP .NET Page Lifecycle
/// <summary>
/// When the orchestrator initializes.
/// </summary>
/// <param name="e">Event Arguments</param>
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
PerformWireup();
}
#endregion
#region Methods
/// <summary>
/// Perform the various MVP wireup tasks.
/// </summary>
protected void PerformWireup()
{
try
{
this.TraceInformation("PerformWireup::Starting");
// Validate state
if (Presenter == null || Presenter.Count == 0)
throw new ArgumentNullException("Presenter", "There are no presenters in the Presenter collection.");
if (Presenter.Count > 1)
throw new ArgumentException("Too many presenters specified. Can only set a single presenter.", "Presenter");
if (Views == null || Views.Count == 0)
throw new ArgumentNullException("Views", "No views specified - cannot perform wireup.");
// Create the presenter
TPresenterContract presenter = Presenter.First().GetPresenterInstance<TPresenterContract, TViewContract>(this);
// Wireup each view.
foreach (IViewLoader viewLoader in Views)
{
viewLoader.Connect<TViewContract, TPresenterContract>(this, presenter);
}
}
catch (Exception ex)
{
this.TraceWarning("PerformWireup::Failed due to exception:" + ex.ToString());
throw;
}
finally
{
this.TraceInformation("PerformWireup::Finished");
}
}
#endregion
#region Properties
/// <summary>
/// Presenter source.
/// </summary>
[PersistenceMode(PersistenceMode.InnerProperty)]
public List<IPresenterLoader> Presenter { get; set; }
/// <summary>
/// Views collection
/// </summary>
[PersistenceMode(PersistenceMode.InnerProperty)]
[MergableProperty(false)]
public List<IViewLoader> Views { get; set; }
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Steve Gray is a Senior Developer at a British insurance company, working on a popular aggregator. When he's not writing ASP .NET, it's because there's SQL or WCF to write instead.