none
ResourceEventReceiver and value change RRS feed

  • Question

  • Hi,

    I'm trying to implement an event receiver for resource.

    What I want to do is changing some values on the resource when the resource has changed ex. the mail.

    I have tried to use the methods OnChanged, but when I get the resource from project server webservice and try to change it's values, it says it's already checkout by another user, which makes sense because the event receiver is ongoing a change for the resource.

    So my question is: How do I change the values on a resource from a event receiver on a resource?

    Tuesday, November 20, 2012 1:43 PM

Answers

  • Good question! You are simply too early in the process as you cannot get hold of the session under which the resource is checked out (unless you do some dirty work query directly the database). Luckily you can postphone the operation using the OnCheckedIn of the Resources PSI webservice. The ResourceCheckInPostEventArgs argument will pass you in the Resources member the resources that are checked in with (potentially different) properties. You need to check out again and do your additional modifications. To ensure that you are not calling endlessly check the resource out with specific names or account - and ignore the OnCheckedIn under that condition.


    Jan Cirpka

    Tuesday, November 20, 2012 6:31 PM

All replies

  • Good question! You are simply too early in the process as you cannot get hold of the session under which the resource is checked out (unless you do some dirty work query directly the database). Luckily you can postphone the operation using the OnCheckedIn of the Resources PSI webservice. The ResourceCheckInPostEventArgs argument will pass you in the Resources member the resources that are checked in with (potentially different) properties. You need to check out again and do your additional modifications. To ensure that you are not calling endlessly check the resource out with specific names or account - and ignore the OnCheckedIn under that condition.


    Jan Cirpka

    Tuesday, November 20, 2012 6:31 PM
  • Hi Jan,

    Thanks for your reply iv'e had found the event you talking about but I get some strange exceptions, when I try to connect to the webservice.

    Following code examples are what i'm using:

    var id = THE ID FROM EVENT ARGS!
    var ws = new Resource();
    ws.UseDefaultCredentials = true;
    var res = ws.ReadResource(id);

    I have tried to place this code in OnChanging, OnChanged and OnCheckOut where it works just fine, but when I place the exact same code in OnCheckedIn I get following exception:

    Event Handler \XXX.ResourceUpdater.Eventhandlers.ResourceUpdateHandler\ threw an exception: Unhandled Communication Fault occurred
       at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
       at XXX.ResourceUpdater.WSResource.Resource.ReadResource(Guid resourceUid)
       at XXX.ResourceUpdater.Eventhandlers.ResourceUpdateHandler.OnCheckedIn(PSContextInfo contextInfo, ResourceCheckInPostEventArgs e) 

    I cant get hold of what's wrong, do you have any questions?

    What I did to get around this problem is to make a new Thread with ThreadPool to do the change for the resource - where it worked, but I would like to find the real answer for what's wrong.

    I'll give you the mark for right answer but if you have any clue about the other strange problem, I would be glad to hear :)


    Wednesday, November 21, 2012 7:21 AM
  • I have no clue - and would suggest to open a new thread with this issue, such that everyone (and Microsoft in particular) takes a look at this. Sounds like a bug to me.

    Jan Cirpka

    Wednesday, November 21, 2012 9:46 AM