This HOWTO will guide you throught the differents steps to create your first project based on the Claymore MVP Pattern.

1 - Create the views interfaces project

  • Create a new C# Class Library project

Create_IViews_Project.png
  • Add a new Claymore IView Item in the project

Create_IClockView_2.png

and complete the code like this

using System;
using Claymore;

namespace Clock.IViews
{
    public delegate string GetTimeEventHandler(object sender, EventArgs e);

    /// <summary>
    /// Add needed operation here.
    /// </summary>
    public interface IClockView : IView
    {
        event GetTimeEventHandler GetTime;
    }
}

2 - Create the Winform views implementation project

  • Create a new C# Class Library project

Create_Views_Project.png
  • Add a new Windows form and design it to match the following example

Clock_GUI.png
  • complete the code like this

using System;
using System.Windows.Forms;
using Clock.IViews;

namespace Clock.Views
{
    public partial class ClockView : Form, IClockView
    {
        public event GetTimeEventHandler GetTime;
        
        public ClockView()
        {
            InitializeComponent();
        }

        private void btnGetTimeClicked(object sender, EventArgs e)
        {
            if (GetTime != null)
            {
                string time = GetTime(this, EventArgs.Empty);
                TxtTime.Text = time;
            }
        } 
    }
}

Note : You will have to add a reference to the Claymore assembly, and to the Clock.IViews project we've previously created.

3 - Create the presenters project

  • Create a new C# Class Library project

Create_Presenters_Project.png
  • Add a new Claymore Presenter Item in the project

Create_ClockPresenter_2.png

and complete the code like this

using System;
using Claymore;
using Clock.IViews;

namespace Clock.Presenters
{
    public class ClockPresenter : PresenterBase<IClockView>
    {

        public ClockPresenter(IClockView view) : base(view)
        {
            view.GetTime += onGetTime;
        }

        private static string onGetTime(object sender, EventArgs e)
        {
            return DateTime.Now.ToString();
        }
    }
}

Note : You will have to add a reference to the Claymore assembly, and to the Clock.IViews project we've previously created.

4 - Create the hosting project

  • Create a new C# Windows form application project

Create_ClockHoster_Project.png
  • Add an Application Configuration File to the project

App_Config.png
  • Configure it like this

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  
  <configSections>
    <section name="Claymore" type="Claymore.Configuration.ConfigSectionHandler, Claymore, Version=1.0.2.0, Culture=neutral, PublicKeyToken=0c92c1fcefb3e8b3"/>
  </configSections>

  <Claymore>
    <ViewsAssemblies>
      <Add assemblyName="Clock.Views"/>
    </ViewsAssemblies>
    <PresentersAssemblies>
      <Add assemblyName="Clock.Presenters"/>
    </PresentersAssemblies>
  </Claymore>
  
</configuration>
  • Now add the following code in the program.cs file

using System;
using System.Windows.Forms;
using Clock.IViews;

namespace Clock
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Claymore.Claymore.Initialize("Claymore");

            IClockView clockView;
            if ((clockView = Claymore.Claymore.ViewManager.CreateView<IClockView>()) == null)
                return;

            Form clockForm;
            if ((clockForm = clockView as Form) == null)
                return;

            if (Claymore.Claymore.PresenterManager.CreatePresenterFor<IClockView>(clockView) == null)
                return;

            Application.Run(clockForm);
        }
    }
}


Note : You will have to add a reference to the Claymore assembly, and to the Clock.IViews project we've previously created.
Note : At runtime Claymore will dynamically invoke the Views and Presenters implementation; So that Clock.Presenters.dll and Clock.Views.dll must be placed in the output directory (bin/debug or bin ) of the project.

5 - Launch it :)

Clock.png

Last edited Feb 17, 2010 at 8:48 PM by Fab_Michellonet, version 18

Comments

No comments yet.