none
How to track the creation of project of particular EPT type in PS2010 Server Side Event Handlers? RRS feed

  • Question

  • Hello,

    I've created custom Enterprise Project Type (EPT) and need to execute custom logic when the project of this EPT is created.

    I've tried to use PS2010 Server Side Event Handlers (OnCreated, OnPublished, OnAdded and other "post"-events) for this purpose. I made PSI call to(particularly ReadProjectEntities method of  Project service) from the code and tried to read ENTERPRISE_PROJECT_TYPE_UID column. But it doesn't conain my EPT type Uid, for some reason. How can I work-around that?

    PS: the same approach I'm using successfully with OnUpdated event handler, but I have no success with creation-time events.

    Regards,

    Andrew

    • Moved by Alexander.BurtonModerator Monday, November 22, 2010 9:06 AM Programming Question (From:Project Server General Questions and Answers)
    Monday, November 22, 2010 9:00 AM

All replies

  • Hi,

    Just curious as to why you are looking at Event Handlers, instead of developing an EPT associated workflow to perform the processing? 

    (Also moving this to the Programming and Customisation forum).

    Alex.


    Alex Burton
    www.epmsource.com | Twitter
    Project Server TechCenter | Project Developer Center | Project Server Help | Project Product Page
    Monday, November 22, 2010 9:05 AM
    Moderator
  • Hi, thanks for quick response!

    My logic is to run my code when the project is either created or updated, so I'd like to have one general approach for it. Besides there were no any business needs to create project workflow, and the plan was to dispense with it.

    Rerards,

    Andrew

    Monday, November 22, 2010 9:29 AM
  • Hi PS2010 team!

    Has anybody got a chance to take a look at this problem?

    Monday, November 29, 2010 12:56 PM
  • Hi Andrew,

    Looking at the data returned by the new 2010 version of ProjTool I can certainly see my Enterprise_Project_Type_UID and the Enterprise_Project_Type_Name returned by the ReadProjectList call.  I know this call has extra overhead so may not be the best call to use.  Are you not seeing these values returned with ReadProjectEntities with Entity type of 1?  How about ReadProjectStatus - that should also return the Project Dataset.  I can dig deeper if you let me know what you are seeing.

    Best regards,

    Brian.


    Blog | Facebook | Twitter | Posting is provided "AS IS" with no warranties, and confers no rights.
    Project Server TechCenter | Project Developer Center | Project Server Help | Project Product Page
    Tuesday, November 30, 2010 8:47 PM
    Owner
  • Hi Brian,

    the problem is to access EPT Uid somewhere on project creation, there is no problem to get it on project update.

    I've tried to use all three methods you've suggested in my "OnCreated" Event Handler, but none of them give me the EPT Uid. Here is the code I've using:

     

    public class ProjectEventReceiver : Microsoft.Office.Project.Server.Events.ProjectEventReceiver

    {

        public override void OnCreated(PSContextInfo contextInfo, ProjectPostEventArgs e)

        {

            base.OnCreated(contextInfo, e);

            System.Diagnostics.Debugger.Break();

     

            var svcProject = ...//instantiate "Project" WCF service here

            var eptUid = new Guid("09fa52b4-059b-4527-926e-99f9be96437a");//my EPT Guid, OOB "Basic Project Plan" is used in this sample

            ProjectDataSet ds;

            bool isMyEPT;

            ds = svcProject.ReadProjectEntities(e.ProjectGuid, 1, DataStoreEnum.WorkingStore);

            isMyEPT = eptUid == GetEPTUid(ds, e.ProjectGuid);

            if (isMyEPT)

            {

                   //never gets here

            }

     

            ds = svcProject.ReadProjectList();

            isMyEPT = eptUid == GetEPTUid(ds, e.ProjectGuid);

            if (isMyEPT)

            {

                       //never gets here

            }

     

            ds = svcProject.ReadProjectStatus(e.ProjectGuid,DataStoreEnum.WorkingStore,e.ProjectName, 1);

            isMyEPT = eptUid == GetEPTUid(ds, e.ProjectGuid);

            if (isMyEPT)

            {

                   //never gets here

            }

        }

     

        private Guid GetEPTUid(ProjectDataSet ds, Guid projUid)

        {

            var projectRow = ds.Project.Rows

                .Cast<ProjectDataSet.ProjectRow>()

                .First(row => row.PROJ_UID == projUid);

     

            // the statement "projectRow.IsENTERPRISE_PROJECT_TYPE_NAMENull()" always true,

            // so can't access projectRow.ENTERPRISE_PROJECT_TYPE_UID without this check for it will throw an exception

            return projectRow.IsENTERPRISE_PROJECT_TYPE_NAMENull()

                       ? Guid.Empty

                       : projectRow.ENTERPRISE_PROJECT_TYPE_UID;

        }

     

    }

    Any idea?

    Thanks in advance,

    Andrew

     

    Wednesday, December 1, 2010 8:45 AM
  • Hi PS2010 team!

    Has anybody got a chance to take a look at this problem?

    Tuesday, December 7, 2010 10:57 AM
  • Any progress here?
    Monday, December 13, 2010 4:35 PM
  • Can anyone answer if this is a bug or expected behavior? Will it be fixed?
    Friday, December 24, 2010 2:32 PM
  • Any progress here?
    Thursday, January 13, 2011 8:55 AM
  • Hi Andrew,

    I haven't been able to find a workaround for you - but getting back to Alex's response if you have more than one EPT and you wan to execute some special code when different ones are created then Demand Management is really what you are doing.  It doesn't need to be 'workflow' as such - but that is designed to execute different stuff based on different EPTs.  Also using ProjTool for 2010 I do see the ENTERPRISE_PROJECT_TYPE_UID returned for each project so not sure why you are seeing these in your code.  In debug can you view the dataset - rather than trying to use the match to your GUID?

    Best regards,

    Brian.


    Blog | Facebook | Twitter | Posting is provided "AS IS" with no warranties, and confers no rights.
    Project Server TechCenter | Project Developer Center | Project Server Help | Project Product Page
    Thursday, January 13, 2011 9:34 PM
    Owner
  • Hi Brian,

    Thanks a lot for your response. Not sure what you mean by phrase " In debug can you view the dataset - rather than trying to use the match to your GUID". If I understand it correctly, you suggest to debug event handler and to check the content of dataset. I've already tried these steps, and unfortunately with no success...

    As for seeing ENTERPRISE_PROJECT_TYPE_UID in ProjTool for 2010, it is really accessible by PSI when the project is already created, but not in Event Handler, like in my case.

    Thanks,

    Andrew

    Monday, January 17, 2011 2:06 PM
  • Yes Andrew - you understood my meaning for the debug.  The thing confusing me is that this is an 'OnCreated' event handler - so re-reading the dataset at that point should be no different than reading for any other created project (for example through ProjTool).  I'll make some time this week to have more of a play with this one Andrew.

    Best regards,

    Brian.


    Blog | Facebook | Twitter | Posting is provided "AS IS" with no warranties, and confers no rights.
    Project Server TechCenter | Project Developer Center | Project Server Help | Project Product Page
    Monday, January 17, 2011 3:04 PM
    Owner
  • Yes, I had the same opinion before I tried it. This is why I asked if this is a bug or known limitation/expected behavior.

    Thank you again for looking into this issue!

    Regards,

    Andrew.

    Tuesday, January 18, 2011 8:46 AM
  • Hi Andrew,

    It looks like the 'Created' event fires during the 'creating' queue process - and that queue job is held up until the event handler completes.  At the stage it fires the project exists but has not completed the first full save - and I am seeing the same as you when making a PSI call within the handler - NULL for the EPT name and GUID.  I am making enquiries internally at Microsoft to understand why this is happening.  It certainly looks like a bug to me - or the event should be renamed nearlycreated...  I will let you know what I find.

    I am guessing that it might be possibly to spawn another process to do the work - so that the event handler completes and the queue job finishes, but even this would be prone to potential timing issues unless you also monitored the queue job from this other process.

    Best regards,

    Brian.


    Blog | Facebook | Twitter | Posting is provided "AS IS" with no warranties, and confers no rights.
    Project Server TechCenter | Project Developer Center | Project Server Help | Project Product Page
    Tuesday, January 18, 2011 7:45 PM
    Owner
  • And just as I type my response I get an answer:

    The EPT association can be found on WorkflowStarted event. Usually, after the project is created, a new queue job is triggered for StartWorkflow. It has a misleading name since this is triggered even for EPTs without workflow and inserts the link between project and EPT in our tables. I think we can document this better, so that customers can find the solution faster.

    Best regards, and thanks to Bia!

    Brian.


    Blog | Facebook | Twitter | Posting is provided "AS IS" with no warranties, and confers no rights.
    Project Server TechCenter | Project Developer Center | Project Server Help | Project Product Page
    Tuesday, January 18, 2011 7:46 PM
    Owner
  • Sorry to get your hopes up Andrew - this looks like it has a bug and only raises the event for new project based on an EPT that has a workflow attached...  I'll keep you posted once I hear more.
    Blog | Facebook | Twitter | Posting is provided "AS IS" with no warranties, and confers no rights.
    Project Server TechCenter | Project Developer Center | Project Server Help | Project Product Page
    Tuesday, January 18, 2011 11:31 PM
    Owner
  • Thanks  a lot Brian for getting into this issue deeply and for escalating it! Hope it will have some resolution in nearby future!
    Wednesday, January 19, 2011 7:29 AM