Freigeben über


Calendar.UpdateCalendars-Methode

Fügt hinzu, ändert oder löscht Enterprise Kalenderausnahmen.

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

Syntax

'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Calendar/UpdateCalendars", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Calendar/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Calendar/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Sub UpdateCalendars ( _
    calendarDataSet As CalendarDataSet, _
    validateOnly As Boolean, _
    autoCheckIn As Boolean _
)
'Usage
Dim instance As Calendar
Dim calendarDataSet As CalendarDataSet
Dim validateOnly As Boolean
Dim autoCheckIn As Boolean

instance.UpdateCalendars(calendarDataSet, _
    validateOnly, autoCheckIn)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Calendar/UpdateCalendars", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Calendar/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Calendar/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public void UpdateCalendars(
    CalendarDataSet calendarDataSet,
    bool validateOnly,
    bool autoCheckIn
)

Parameter

  • validateOnly
    Typ: System.Boolean

    Wenn True, führt ein Test, um sicherzustellen, dass die Daten wird eingecheckt ist gültig, aber nicht die Checkin abgeschlossen.

  • autoCheckIn
    Typ: System.Boolean

    Wenn True, die neu erstellte Kalenderausnahmen automatisch eingecheckt werden.

Hinweise

Die UpdateCalendars -Methode fügt neue Ausnahmen, löscht Ausnahmen, die nicht vorhanden sind und Ausnahmen gemäß der CalendarDataSet -Objekts ändert.

Die UpdateCalendars -Methode unterstützt nur Kalenderausnahmen für Enterprise-Kalender, nicht alle Funktionen von Enterprise-Kalender in Project Server. Sie können hinzufügen oder löschen Zeit deaktiviert für Project Server-Ressourcen als Kalenderausnahmen mithilfe des WebSvcResource -Namespaces.

Diese Methode ändert nicht Enterprise Kalenderausnahmen. Wenn Updates erforderlich sind, müssen Sie löschen und neu erstellen die Kalenderausnahmen.

Arbeitswochen Enterprise-Kalender in der veröffentlichten Datenbank nicht normalisiert. Informationen zur Arbeitswoche wird als binäre Daten gespeichert werden, daher sind keine direkten Abfragen für alle Kalenderinformationen eine CalendarDataSetLaden verfügbar.

Um die aktualisierte Ausnahme anzuzeigen, klicken Sie auf Edit Calendar in Project Web App.

Project Server-Berechtigungen

Berechtigung

Beschreibung

ManageEnterpriseCalendars

Ermöglicht einem Benutzer das Verwalten von Enterprise-Kalender. Die globale Berechtigung.

Beispiele

Der folgende Code die Kalender Listet die vorhandenen Kalenderausnahmen liest, checkt einen Kalender zu aktualisieren, fügt eine neue Ausnahme auf die Kalender- und Überprüfungen im Kalender dann wieder anmelden.

For more information about running this code sample, see Prerequisites for WCF-Based Code Samples.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ServiceModel;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace Microsoft.SDK.Project.Samples.TestCalendars
{
  class Calendar
  {
    private static SvcCalendar.CalendarClient calendarClient;
    private static SvcResource.ResourceClient resourceClient;
    private const string OUTPUT_FILES = @"C:\Projects\Samples\Output\";
    private const string ENDPOINT = "basicHttp_Calendar";
    private const string RES_ENDPOINT = "basicHttp_Resource";
    private static string outFilePath;
    private static string outExceptionsPath;

    static void Main(string[] args)
    {
      Guid[] calendarID = new Guid[3];
      calendarID[0] = new Guid("B6635B2E-E747-4771-A78B-24F7509629D0");
      calendarID[1] = new Guid("27FB4A18-00C4-491F-9C68-5C68C2B231F2");
      calendarID[2] = new Guid("8283C310-0877-49A2-9264-29A9EDA84CED");

      try
      {
        // Use the endpoints that are defined in app.config to configure the client.
        ConfigClientEndpoints(ENDPOINT);
        SetClientEndpoints(RES_ENDPOINT);

        // If directory does not exist, create it.
        if (!Directory.Exists(OUTPUT_FILES))
        {
          Directory.CreateDirectory(OUTPUT_FILES);
        }
        
        // Assign the path where the output XML file will be saved.
        outFilePath = OUTPUT_FILES + "CalendarList.xml";
        outExceptionsPath = OUTPUT_FILES + "ExceptionsList.xml";

        // Create a dataset.
        SvcCalendar.CalendarDataSet calendarDS =
          new SvcCalendar.CalendarDataSet();
        
        // Get the list of calendars.
        calendarDS = ListOfCalendars(calendarDS);
        
        // Read calendar exceptions.
        calendarDS = ReadCalendarExceptions(calendarDS);
        
        // Get the ID of the user.
        Guid me = resourceClient.GetCurrentUserUid();
        
        // Read the calendar rows.
        calendarDS = ReadCalendarRows(calendarDS);

        bool checkedOut = false;  

        // Check whether the calendar to be updated is checked out.
        foreach (SvcCalendar.CalendarDataSet.CalendarsRow calRow in calendarDS.Calendars)
        {
          if (calRow.CAL_UID == new Guid("8283C310-0877-49A2-9264-29A9EDA84CED"))
          {
            if (calRow.IsNull("CAL_CHECKOUTBY"))
            {
              // Check out the calendar.
              calendarClient.CheckOutCalendars(new Guid[] { calRow.CAL_UID });
              checkedOut = true;
              Console.WriteLine("Calendar checked out.....");
              break;
            }
            else
            {
              // Check whether the calendar is checked out by you.
              if (calRow.CAL_CHECKOUTBY == me)
              {
                checkedOut = true;
                Console.WriteLine("The calendar is already checked out by you");
                break;
              }
              else
              {
                checkedOut = false;
                Console.WriteLine("This calendar has already been checked out");
                Console.ReadLine();
                break;
              }
            }
          }
        }

        if (checkedOut)
        {
          // Copy the calendar to a new dataset for editing.
          string tableName = calendarDS.Calendars.TableName;
          string uidColumn = calendarDS.Calendars.CAL_UIDColumn.ColumnName;
          string nameColumn = calendarDS.Calendars.CAL_NAMEColumn.ColumnName;

          PSLibrary.Filter calFilter = new PSLibrary.Filter();
          
          calFilter.FilterTableName = tableName;
          calFilter.Fields.Add(new PSLibrary.Filter.Field(
            tableName, 
            nameColumn, 
            PSLibrary.Filter.SortOrderTypeEnum.None));
          calFilter.Fields.Add(new PSLibrary.Filter.Field(uidColumn));
          PSLibrary.Filter.FieldOperator foCalendar = new PSLibrary.Filter.FieldOperator(
            PSLibrary.Filter.FieldOperationType.Equal, 
            uidColumn, 
            "8283C310-0877-49A2-9264-29A9EDA84CED");
          calFilter.Criteria = foCalendar;
          
          SvcCalendar.CalendarDataSet returnedCalendarDataSet = 
            calendarClient.ReadCalendars(calFilter.GetXml(), false);
          
          // Update the calendar.
          Guid calID = new Guid("8283C310-0877-49A2-9264-29A9EDA84CED");
          UpdateCalendarException(calID, returnedCalendarDataSet);
          Console.WriteLine("Calendar updated successfully...");
        }
        
        // Check in calendars.
        calendarClient.CheckInCalendars(new Guid[] { calendarID[2] }, true);
        Console.WriteLine("Calendar has been checked in.....");
        
        // To see the updated calendar, call the read calendar exceptions method again.
        calendarDS = ReadCalendarExceptions(calendarDS);
      }

      catch (CommunicationException e)
      {
        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine("\n***System.ServiceModel.CommunicationException:");
        Console.WriteLine(e.ToString());
        Console.ResetColor();
      }
      finally
      {
        Console.Write("\r\n\r\nPress any key....");
        Console.ReadKey();
      }
    }
    // Read the calendar rows into a dataset.
    private static SvcCalendar.CalendarDataSet ReadCalendarRows(SvcCalendar.CalendarDataSet calendarDS)
    {
      PSLibrary.Filter cfilter = new PSLibrary.Filter();

      cfilter.FilterTableName = calendarDS.Calendars.TableName;
      cfilter.Fields.Add(new PSLibrary.Filter.Field(calendarDS.Calendars.TableName,
        calendarDS.Calendars.CAL_UIDColumn.ColumnName,
        PSLibrary.Filter.SortOrderTypeEnum.None));
      cfilter.Fields.Add(new PSLibrary.Filter.Field(calendarDS.Calendars.TableName,
        calendarDS.Calendars.CAL_CHECKOUTBYColumn.ColumnName,
        PSLibrary.Filter.SortOrderTypeEnum.None));

      calendarDS = calendarClient.ReadCalendars(cfilter.GetXml(), false);
      return calendarDS;
    }
        
    // Add a new exception to the exceptions table and update the calendar.
    private static void UpdateCalendarException(Guid cID, SvcCalendar.CalendarDataSet calDS)
    {
      SvcCalendar.CalendarDataSet.CalendarExceptionsRow calendarExceptionsRow = 
        calDS.CalendarExceptions.NewCalendarExceptionsRow();

      calendarExceptionsRow.CAL_UID = cID;
      calendarExceptionsRow.Name = "Stand Up Meeting";
      calendarExceptionsRow.Start = new DateTime(2010, 2, 2);
      calendarExceptionsRow.Finish = new DateTime(2010, 2, 4);
      calendarExceptionsRow.RecurrenceFrequency = 1;
      calendarExceptionsRow.RecurrenceType = 0; // 0 implies daily recurrence
      try
      {
        calDS.CalendarExceptions.AddCalendarExceptionsRow(calendarExceptionsRow);
        calendarClient.UpdateCalendars(calDS, false, false);
      }
      catch (Exception e)
      {
        Console.WriteLine(e.ToString());
      }
    }

    // Read the calendar exceptions.
    private static SvcCalendar.CalendarDataSet ReadCalendarExceptions(SvcCalendar.CalendarDataSet calendarDS)
    {
      PSLibrary.Filter filter = new PSLibrary.Filter();

      filter.FilterTableName = calendarDS.CalendarExceptions.TableName;
      filter.Fields.Add(new PSLibrary.Filter.Field(calendarDS.CalendarExceptions.TableName,
        calendarDS.CalendarExceptions.CAL_UIDColumn.ColumnName,
        PSLibrary.Filter.SortOrderTypeEnum.None));
      filter.Fields.Add(new PSLibrary.Filter.Field(calendarDS.CalendarExceptions.TableName,
        calendarDS.CalendarExceptions.NameColumn.ColumnName,
        PSLibrary.Filter.SortOrderTypeEnum.None));
      
      calendarDS = calendarClient.ReadCalendars(filter.GetXml(), false);
      calendarDS.WriteXml(outExceptionsPath);
      Console.WriteLine("\nSee XML output of calendar exceptions at {0}",
        outExceptionsPath);

      return calendarDS;
    }

    // Get the list of calendars.
    private static SvcCalendar.CalendarDataSet ListOfCalendars(SvcCalendar.CalendarDataSet calendarDS)
    {
      // Get the list of calendars.
      calendarDS = calendarClient.ListCalendars();
      calendarDS.WriteXml(outFilePath);
      
      // Write the list of calendars to an XML file.
      Console.WriteLine("\nSee XML output of the CalendarDataSet at {0}",
          outFilePath);

      return calendarDS;
    }
    
    // Configure the client endpoints.
    public static void ConfigClientEndpoints(string endpt)
    {
      calendarClient = new SvcCalendar.CalendarClient(endpt);
    }
    
    // Configure the client endpoints.
    public static void SetClientEndpoints(string ept)
    {
      resourceClient = new SvcResource.ResourceClient(ept);
    }
  }
}

Siehe auch

Referenz

Calendar Klasse

Calendar-Member

WebSvcCalendar-Namespace