The event arguments parameter in both pre- and post-event handlers can
include a DataSet for the entity, if the related PSI method uses a DataSet.
For example, the event arguments parameter for the CustomField OnCreated
event handler includes CustomFieldInformation of type CustomFieldDataSet.
To use a DataSet in an event handler, you must set a reference to the
Microsoft.Office.Project.Schema.dll assembly. The
Microsoft.Office.Project.Server.Schema namespace includes the necessary
class definitions such as CustomFieldDataSet.
You can copy the schema assembly from
C:\WINDOWS\assembly\GAC_MSIL\Microsoft.Office.Project.Schema\12.0.0.0__71e9bce111e9429c
if you first run the following command:
regsvr32 /u C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\shfusion.dll
--then re-register shfusion.dll when you're done.
Datasets in event handlers are for read-only use. For example, you cannot
modify the CustomFieldDataSet to change the name of a custom field within
the OnCreating pre-event handler. However, you can trap the event, get the
properties you need, cancel creation of the custom field, and then use the
CreateCustomFields method in the CustomFields Web service to create a new
custom field with the correct name.
Here's some code (modified from the SDK example) that uses a
CustomFieldDataSet in a post-event handler.
using System;
using System.Diagnostics;
using System.Data;
using System.Xml;
using Microsoft.Office.Project.Server.Events;
using PSLibrary = Microsoft.Office.Project.Server.Library;
namespace TestEventHandlers
{
public override void OnCreated(
PSLibrary.PSContextInfo contextInfo,
CustomFieldsPostEventArgs e)
{
// Create an EventLog instance and assign its source.
EventLog myLog = new EventLog();
myLog.Source = "Custom Field OnCreated Event Handler";
// Get information from the event arguments, and
// write an entry to the Application event log.
string userName = contextInfo.UserName.ToString();
string cfName =
e.CustomFieldInformation.CustomFields.Rows[0]["MD_PROP_NAME"].ToString();
byte cfTypeEnum =
(byte)e.CustomFieldInformation.CustomFields.Rows[0]["MD_PROP_TYPE_ENUM"];
Guid cfUid =
(Guid)e.CustomFieldInformation.CustomFields.Rows[0]["MD_PROP_UID"];
string[] cfTypes =
Enum.GetNames(typeof(PSLibrary.CustomField.Type));
string cfType = "";
int index = 0;
e.CustomFieldInformation;
foreach (int i in
Enum.GetValues(typeof(PSLibrary.CustomField.Type)))
{
if (i == Convert.ToInt32(cfTypeEnum))
{
cfType = cfTypes[index];
break;
}
index++;
}
int eventId = 3652;
string logEntry;
logEntry = "User: " + userName +
"\nCustom Field Name: " + cfName +
"\nGUID: " + cfUid.ToString() +
"\nType: " + cfType +
"\nThe custom field has been created.";
myLog.WriteEntry(logEntry, EventLogEntryType.Information,
eventId);
}
}
When you create a class that inherits from ProjectEventReceiver, and crtete
a method within it, you should see all of the pre- and post-events within
the Intellisense list (for the list of events, see ProjectEventReceiver
Methods (Microsoft.Office.Project.Server.Events) --
http://msdn2.microsoft.com/en-us/li...rver.events.projecteventreceiver_methods.aspx -
- in the SDK. If you don't, check whether you've set a reference to
Microsoft.Office.Project.Server.Events, and included it in the using
statements:
using Microsoft.Office.Project.Server.Events;
Whether an event is fired, depends on the situation. If you're using WinProj
Pro, you have to save to get the OnCreating event. Another possibility is
that the event handler isn't registered properly. You need the exact
Namespace.ClassName, and the correct assembly name, e.g.
TestEventHandler,Version=1.0.0.0,Culture=Neutral,PublicKeyToken=1e3db2b86a6e0210
--Jim