2016-11-28 5 views
0

特定の共有予定の予定表からすべての予定を取得するSSISパッケージを実装しました。EWSを使用して定期的な予定を含む予定を取得する

私が気づいたのは、繰り返しのものは一種の仮想なので返されないということです。彼らのマスターだけが、私に繰り返しのものを手に入れる能力を与えるでしょう。

私のコードを見ると、どのように私は定期的なものを取り出すことができますか?

私はちょっと立ち往生していますが、ヒントは非常に高く評価されています!

#region Namespaces 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Data; 
using Microsoft.SqlServer.Dts.Pipeline.Wrapper; 
using Microsoft.SqlServer.Dts.Runtime.Wrapper; 
using Microsoft.Exchange.WebServices.Data; 
#endregion 

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute] 
public class ScriptMain : UserComponent 
{ 
    string sharedCalendarID; 

    static FolderId FindPublicFolder(ExchangeService myService, FolderId baseFolderId, string folderName) 
    { 

     // search using paging. 
     FolderView folderView = new FolderView(10, 0); 
     folderView.OffsetBasePoint = OffsetBasePoint.Beginning; 
     // need only DisplayName and Id of every folder 
     // reduce the property set to the properties 
     folderView.PropertySet = new PropertySet(FolderSchema.DisplayName, FolderSchema.Id); 

     FindFoldersResults folderResults; 
     do 
     { 
      folderResults = myService.FindFolders(baseFolderId, folderView); 

      foreach (Folder folder in folderResults) 
       if (String.Compare(folder.DisplayName, folderName, StringComparison.OrdinalIgnoreCase) == 0) 
        return folder.Id; 

      if (folderResults.NextPageOffset.HasValue) 
       // go to the next page 
       folderView.Offset = folderResults.NextPageOffset.Value; 
     } 
     while (folderResults.MoreAvailable); 

     return null; 
    } 

    public override void CreateNewOutputRows() 
    { 
     // IMPORTANT: ExchangeService is NOT thread safe, so one should create an instance of 
     // ExchangeService whenever one needs it. 
     ExchangeService myService = new ExchangeService(ExchangeVersion.Exchange2013_SP1); 

     myService.Credentials = new NetworkCredential("username", "password"); 
     myService.Url = new Uri("https://......Exchange.asmx"); 
     // next line is very practical during development phase or for debugging 
     myService.TraceEnabled = true; 

     Folder myPublicFoldersRoot = Folder.Bind(myService, WellKnownFolderName.PublicFoldersRoot); 
     string myPublicFolderPath = @"CHI\WIED PFL Agenda"; 
     string[] folderPath = myPublicFolderPath.Split('\\'); 
     FolderId fId = myPublicFoldersRoot.Id; 
     foreach (string subFolderName in folderPath) 
     { 
      fId = FindPublicFolder(myService, fId, subFolderName); 
      if (fId == null) 
      { 
       // No Calendar found 
       return; 
      } 
     } 

     // verify 
     Folder folderFound = Folder.Bind(myService, fId); 
     if (String.Compare(folderFound.FolderClass, "IPF.Appointment", StringComparison.Ordinal) == 0) 
     { 
      sharedCalendarID = fId.ToString(); ; 
     } 
     else 
      return; 

     CalendarFolder myPublicFolder = CalendarFolder.Bind(myService, 
      //WellKnownFolderName.Calendar, 
      fId, 
      PropertySet.FirstClassProperties); 

     // search using paging. page size 10 
     ItemView viewCalendar = new ItemView(10); 
     // include all properties which we need in the view 
     // comment the next line then ALL properties will be read from the server. 
     //viewCalendar.PropertySet = new PropertySet(ItemSchema.Subject, ItemSchema.Id); 
     viewCalendar.Offset = 0; 
     viewCalendar.OffsetBasePoint = OffsetBasePoint.Beginning; 
     viewCalendar.OrderBy.Add(ContactSchema.DateTimeCreated, SortDirection.Descending); 
     FindItemsResults<Item> findResultsCalendar; 
     do 
     { 
      //SearchFilter searchFilter = new SearchFilter.IsGreaterThan(AppointmentSchema.Start, DateTime.Today); 
      var searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, 
      new SearchFilter.IsEqualTo(ItemSchema.ItemClass, "IPM.Appointment"), 
      new SearchFilter.IsGreaterThanOrEqualTo(AppointmentSchema.Start, DateTime.Now), 
      new SearchFilter.IsLessThan(AppointmentSchema.Start, DateTime.Now.AddDays(4))); 

      findResultsCalendar = myPublicFolder.FindItems(searchFilter, viewCalendar); 

      //get additional properties for each item returned by view, do this as view cannot return a lot of useful stuff like attendees 
      ServiceResponseCollection<ServiceResponse> addProperties = 
         myService.LoadPropertiesForItems(from Item item in findResultsCalendar select item, 
         new PropertySet(
           BasePropertySet.IdOnly, 
           AppointmentSchema.Body, 
           AppointmentSchema.Subject, 
           AppointmentSchema.Start, 
           AppointmentSchema.End, 
           AppointmentSchema.IsRecurring, 
           AppointmentSchema.AppointmentType 
           )); 

      List<Appointment> additionalProperties = new List<Appointment>(addProperties.Count); 

      if (addProperties != null) 
      { 
       foreach (ServiceResponse currentResponce in addProperties) 
       { 
        additionalProperties.Add(((Appointment)((GetItemResponse)currentResponce).Item)); 
       } 
      } 

      foreach (Item item in findResultsCalendar) 
      { 
       Appointment appt = item as Appointment; 

       if (item is Appointment || appt.AppointmentType == AppointmentType.RecurringMaster) 
       { 
        Appointment currentAppointmentAddProps = null; 
        currentAppointmentAddProps = additionalProperties.Find(
         delegate(Appointment arg) 
         { 
          return arg.Id == item.Id; 
         } 
        ); 

        //convert to int wether the Appointment is recurring or not 
        int isRecurring = currentAppointmentAddProps.IsRecurring ? 1 : 0; 

        Appointment appoint = item as Appointment; 
        OutputRecordSetBuffer.AddRow(); 
        OutputRecordSetBuffer.ActualEndDate = currentAppointmentAddProps.End; 
        OutputRecordSetBuffer.ActualStartDate = currentAppointmentAddProps.Start; 
        OutputRecordSetBuffer.Subject = appoint.Subject; 
        OutputRecordSetBuffer.EntryID = Guid.NewGuid(); 
        //OutputRecordSetBuffer.Detail = appoint.Body.ToString(); 
        //OutputRecordSetBuffer.CalendarID = fId.ToString(); 
        //OutputRecordSetBuffer.AppointmentID = appoint.Id.ToString(); 
        OutputRecordSetBuffer.CalendarID = sharedCalendarID; 
        OutputRecordSetBuffer.AppointmentID = Guid.NewGuid(); 
        OutputRecordSetBuffer.IsRecurring = isRecurring; 

       } 
      } 

      if (findResultsCalendar.NextPageOffset.HasValue) 
       // go to the next page 
       viewCalendar.Offset = findResultsCalendar.NextPageOffset.Value; 
     } 
     while (findResultsCalendar.MoreAvailable); 
    } 
} 

答えて

0

私は自分で自分の問題を解決した:)

代わりItemViewクラスを使用して、私はCalendarViewクラスを使用していました。

CalendarViewも定期的な予定を展開しています:

関連する問題