Events.ReadEventHandlerAssociationsForEvent-Methode

Ruft Informationen zu allen der Ereignishandler für ein angegebenes Project Server-Ereignis.

Namespace:  WebSvcEvents
Assembly:  ProjectServerServices (in ProjectServerServices.dll)

Syntax

'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Events/ReadEventHandlerAssociationsForEvent", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Events/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Events/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function ReadEventHandlerAssociationsForEvent ( _
    eventId As PSEventID _
) As EventHandlersDataSet
'Usage
Dim instance As Events
Dim eventId As PSEventID
Dim returnValue As EventHandlersDataSet

returnValue = instance.ReadEventHandlerAssociationsForEvent(eventId)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Events/ReadEventHandlerAssociationsForEvent", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Events/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Events/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public EventHandlersDataSet ReadEventHandlerAssociationsForEvent(
    PSEventID eventId
)

Parameter

Rückgabewert

Typ: WebSvcEvents.EventHandlersDataSet
Die EventHandlersDataSet enthält Informationen zu allen Zuordnungen der Ereignis-Handler für ein bestimmtes Ereignis, einschließlich der Assemblynamen von Ereignishandlern, Klassennamen, Beschreibungen, die dazugehörige Ereignis und der Reihenfolge, in der einzelnen Ereignishandler (Sequenznummer) aufgerufen wird.

Hinweise

Project Server-Berechtigungen

Berechtigung

Beschreibung

ManageServerEvents

Kann der Server zum Verwalten von Ereignishandlern für serverseitige Ereignisse. Die globale Berechtigung.

Beispiele

Das folgende Beispiel zeigt die Verwendung der ReadEventHandlerAssociationsForEvent -Methode. Zu Beginn der Ausführung wird ein Ereignishandler für das CustomFieldsCreated -Ereignis erstellt. Die Anwendung verwendet ReadEventHandlerAssociationsForEvent für den Zugriff des Ereignishandlers vor dem Bearbeiten, und klicken Sie erneut, bevor Sie sichergestellt haben, dass der Änderung auf. Die Anwendung schreibt das ursprünglichen Ereignis Ereignishandler Dataset und das geänderte Ereignishandler Dataset, das zwei separate XML-Dateien und eine Liste aller Project Server-Ereignisse in einer dritten XML-Datei schreibt.

Im Beispiel wird den SvcEvent -Namespace in der Assembly für ProjectServerServices.dll Proxy verwendet.

Hinweis

In einigen Fällen kann es bis zu 60 Sekunden für den Event Handler Association-Prozess für die Durchführung dauern. Ein Intervall von dem Standbymodus muss festgelegt werden, damit es lange, bis dieser Prozess abgeschlossen ist. Andernfalls möglicherweise ein Fehler bei der Indizierung Dataset die Anwendung zu beenden. Wenn die Anwendung ausgeführt wird, ohne einen vorherigen Schritt abzuschließen, wird das Ergebnis nicht zuverlässig ist. In diesem Beispiel wird die Zeit für das Erstellen des Ereignishandlers zulässig ist, 45 Sekunden und die Zeit für den Zugriff auf den Ereignishandler zulässig ist 5 Sekunden. In einer Umgebung mit bestimmten ist experimentieren erforderlich, um die Zeitspanne zu ermitteln, die für diese Vorgänge abgeschlossen erforderlich ist.

The ConfigClientEndpoints method uses an app.config file for setting the WCF binding, behavior, and endpoint. For information about creating a PSI proxy assembly and an app.config file, see Prerequisites for WCF-Based Code Samples.

using System;
using System.Threading;
using System.Diagnostics;
using System.ServiceModel;
using System.Xml;
using Microsoft.SharePoint;
using PSLibrary = Microsoft.Office.Project.Server.Library;
using Microsoft.Office.Project.Server.Events;

namespace ManageEventHandler
{
    class Program
    {
        private static SvcEvents.EventsClient eventsClient;
        private const string ENDPOINT_EVENTS = "basicHttp_Events";

        // Change the output directory for your computer.
        private const string OUTPUT_FILES = @"C:\Project\Samples\Output\";
        private static string outFileCreatedEH;
        private static string outFileUpdatedEH;
        private static string outFileAllEvents;

        private static int dbWriteInterval = 35000;
        private static int dbReadInterval = 5000;

        static void Main(string[] args)
        {
            Console.WriteLine("\nStart Time: {0}", DateTime.Now.ToString());
            Stopwatch timer = new Stopwatch();
            timer.Start();

            // Set path and file name for output files and configure web service client endpoints.
            outFileCreatedEH = OUTPUT_FILES + "MEH_CreatedHandler.xml";
            outFileUpdatedEH = OUTPUT_FILES + "MEH_CreatedHandlerUpdated.xml";
            outFileAllEvents = OUTPUT_FILES + "MEH_AllEvents.xml";

            ConfigClientEndpoints();

            try
            {
                // Create an instance of an event handler dataset with one row.
                SvcEvents.EventHandlersDataSet eventHandlerDS = new SvcEvents.EventHandlersDataSet();
                SvcEvents.EventHandlersDataSet.EventHandlersRow ehRow = eventHandlerDS.EventHandlers.NewEventHandlersRow();

                // Add CustomFieldsCreated event handler registration information to the row.
                Guid uid = Guid.NewGuid();
                ehRow.EventHandlerUid = uid;
                ehRow.Name = "Custom Fields Created Event Handler";
                ehRow.AssemblyName =
                    "TestCreatedCustomField, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f94f2907cf07bc7c";
                ehRow.ClassName =
                    "Microsoft.SDK.Project.Samples.EventHandlers.TestCreatedCustomField.WriteCustomFieldCreatedEvent";
                ehRow.EventId = (int)SvcEvents.PSEventID.CustomFieldsCreated;
                ehRow.Description = "Test the OnCreated event handler for custom fields.";
                ehRow.Order = 1;
                eventHandlerDS.EventHandlers.AddEventHandlersRow(ehRow.EventHandlerUid, ehRow.Name,
                    ehRow.AssemblyName, ehRow.ClassName, ehRow.EventId, ehRow.Description, ehRow.Order);

                // Associate the event handler with the CustomFieldCreated event.
                eventsClient.CreateEventHandlerAssociations(eventHandlerDS);
                DisplayComment("\nCreating and storing a CustomFieldCreated event handler...", "Yellow");
                Thread.CurrentThread.Join(dbWriteInterval);
                DisplayTime(timer);

                // Retrieve the new event handler from the dataset by using its event identifier. 
                SvcEvents.EventHandlersDataSet initEvDS = eventsClient.ReadEventHandlerAssociationsForEvent(SvcEvents.PSEventID.CustomFieldsCreated);
                DisplayComment("\nRetrieving the new event handler from the database...", "Yellow");
                Thread.CurrentThread.Join(dbReadInterval);
                DisplayTime(timer);

                initEvDS.WriteXml(outFileCreatedEH);

                string currDesc = "\nDescription field of the retrieved event handler: \n  " + initEvDS.EventHandlers[0].Description;
                DisplayComment(currDesc, "White");


                // Modify the event handler description field and update the dataset.
                initEvDS.EventHandlers[0].Description = "This is the modified event handler description.";

                eventsClient.UpdateEventHandlerAssociations(initEvDS);
                DisplayComment("\nModifying the description field and updating the event handler...", "Yellow");
                Thread.CurrentThread.Join(dbWriteInterval);
                DisplayTime(timer);


                // Retrieve the event handler from the dataset by using its event identifier. 
                SvcEvents.EventHandlersDataSet updEvDS = eventsClient.ReadEventHandlerAssociationsForEvent(SvcEvents.PSEventID.CustomFieldsCreated);
                DisplayComment("\nRetrieving the updated event handler...", "Yellow");
                Thread.CurrentThread.Join(dbReadInterval);
                DisplayTime(timer);

                currDesc = "\nDescription field of the updated event handler: \n  " + updEvDS.EventHandlers[0].Description;
                DisplayComment(currDesc, "White");

                updEvDS.WriteXml(outFileUpdatedEH);

                // Compare the original and the modified description fields to verify that the dataset was updated.
                int same = eventHandlerDS.EventHandlers[0].Description.CompareTo(updEvDS.EventHandlers[0].Description);

                if (same == 0)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("\nThe description field was not modified during the alloted time.");
                    Console.ResetColor();

                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine(
                        "\n\nThe CustomFieldCreated event handler description has been modified \n  from '{0}' \n  to '{1}'",
                        eventHandlerDS.EventHandlers[0].Description, updEvDS.EventHandlers[0].Description, ".");
                    Console.ResetColor();
                }

                // Read the list of all events and write them to an output file.
                SvcEvents.EventsDataSet AllEventsDS = new SvcEvents.EventsDataSet();
                AllEventsDS = eventsClient.ReadEventsList();
                AllEventsDS.WriteXml(outFileAllEvents);
            }

            catch (FaultException fault)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                // Use the WCF FaultException, because the ASMX SoapException does not 
                // exist in a WCF-based application.
                WriteFaultOutput(fault);
                Console.ForegroundColor = ConsoleColor.Yellow;

            }
            finally
            {
                DisplayTime(timer);
                Console.ResetColor();
                Console.Write("\nPress any key to exit... ");
                Console.ReadKey(true);
            }
        }


        // Use the endpoint that is defined in app.config to configure the client.
        public static void ConfigClientEndpoints()
        {
            eventsClient = new SvcEvents.EventsClient(ENDPOINT_EVENTS);
        }

        public static void DisplayTime(Stopwatch timer)
        {

            // Pause the timer and display the current accumulated time in seconds.
            timer.Stop();
            TimeSpan ts = timer.Elapsed;
            string elapsedTime = String.Format("\n\tElapsed time: {0:F4} seconds ({1:F2} minutes) ",
                ts.TotalSeconds, ts.TotalMinutes);
            Console.WriteLine(elapsedTime);
            timer.Start();
        }

        public static void DisplayComment(string comment, string color)
        {
            switch (color)
            {
                case "White": Console.ForegroundColor = ConsoleColor.White; break;
                case "Red": Console.ForegroundColor = ConsoleColor.Red; break;
                case "Yellow": Console.ForegroundColor = ConsoleColor.Yellow; break;
                case "Cyan": Console.ForegroundColor = ConsoleColor.Cyan; break;
                default: Console.ForegroundColor = ConsoleColor.White; break;
            }

            Console.WriteLine("\n\n" + comment);
            Console.ResetColor();
        }

        // Extract a PSClientError object from the WCF FaultException object, and
        // then display the exception details and each error in the PSClientError stack.
        private static void WriteFaultOutput(FaultException fault)
        {
            string errAttributeName;
            string errAttribute;
            string errOut;
            string errMess = "".PadRight(30, '=') + "\r\n"
                + "Error details: \n" + "\r\n";

            PSLibrary.PSClientError error = Helpers.GetPSClientError(fault, out errOut);
            errMess += errOut;

            PSLibrary.PSErrorInfo[] errors = error.GetAllErrors();
            PSLibrary.PSErrorInfo thisError;

            for (int i = 0; i < errors.Length; i++)
            {
                thisError = errors[i];
                errMess += "\r\n".PadRight(30, '=') + "\r\nPSClientError output:\r\n\n";
                errMess += thisError.ErrId.ToString() + "\n";

                for (int j = 0; j < thisError.ErrorAttributes.Length; j++)
                {
                    errAttributeName = thisError.ErrorAttributeNames()[j];
                    errAttribute = thisError.ErrorAttributes[j];
                    errMess += "\r\n\t" + errAttributeName
                        + ": " + errAttribute;
                }
            }
            Console.WriteLine(errMess);
        }

        // Helper methods: GetPSClientError.
        class Helpers
        {
            // Helper method: GetPSClientError.
            /// <summary>
            /// Extract a PSClientError object from the ServiceModel.FaultException,
            /// for use in output of the GetPSClientError stack of errors.
            /// </summary>
            /// <param name="e"></param>
            /// <param name="errOut">Shows that FaultException has more information 
            /// about the errors than PSClientError has. FaultException can also contain 
            /// other types of errors, such as failure to connect to the server.</param>
            /// <returns>PSClientError object, for enumerating errors.</returns>
            public static PSLibrary.PSClientError GetPSClientError(FaultException e,
                                                                   out string errOut)
            {
                const string PREFIX = "GetPSClientError() returns null: ";
                errOut = string.Empty;
                PSLibrary.PSClientError psClientError = null;

                if (e == null)
                {
                    errOut = PREFIX + "Null parameter (FaultException e) passed in.";
                    psClientError = null;
                }
                else
                {
                    // Get a ServiceModel.MessageFault object.
                    var messageFault = e.CreateMessageFault();

                    if (messageFault.HasDetail)
                    {
                        using (var xmlReader = messageFault.GetReaderAtDetailContents())
                        {
                            var xml = new XmlDocument();
                            xml.Load(xmlReader);

                            var serverExecutionFault = xml["ServerExecutionFault"];
                            if (serverExecutionFault != null)
                            {
                                var exceptionDetails = serverExecutionFault["ExceptionDetails"];
                                if (exceptionDetails != null)
                                {
                                    try
                                    {
                                        errOut = exceptionDetails.InnerXml + "\r\n";
                                        psClientError =
                                            new PSLibrary.PSClientError(exceptionDetails.InnerXml);
                                    }
                                    catch (InvalidOperationException ex)
                                    {
                                        errOut = PREFIX + "Unable to convert fault exception info ";
                                        errOut += "a valid Project Server error message. Message: \n\t";
                                        errOut += ex.Message;
                                        psClientError = null;
                                    }
                                }
                                else
                                {
                                    errOut = PREFIX + "The FaultException e is a ServerExecutionFault, "
                                        + "but does not have ExceptionDetails.";
                                }
                            }
                            else
                            {
                                errOut = PREFIX + "The FaultException e is not a ServerExecutionFault.";
                            }
                        }
                    }
                    else // There is no detail in the MessageFault.
                    {
                        errOut = PREFIX + "The FaultException e does not have any detail.";
                    }
                }
                errOut += "\r\n" + e.ToString() + "\r\n";
                return psClientError;
            }


        }
    }
}

Es folgt ein Beispiel für die Ausgabedatei MEH_CreatedHandler.xml, die die Anwendung speichert.

<?xml version="1.0" standalone="true"?>
<EventHandlersDataSet xmlns="https://schemas.microsoft.com/office/project/server/webservices/EventHandlersDataSet/"> 
<EventHandlers> 
<EventHandlerUid>d4d0a891-02cd-4c5a-9c08-a3f88b295270</EventHandlerUid> 
<Name>Custom Fields Created Event Handler</Name>
<AssemblyName>TestCreatedCustomField, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f94f2907cf07bc7c</AssemblyName> <ClassName>Microsoft.SDK.Project.Samples.EventHandlers.TestCreatedCustomField.WriteCustomFieldCreatedEvent</ClassName> <EventId>26</EventId>
<Description>Test the OnCreated event handler for custom fields.</Description>
<Order>1</Order> 
</EventHandlers>
</EventHandlersDataSet>

Es folgt ein Beispiel für die Ausgabedatei MEH_CreatedHandlerUpdated.xml, die die Anwendung speichert.

<?xml version="1.0" standalone="true"?>
<EventHandlersDataSet xmlns="https://schemas.microsoft.com/office/project/server/webservices/EventHandlersDataSet/">
<EventHandlers>
<EventHandlerUid>d4d0a891-02cd-4c5a-9c08-a3f88b295270</EventHandlerUid>
<Name>Custom Fields Created Event Handler</Name>
<AssemblyName>TestCreatedCustomField, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f94f2907cf07bc7c</AssemblyName> <ClassName>Microsoft.SDK.Project.Samples.EventHandlers.TestCreatedCustomField.WriteCustomFieldCreatedEvent</ClassName> <EventId>26</EventId>
<Description>This is the modified event handler description.</Description>
<Order>1</Order>
</EventHandlers>
</EventHandlersDataSet>

Es folgt ein Beispiel für die Ausgabedateien MEH_AllEvents.xml, die die Anwendung speichert.

<?xml version="1.0" standalone="true"?>
<EventsDataSet xmlns="https://schemas.microsoft.com/office/project/server/webservices/EventsDataSet/"> -<Event> <EventId>0</EventId><SourceName>Admin</SourceName> <EventName>ReportingPeriodUpdated</EventName></Event> 
<Event><EventId>1</EventId><SourceName>Admin</SourceName> <EventName>ReportingPeriodUpdating</EventName></Event> 
<Event><EventId>2</EventId><SourceName>Admin</SourceName> <EventName>LineClassUpdated</EventName></Event> 
<Event><EventId>3</EventId><SourceName>Admin</SourceName> <EventName>LineClassUpdating</EventName></Event> 
<Event><EventId>4</EventId><SourceName>Admin</SourceName> <EventName>StatusReportsDeleted</EventName></Event> 
<Event><EventId>5</EventId><SourceName>Admin</SourceName> <EventName>StatusReportsDeleting</EventName></Event> 
<Event><EventId>10</EventId><SourceName>Admin</SourceName> <EventName>AdSyncERPSynchronized</EventName></Event>
…
<Event><EventId>197</EventId><SourceName>UserDelegation</SourceName> <EventName>Activating</EventName></Event> 
<Event><EventId>198</EventId><SourceName>UserDelegation</SourceName> <EventName>Changed</EventName></Event> 
<Event><EventId>199</EventId><SourceName>UserDelegation</SourceName> <EventName>Changing</EventName></Event> 
<Event><EventId>200</EventId><SourceName>UserDelegation</SourceName> <EventName>Deactivated</EventName></Event> 
<Event><EventId>201</EventId><SourceName>UserDelegation</SourceName> <EventName>Deactivating</EventName></Event> 
</EventsDataSet>

Siehe auch

Referenz

Events Klasse

Events-Member

WebSvcEvents-Namespace