Tuesday, June 1, 2010

Using WECPOF in runtime

You can use WECPOF in design time ECO projects and in Gaffr.net files.

This article explains how to use it in runtime to deliver finished applications.

It starts out as an ordinary ECO project (create one from the wizard, Create new project Eco project).

You then create your model, update the code, configure your Persistence mapper of choice, set up any remote persistence mapper and synchronization if you want to just as the PDF-tutorials explain, Create or evolve your database, or derive the model from an existing database with the Reverse derive options.

Then add a WPF-Window or a WPF-Page (for browser applications).

Make sure your project references WECPOFLogic, then add a reference to the xaml :


And add a MainMenu and a WECPOFWindowEnvironment (this is where the WECPOF windows will be hosted)

   1: <Window x:Class="WpfApplication1.Window1"
   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:         xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"  
   5:     xmlns:wecpof="clr-namespace:WECPOFLogic;assembly=WECPOFLogic"
   6:     Title="Window1" Height="314" Width="354">
   7:     <Window.Resources>
   8:         <LinearGradientBrush x:Key="WECPOFWinBackgroundBrush" EndPoint="0,1" StartPoint="0,0">
   9:             <GradientStop Color="#CCC" Offset="0.0" />
  10:             <GradientStop Color="#EEE" Offset="1.0" />
  11:         </LinearGradientBrush>
  12: ... cut for clarity...
  13:     </Window.Resources>
  14:     <Grid>
  15:         <Grid.RowDefinitions>
  16:             <RowDefinition Height="22"></RowDefinition>
  17:             <RowDefinition></RowDefinition>
  18:         </Grid.RowDefinitions>
  19:         <Menu Grid.Row="0"  Name="MainMenu">
  20:         </Menu>
  21:         <wecpof:WECPOFWindowEnvironment x:Name="WecpofWinEnv">
  23:         </wecpof:WECPOFWindowEnvironment>
  24:     </Grid>
  25: </Window>

In code behind we need to create our ecospace and hook everything up; this is boiler plate code:

   1: public partial class Window1 : Window
   2: {
   3:     EcoSpace _ecospace;
   4:     MenuHandling _MenuHandling;
   5:     public Window1()
   6:     {
   7:         InitializeComponent();
   9:         // Create ecospace or use one that you have
  10:         _ecospace = new EcoProject1.EcoProject1EcoSpace();
  11:         _ecospace.Active = true;
  12:         // Start up the Eco UI dequeuer ; if not set nothing will show
  13:         WPFDequeuer.Active = true;
  14:         // Load viewmodel definitions from embedded resources
  15:         ViewModelDefinitionsInApplication.Init(_ecospace);
  17:         // Create a WECPOF menu handling component
  18:         _MenuHandling = new MenuHandling();
  20:         // Define where WECPOF should look for styles
  21:         WecpofWinEnv.PathToStyles = Directory.GetCurrentDirectory()+"\\Styles";
  22:         // And to where WECPOF should apply a choosen style
  23:         WecpofWinEnv.ResourceDictionaryTargetForStyles(this);
  24:         // Tell the MenuHandling component where to put the MenuItems. Hand over the list of Actions from ECO, hand over the EcoSpace. 
  25:         // Send in the WindowEnvironment defined in xaml, and say in what context should the speed keys be evaluated
  26:         _MenuHandling.InitMainMenu(MainMenu, ViewModelDefinitionsInApplication.GetActionsRuntime(), _ecospace, WecpofWinEnv, this);
  27:         // Let the WECPOF Window environment know about the MenuHandling component
  28:         WecpofWinEnv.InstallMenuHandling(_MenuHandling);
  29:         // Implement the event to implement Quit...
  30:         MenuHandling.OnExit += new EventHandler<EventArgs>(MenuHandling_OnExit);
  31:     }
  33:     void MenuHandling_OnExit(object sender, EventArgs e)
  34:     {
  35:         Close();
  36:     }
  37: }

And you are done:



Anonymous Anonymous said...

When do you expect to share WECPOV with us? Last build of eco 5 was 27May and your newsgrp msg was next one after that date.

Looking forward to trying it.


June 4, 2010 at 8:16 PM  
Blogger Hans Karlsen said...

WECPOF is part of ECO6. Everything we do now goes into ECO6. The latest release of ECO5 was a merge of some important fix from the ECO6 branch.

ECO6 will release soon, but until then you find it at http://dl.capableobjects.com/dl/dailybuilds/

June 5, 2010 at 10:54 AM  
Anonymous Anonymous said...

Installing eco6 5june build on systm with both vs08 having eco4 and eco5 and vs10 will end up in vs08 only and will remove ec05 so Jonas' newsgrp advice to install in virtual machine seems to be still applicable.

And of course the wecpof sample app will not run in vs08. I got error msg that it solution was built with "newer version of this application".

If I install eco6 on new machine with only vs10 will I be limited to the 12 class version?



June 5, 2010 at 8:16 PM  
Blogger Hans Karlsen said...

ECO6 still use the keys from ECO5 so if you intend to upgrade once we release you can start using ECO6 today with your current key.
All you need to do is to rename the %ProgramData%\CapableObjects\ECO5VS.lic file to ECO6VS

But the dailybuilds are still created for VS2008 and we need to manually release VS2010 versions.

June 6, 2010 at 10:07 AM  
Anonymous Anonymous said...

If I install today's manual release of eco6 for vs2010 will it affect my vs2008 setup? ie must I install on non-vs2008 system or use a VM?


June 6, 2010 at 10:46 PM  
Blogger Jonas Hogstrom said...

Installing in a VM is still recommended.

June 7, 2010 at 10:53 AM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home

Contact Us | Terms of Use | Privacy Statement © 2009 CapableObjects