How do I add/create event handler associations?

X

x_celdin_x

I know I've seen documentation on the methods and members of the Events web
service in the SDK but I haven't seen any code examples for adding event
handler associations. Let me explain what I'm looking for and hopefully
someone can shed some light for me.

I have created an event handler for the project OnPublished event and I now
want to create an install application that will install the dll into the GAC
and add the association to the event in Project Server 2007. Putting the dll
into the GAC is easy enough, yes I managed this all on my own :)P), but I'm
having a hard time finding and figuring out how to begin coding for making
the association to the eventhandler.

Any help is greatly appreciated. Thanks everyone!
 
J

Jim Corbin [MSFT]

Although the Project SDK does not currently have code examples for the
Events methods in the PSI, they are pretty straightforward with the CRUD
methods (create, read, update, delete) for event handler associations (
http://msdn2.microsoft.com/en-us/library/websvcevents.events_methods.aspx ).

If you can use PWA to add event handler associations, you should be able to
see how to use the PSI Events methods, because PWA itself uses those
methods.
Then adapt a simple app such as How to: Log on to Project Server
Programmatically to do the same thing (
http://msdn2.microsoft.com/en-us/library/ms455600.aspx ).

--Jim
 
X

x_celdin_x

Hey Jim, thanks for your reply. I have developed some code that I believe
should be able to add an event handler association but it doesn't seem to
work; I seem to be missing a step somewhere. The code runs without error so I
know I'm on the right track, just not sure how to finish it off; any help or
hints you can send my way is greatly appreciated.

Here is the code:

this.Cursor = Cursors.WaitCursor;
try
{
//create web service...
EventsWS.Events lc_eventsWebService = new EventsWS.Events();
lc_eventsWebService.Url = FBaseUrl + FEventsWSPath;
lc_eventsWebService.Credentials =
CredentialCache.DefaultCredentials;

//get id for Project OnPublished event...
int li_eventId = GetEventId(lc_eventsWebService);

//create dataset...
EventsWS.EventHandlersDataSet lc_handlerDataSet =
new EventsWS.EventHandlersDataSet();

//create row...
EventsWS.EventHandlersDataSet.EventHandlersRow lc_handlerRow =
lc_handlerDataSet.EventHandlers.NewEventHandlersRow();

//edit row...
Guid lc_handlerGuid = Guid.NewGuid();
lc_handlerRow.EventHandlerUid = lc_handlerGuid;
lc_handlerRow.EventId = li_eventId;
lc_handlerRow.Name = "Project.OnPublished Event";
lc_handlerRow.Description = "Import the published project into our
system.";
lc_handlerRow.AssemblyName = "OurOnPublished, Version=1.0.0.0,
Culture=Neutral, PublicKeyToken=4610b969504e2353";
lc_handlerRow.ClassName = "OurOnPublished.OurOnPublishedEvent";
lc_handlerRow.Order = 1;

//add row to dataset...
lc_handlerDataSet.EventHandlers.AddEventHandlersRow(lc_handlerRow);

//create event handler...
lc_eventsWebService.CreateEventHandlerAssociations(lc_handlerDataSet);

MessageBox.Show("OurOnPublished Event was added successfully!", "Add
Event", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Add Event",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
this.Cursor = Cursors.Default;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top