Welcome to MSDN Blogs Sign in | Join | Help
How to extend the Data Warehouse to include a custom Commerce Server event (Part 1)

Here I am going to show you how to write your own custom Commerce Server event and utilize it in the Data Warehouse for reporting purposes.  In this case, we are going to create a fictitious MusicDownload event, which, if you have a music Commerce Server site, can record an event on every music download.  This event will keep track of the Artist, Album, and Title.  This will be a two part series where the first part focuses on the custom event and part 2 focuses on extending the Data Warehouse. 

  • Let's create a new DLL C# project.  We need to Add a Reference to the Microsoft.CommerceServer.Runtime dll.  You can find this dll in the C:\Program Files\Microsoft Commerce Server 2007\Assemblies\ directory.
  • So now we create the Class MusicDownloadEvent.  To have a Commerce Server event, we need to extend the BaseCommerceEvent, thus overriding the Validate Method.  Here is the entire class with comments below:

        1 using System;

        2 using System.Collections.Generic;

        3 using System.Text;

        4 using Microsoft.CommerceServer.Runtime;

        5 

        6 namespace CompanyName.Project.MusicDownloads

        7 {

        8     [CommerceEvent("MusicDownload")]

        9     public class MusicDownloadEvent : BaseCommerceEvent

       10     {

       11         #region Members

       12         string _title;

       13         string _artist;

       14         string _album;     

       15         #endregion

       16 

       17         /// <summary>

       18         /// Default Constructor

       19         /// </summary>

       20         public MusicDownloadEvent()

       21             : base()

       22         {

       23 

       24         }

       25 

       26         public MusicDownloadEvent(string title, string artist, string album)

       27         {

       28             _title = title;

       29             _artist = artist;

       30             _album = album;

       31 

       32         }

       33 

       34         [CommerceEventMember("Artist")]

       35         public string Artist

       36         {

       37             get { return _artist; }

       38             set { _artist = value; }

       39         }

       40 

       41         [CommerceEventMember("Album")]

       42         public string Album

       43         {

       44             get { return _album; }

       45             set { _album = value; }

       46         }

       47 

       48         [CommerceEventMember("Title")]

       49         public string Title

       50         {

       51             get { return _title; }

       52             set { _title = value; }

       53         }

       54 

       55         /// <summary>

       56         /// Validates that this is a valid Event

       57         /// </summary>

       58         /// <returns></returns>

       59         public override bool Validate()

       60         {

       61             if (string.IsNullOrEmpty(_title) ||

       62                 string.IsNullOrEmpty(_artist) ||

       63                 string.IsNullOrEmpty(_album))

       64             {

       65                 return false;

       66             }

       67             return base.Validate();

       68         }

       69     }

       70 }

  • You notice that we had to apply attributes to the class indicating that this is a Commerce Event with the name "MusicDownload".  This is required. 

        8  [CommerceEvent("MusicDownload")]

        9     public class MusicDownloadEvent : BaseCommerceEvent

  • You also notice that each property that we want to include in the event must have the attribute CommerceEventMember, with the event name as a parameter, as illustrated below:

       34  [CommerceEventMember("Artist")]

       35         public string Artist

       36         {

       37             get { return _artist; }

       38             set { _artist = value; }

       39         }

  • Once you compile and sign this dll, you need to add the DLL as a reference in the site's Visual Studio project. 

  • Next, you need to add the entry for the event in your web.config file.  It's important to note that the assembly name must be fully qualified.  Here is what our MusicDownloadEvent looks like in the web.config file:

 <add className="CompanyName.Project.MusicDownloads.MusicDownloadEvent, CompanyName.Project.MusicDownloads, Version=1.0.0.0, Culture=neutral" id="MusicDownload" loggingEnabled="true"/>

  • Now, let's create a very simplistic Aspx page that uses this event, here it is below:

        1 using System;

        2 using System.Data;

        3 using System.Configuration;

        4 using System.Collections;

        5 using System.Web;

        6 using System.Web.Security;

        7 using System.Web.UI;

        8 using System.Web.UI.WebControls;

        9 using System.Web.UI.WebControls.WebParts;

       10 using System.Web.UI.HtmlControls;

       11 using CompanyName.Project.MusicDownloads;

       12 using Microsoft.CommerceServer.Runtime;

       13 

       14 

       15 public partial class MusicDownload : System.Web.UI.Page

       16 {

       17     protected void Page_Load(object sender, EventArgs e)

       18     {

       19         MusicDownloadEvent evt = new MusicDownloadEvent("Back in black", "AC/DC", "Unknown");

       20         CommerceContext.LogCommerceEvent(evt);

       21 

       22     }

       23 }

  • Next Step is to Extend the Data Warehouse to include this event.  This will be covered in Part 2, where I hope to have some utilities that will make it easy for you to extend!

 

Hope this helps!

 

-Alan

Posted: Friday, September 08, 2006 3:33 PM by akfaulkner

Comments

Alan Faulkner's Connected Commerce Blog said:

This is the second part of a three part series in extending the Data Warehouse. To recap the first part,

# October 30, 2006 7:25 PM

Prescription drug: Zyloprim said:

Zyloprim Uses, How Taken, Warnings/Precautions, Missed Dose, Possible Side Effects, Storage, Overdose, More Information, where to buy online.

# May 28, 2007 5:44 PM

Max Akbar said:

How about everything :)! Integrating a Custom Snap-in Extension Developing with Resources Using Pup to

# August 27, 2007 7:15 AM

kostenloses online kasinos said:

Su  <a href=http://groups.google.de/group/kristin286/web/online-spielkasino>online spielkasino</a> Doppeltes Wert gekommen vigorish roulette <a href=http://groups.google.de/group/kristin286/web/online-spielbank>online spielbank</a> Progressist Wette Dollar Lotterie <a href=http://groups.google.de/group/kristin286/web/spiel-automaten>spiel automaten</a> Butterfaß Handgriff Überprüfung longshot!

# November 19, 2007 8:30 AM

hlam 1 said:

Hello, people <a href="http://hlam-1.info/284.html ">6as7</a> <a href="http://hlam-1.info/873.html ">acanac</a> <a href="http://hlam-1.info/834.html ">abu garcia ambassadeur 7000c3i</a> <a href="http://hlam-1.info/139.html ">4l80e</a> [URL=http://hlam-1.info/808.html]abrasion arthroplasty[/URL] [URL=http://hlam-1.info/387.html]848 ardis st[/URL] likes

# December 25, 2007 4:33 PM

samsung said:

Nice world <a href="http://bestname9.info/696.html ">samsung hln5065w</a> <a href="http://bestname9.info/789.html ">samsung microwaves</a> <a href="http://bestname9.info/994.html ">samsung sph a460 cell phone</a> <a href="http://bestname9.info/67.html ">930b monitor review samsung syncmaster</a> [URL=http://bestname9.info/454.html]samsung a670 unlock code[/URL] [URL=http://bestname9.info/355.html]samsung 56 inch dlp[/URL] new

# January 20, 2008 6:57 PM

advance cash loan overnight said:

In the first case best loan payday advance loan paycheck payday

# January 26, 2008 9:08 AM

first american cash advance said:

Before advance cash day loan pay payday business internet loan payday start

# January 26, 2008 9:13 AM

dating1 said:

Funny sites <a href="http://my-tava-d.info/784.html ">who is jeff probst dating</a> <a href="http://my-tava-d.info/449.html ">speed dating in tulsa ok</a> <a href="http://my-tava-d.info/14.html ">halifax singles speed dating</a> <a href="http://my-tava-d.info/307.html ">dating memphis escort service</a> [URL=http://my-tava-d.info/250.html]milwaukee speed dating[/URL] [URL=http://my-tava-d.info/617.html]adult dating services koloa hawaii[/URL] do it

# February 6, 2008 5:12 PM

ctl00$_$ctl00$_$ctl02$_$form$_$tbname said:

do meridia <a href= http://meridia.zblog.ru >meridia results</a> [url=http://meridia.zblog.ru]meridia results[/url]

# February 16, 2008 3:03 PM

real estate c blog said:

Welcome to <a href="http://real-estate-cblog.info/636.html ">pasco county real estate</a> <a href="http://real-estate-cblog.info/1.html ">leederville real estate</a> <a href="http://real-estate-cblog.info/386.html ">mullaloo real estate premises</a> <a href="http://real-estate-cblog.info/691.html ">peterborough nh real estate</a> [URL=http://real-estate-cblog.info/622.html]panacea florida real estate[/URL] [URL=http://real-estate-cblog.info/177.html]maricopa real estate records[/URL] more

# March 5, 2008 6:51 PM

degree hnew said:

Hello, people <a href="http://uaduh.info/college_scholarships_for_homeschoolers.html ">college scholarships for homeschoolers</a> <a href="http://uaduh.info/colleges_in_jackson_tennesee.html ">colleges in jackson tennesee</a> <a href="http://uaduh.info/college_valedictory_speeches.html ">college valedictory speeches</a> <a href="http://uaduh.info/collegen_magazine.html ">collegen magazine</a> [URL=http://uaduh.info/college_streakers.html]college streakers[/URL] [URL=http://uaduh.info/college_university_boat_yacht_design.html]college university boat yacht design[/URL] more

# May 20, 2008 2:41 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker