In Project Server 2007 (SharePoint 2007) sono disponibili una serie di eventi gestibili lato server.

Per gestire gli eventi è necessario andare nella nel sito di Project Web Access (PWA) in Server Settings / Operational Policies / Server-Side Event Handler Configuration e per ogni evento che si vuole gestire indicare il full name dell'assembly (Assembly Name) e la classe (Class Name).
Attenzione, il cambiamento degli eventi è asincrono, quindi potrebbe volerci un po' di tempo prima che gli eventi vengano agganciati
Un esempio di classe per gestire gli eventi è questa:

C#

//assembly: Microsoft.Office.Project.Server.Events.Receivers e Microsoft.Office.Project.Server.Library
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Project.Server.Events;
using Microsoft.Office.Project.Server.Library;  //contiene PSContextInfo 
using Microsoft.SharePoint;

namespace SgartEventHandler
{
  private static string EVENTSOURCE = "Project Event Handler";
  private static int EVENTID = 3651;
  private static int SITELCID = 1033;

  //gestione eventi di tipo Project
  public class ProjectEventHandler : ProjectEventReceiver
  {

    public override void OnPublishing(Microsoft.Office.Project.Server.Library.PSContextInfo contextInfo, ProjectPrePublishEventArgs e)
    {
      EventLog myLog = new EventLog();
      myLog.Source = EVENTSOURCE;
      int eventId = EVENTID;
      myLog.WriteEntry("OnPublishing", EventLogEntryType.Information, eventId);
      
      //forzo il sito ad essere pubblicato in una precisa posizione
      e.WssUrl = "http://hsarepoint2007/sistes/Progetti/" + e.ProjectName;
      e.Cancel = false; //impostare a true per annullare la pubblicazione
    }

    public override void OnPublished(PSContextInfo contextInfo, ProjectPostPublishEventArgs e)
    {
      EventLog myLog = new EventLog();
      myLog.Source = EVENTSOURCE;
      int eventId = EVENTID;
      myLog.WriteEntry("OnPublished", EventLogEntryType.Information, eventId);
    }
  }

  //gestione eventi di tipo wss
  public class WssEventHandler : WssInteropEventReceiver
  {
    public override void OnWssWorkspaceCreated(PSContextInfo contextInfo, WssWorkspaceCreatedEventArgs e)
    {
      EventLog myLog = new EventLog();
      myLog.Source = EVENTSOURCE;
      int eventId = EVENTID;
      myLog.WriteEntry("OnWssWorkspaceCreated", EventLogEntryType.Information, eventId);
    }
  }
}
In questo caso la classe e solo un esempio e non fa nient'altro che registrare negli eventi di windows l'esecuzione degli stessi.
Faccio presente che la prima volta che si pubblica un sito con il relativo workspace vengono eseguiti gli eventi in quest'ordine:
  • OnPublishing: eseguito prima che il progetto venga pubblicato, utile per cambiare la url del workspace o per annullare la pubblicazione
  • OnPublished: il progetto è stato pubblicato, ma il sito di workspace non è ancora stato creato
  • OnWssWorkspaceCreated: il workspace è stato creato, si possono apportare personalizzazioni al sito
nelle successive pubblicazioni verranno eseguiti solo gli eventi
  • OnPublishing
  • OnPublished
Come dicevo questo è solo un esempio con un elenco parziale di eventi. L'elenco completo si trova a questo link http://msdn.microsoft.com/en-us/libr....events.aspx , le categorie gestibili sono:
  • Admin
  • Calendar
  • CubeAdmin
  • CustomFields
  • LookupTable
  • Notifications
  • Project
  • Reporting
  • Resource
  • Rules
  • Security
  • Statusing
  • StatusReports
  • Timesheet
  • WssInterop
ognuna di queste categorie espone una serie di eventi gestibili.
Per fare il debug dell'event hadler collegati al processo Microsoft.Office.Project.Server.Eventing.exe
Ad ogni modifica sarà necessario riavviare il servizio (su ogni server con project) per fare in modo che venga usato il nuovo assembly.
Lo script seguente ferma il servizio, registra nella gac il nuovo assembly e riavvia il servizio:

DOS / Batch file

net stop ProjectEventService

gacutil.exe /i <assemblyName>.dll

net start ProjectEventService
Tags:
C#235 Project Server12 SharePoint497 SharePoint 2007218
Potrebbe interessarti anche: