Project Server 2010 : Server Event Handlers (Part 1)






Server Event handlers are the expansion points for Project Server 2010, to register a custom event handlers with project server's events, Project Server raises pre-events and post-events when Project Server Interface (PSI) methods change business objects such as Project, Task, Resource, or Timesheet. When you associate an event handler with an event, Project Server runs the event handler when that particular event occurs.

To start with event handlers development, you need to create new Class Library Project, from File > New > Project and select Class Library template (Figure 1)


Figure 1

Delete the default class file class1.cs and right click on the project Add > New Item select class and rename it to ProjectEventHandler.cs, that will create new class file with a class called ProjectEventHandler. Add public access modifier to make this class accessible.

Add these Project Server 2010 reference, right click on the project > Add Reference on the browse tab choose these files:
  • c:\Program Files\Microsoft Office Servers\14.0\bin\Microsoft.Office.Project.Server.Events.Receivers.dll
  • c:\Program Files\Microsoft Office Servers\14.0\bin\Microsoft.Office.Project.Server.Library.dll
  • c:\windows\assembly\GAC_MSIL\Microsoft.Office.Project.Schema\14.0.0.0__71e9bce111e9429c

And add the following reference code
using Microsoft.Office.Project.Server.Events;
using PSLib = Microsoft.Office.Project.Server.Library;
using Microsoft.Office.Project.Server.Schema;
Tip: If the event arguments do not include one of the PSI datasets, the Microsoft.Office.Project.Server.Schema namespace is not needed.

Make ProjectEventHandler class inherits from ProjectEventReceiver class to override the events handler's functions (this class is located in the added references added).

Add function that overrides the Pre-Event OnCreating function, this function will be called when a project is in the creation process (before it is created).

Your C# code will look like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Office.Project.Server.Events;
using PSLib = Microsoft.Office.Project.Server.Library;
using Microsoft.Office.Project.Server.Schema;


namespace ServerEventHandlers
{
    public class ProjectEventHandler : ProjectEventReceiver
    {
        public override void OnCreating(PSLib.PSContextInfo contextInfo, ProjectPreEventArgs e)
        {
            //write business logic here
        }
    }
}

The coding part is over (after adding your business logic code), lets sign and install it into the GAC, to do so follow these steps:
  • right click on the project > Properties from the application tab change the Target framework to .Net framework 3.5 because Project Server 2010 is built on Microsoft .Net framework 3.5
  • Click on Signing tab
  • Check the Sign the assembly check box
  • in Choose a strong name key file: drop down list select a key or create a new one, a .pfx file is added to the project, this key will used to sign the dll to be used in GAC
  • Build the solution and make sure that it is built successfully
  • Locate the dll in the bin folder for that project
  • Register the dll in the GAC, open cmd and type "assebly", it will open the assembly folder (c:\windows\assembly), drag and drop the dll to the folder, find your dll's name in the assembly folder (Figure 2)

Figure 2



The dll now is registered in the GAC and ready to be used in Project Server 2010, in my next post (Part 2) I will describe how to register this event handler association in Project Server Application.
For More details and methods follow the steps in MSDN.

Comments

  1. Hi,

    you repeat the reference Microsoft.Office.Project.Server.Events.Receivers.dll and need add the reference to Microsoft.Office.Project.Server.Library.dll

    ReplyDelete
  2. thank you Anonymous, it is fixed and updated :)

    ReplyDelete

Post a Comment

Popular posts from this blog

Project Server 2010 : Server Event Handlers (Part 2)

Retrieving Sharepoint Lists' Information In Project Sites - Project Server 2010