Umbraco Action Handler

by matt.perry 9/3/2008 12:21:00 PM

I had quite a common requirement with a current Umbraco project I'm working on.  Each page can have an infinite number of banner ads on the right hand column of the screen.   Easiest way is to create a new document type for each banner item and allow them to be added as sub pages of the main text page.   In this particular web site each text page can have its own sub text pages so you end up with a nice tree structure of homepage, child pages and grand-child pages.

If each of these pages can have banner items the visual representation of the tree in the Umbraco manager pages becomes very difficult to understand.

image

What I needed was a container folder in the tree to place all the banner ads so they don't get mixed up with the text pages.

 image

When expanded you can see the banner items

image

This necessitated creating the banner 'container' sub-folder automatically each time a new text page was created.

 

The simplest way to achieve this is to use Umbraco Action Handlers

 

All the code is shown below but the main part of the Action Handler which is simply a Class Library dumped in the bin folder of the Umbraco site.


We are only interested in trapping the event fired when a page is create(d) otherwise leave the function.

// Only work with create event           

if (action.Alias != "create") return true;

Similarly we are only interested in the Text Page document type         

  // Only work with Text Page docuemnt types
            if (documentObject.ContentType.Alias != "Text Page") return true;

 

Create a new document of type banner container and base the location of the current documentID.

 

            Document bannerItem = null;

            bannerItem = Document.MakeNew("Banners", DocumentType.GetByAlias("Banner Container"), documentObject.User, documentObject.Id);

I didn't want this container folder showing up in the navigation or any sitemap so I had to set some properties and then save the object.

            bannerItem.getProperty("umbracoNaviHide").Value = "1";
            bannerItem.getProperty("siteMapHide").Value = "1";
            bannerItem.Save();

 

That's it.....simple but very useful for creating a specific structure of sub-page when creating a new content node.

 

Full Code:

 

using System;
using System.Collections.Generic;
using System.Text;

using umbraco.BusinessLogic.Actions;
using umbraco.BusinessLogic.console;
using umbraco.cms.businesslogic.web;

namespace UmbracoWebsite

{
    public class BannerHandler : IActionHandler
    {
        #region IActionHandler Members

        public bool Execute(Document documentObject, umbraco.interfaces.IAction action)
        {
            // Only work with create event
            if (action.Alias != "create") return true;

            // Only work with Text Page docuemnt types
            if (documentObject.ContentType.Alias != "Text Page") return true;

            Document bannerItem = null;

            bannerItem = Document.MakeNew("Banners", DocumentType.GetByAlias("Banner Container"), documentObject.User, documentObject.Id);
            bannerItem.getProperty("umbracoNaviHide").Value = "1";
            bannerItem.getProperty("siteMapHide").Value = "1";
            bannerItem.Save();

            return true;

        }

        public string HandlerName()
        {
            return "BannerHandler";
        }

        public umbraco.interfaces.IAction[] ReturnActions()
        {
            return new umbraco.interfaces.IAction[] { new umbraco.BusinessLogic.Actions.ActionNew() };
        }

        #endregion

    }
}

CSLA - SQL Reporting Services

by matt.perry 1/4/2008 3:32:00 PM

Quick tip on how to use CSLA objects on a SQL 2005 Reporting Services instance.

http://forums.lhotka.net/forums/post/13747.aspx 

Visual Studio 2008 RTM - Available on MSDN now.

by matt.perry 11/20/2007 8:57:00 AM


The long awaited Visual Studio 2008 was finally released to manufacturing yesterday 19th November.

Highlights of the environmnet built upon .NET 3.5, also relased yesterday include.

  • Multi-targeting of .NET2.0, .NET3.0 and .NET3.5 all from the same IDE
  • Built in AJAX support - no seperate download
  • Extensive changes to the web design component which is based on the expression web designer engine.
  • Extensive support for CSS developement
  • Language improvements
  • LINQ - Language Integrated Query - Built-in Object Relation Mapper (OR/M)  - Working with data now as easy as working with a class
  • Data access improvements

This really is an exciting update to the already formidable developer toolset.

 

Umbraco

by matt.perry 10/25/2007 11:18:00 PM

It's taken me a while to really take a look at this open source .NET CMS system built in c# but now I have I won't look back.

For years I've built many different CMS solutions for clients where I would target each individual site with specific additions to a basic CMS.  This became both tedious and dangerous.  Why dangerous?  Well apart from being very difficult to manage it ultimately leads to an unhappy client and potential lawsuits!  I never quite got that far but it made the projects focus the CMS and not the actual website.

Thanks to Peter Labrow at Labrow Marketing for pointing me in the direction of this great piece of software.  It's based on open standards, fully compliant and easy to extend.  Just got to brush up on the XSLT which is used to build the templates.

www.umbraco.org

.NET Source Code released

by matt.perry 10/12/2007 2:00:00 PM

Scott Gutherie the Program Manager for many .NET technologies at Microsoft including IIS and Visual Studio announces the release of the .NET framework source code.

Whilst it's not quite open source it certainly helps to see how production quality code is written.  It's .NET v3.5 and VS2008 only but it's certainly a start.

Check it out. http://weblogs.asp.net/scottgu/archive/2007/10/03/releasing-the-source-code-for-the-net-framework-libraries.aspx 

CSLA.NET V3.5

by matt.perry 10/11/2007 9:33:00 PM

For any of you unfamiliar with CSLA.NET I suggest you take a look straight away. CSLA.NET is a framework for building enterprise class OO .NET applications and is born out of a 10 year long almost evangelical philosophy by its author Rockofrd Lhotka.

Rocky started his series of books on distributed object orientated applications during the very early VB5 days.  With the arrival of .NET both C# and VB Rocky’s ideals were finally matched by the technologies.  I can assure you that COM and distributed computing was not as easy as Microsoft would have had us believe.

Iterating through the .NET versions 1.0, 2.0, 3.0 & soon to be v3.5 CSLA.NET has always mirrored the .NET roadmap and has been at the forefront of best practice.

Your objects inherit from CSLA.NET base objects and assume a whole host of additiona lfunctionality not provided by .NET itself. 

Top Features

n-level undo
Full support for object databinding in Windows Forms and ASP.NET
Strongly typed paretn child relationships
Field level centralised authorisation
Business rule management.
Database/storage layer abstraction
Web service integration

I’ve met Rocky a few times in Vegas and Orlando conferences although he wouldn’t know me from Adam and not only is his framework top notch he is one of the world’s top speakers at all .NET conferences.

CSLA.NET is described in detail in a number of books VB & C# and later versions of the books are available as PDF eBooks. 

Short of a simple and fair licence whose only major caveat is that you can’t replicate the framework (or a derivative of) to sell as an application framework it is actually free to use.  It provides create structure to your development and helps to abstract and layer a project to obtain great re-use.  Using OO principals it’s also great for hiding and masking the many Microsoft data access technologies over the years.  DAO, ADO, ADO.NET & LINQ anybody??????

As part of my reference application, see later posts, I intend developing using CSLA.NET in C# for the foreseeable future.

Cheers Rocky!!!   

Tags:

VB.NET | C# | CSLA.NET

C#

by matt.perry 10/10/2007 2:26:00 PM

I've been an ASP & VB developer for some 10 years if not longer but never got in to C#.

After recently deciding to move on from Picture Nation I started to look at the contracting market in and around Manchester, UK.  I was amazed at the number of jobs recruiting C# over and above VB.NET.  C# really does seem now to be pushing forward as the defacto .NET language and therefore I have decided to bite the bullet and develop solutions in C# as my primary language.

It's a great time to be a .NET developer, especially C#, as the skills are so in demand.  With v3.5 (Linq et al) around the corner, fingers crossed November 2007, I think it's a perfect time for me to move over.

I'm going to document my transition if not just to help me but also others who come unstuck by the little nuisances of the language.

Wish me luck.

Matt

Tags: ,

C# | Linq

Powered by BlogEngine.NET 1.2.0.0
Theme by Mads Kristensen

About the author

Matt Perry Software architect, CMS specialist and football fanatic. Need to find a way to join them all together!

E-mail me Send mail

Calendar

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Pages

Recent comments

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2010

    Sign in