2016-11-28 98 views
0

我已經實現了一個SSIS包,通過特定的共享Outlook日曆獲取所有的約會。獲取Outlook約會,包括使用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還擴大了定期約會,這就是它:)