none
Registering Remove Event for Project Online issue RRS feed

  • Question

  • Hi guys!

    I have started digging into Project Online and now have new issue. So, I am not sure if it's somehow related to what I have discovered yesterday (SharePoint v16 libraries dont work with Project v15 libraries), but I am not able to register an Remote event receiver in Project Online.

    Here is a simple code in my Provider Hosted SharePoint App. I have changed a TokenHelper to get right Project context and its seems to be working: I can get different EPTs, existing Event Handlers etc.

                using (var projectContext = spContext.CreateProjectContextWithContextToken())
                {
                    projectContext.ExecuteQuery();
                    projectContext.Load(projectContext.Projects);
                    projectContext.ExecuteQuery();
    
                    projectContext.Load(projectContext.EventHandlers);
                    Microsoft.ProjectServer.Client.EventHandler evh = projectContext.EventHandlers.GetByGuid(EventHandlerUid);
                    projectContext.Load(evh);
                    projectContext.ExecuteQuery();
                    if ((bool)evh.ServerObjectIsNull)
                    {
                        projectContext.EventHandlers.Add(new EventHandlerCreationInformation()
                        {
                            EndpointUrl = BaseUrl + "/AppEventReceiver.svc",
                            Id = EventHandlerUid,
                            Name = "Project OnCreating Demo Event",
                            EventId = (int)PSEventID.ProjectCreating,
                            Order = 1,
                            CancelOnError = true
                        });
                        projectContext.EventHandlers.Update();
                        projectContext.ExecuteQuery();
                    }
                    else
                    {
                        projectContext.EventHandlers.Remove(evh);
                        projectContext.EventHandlers.Update();
                        projectContext.ExecuteQuery();
                    }
    
                }
    AppEventReceiver.svc 

    is a simple class which implements IProjectEventReceiverRemote interface.

    However, I have following problems.

    1) For some reason, when I am trying to add new EventHandler, ExecuteQuery returns exception for timeout. When I am running the code again, I can see actually that my handler was successfully registered. Removing Handler takes a bit of time, but works fine.

    2) As soon as I add new Event Handler, I am not able to create any project. It's just keep showing "It takes some time..." 

    In IProjectEventReceiverRemote  I implemented the simple method:

            public ProjectPreEventArgs OnCreatingRemote(Microsoft.Office.Project.Server.Library.PSContextInfo contextInfo, Guid eventHandlerUid, ProjectPreEventArgs e)
            {
                using (var context = new SQLDataContext())
                {
                    context.ErrorLogs.InsertOnSubmit(new ErrorLog { errorMessage = "Method Called" });
                    context.SubmitChanges();
                }
    
                if (e.ProjectName.Contains("New"))
                {
                    e.CancelReason = "Not good";
                    e.Cancel = true;
                }
                return e;
            }

    but Its not hit.

    Any help will be appreciated!

    Thanks

    Nick

    Tuesday, September 30, 2014 10:54 AM

All replies

  • Hi Nick,

    I know this post is old, but I am facing similar issues. Were you able to fix the problem? If so, do you mind sharing the solution with me?

    Thanks!!

    Jorge


    • Edited by George TU Monday, July 24, 2017 2:47 PM
    Monday, July 24, 2017 1:53 PM