2016-11-28 2 views
0

특정 공유 Outlook 일정에서 모든 첨부 파일을 가져 오는 SSIS 패키지를 구현했습니다.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도 반복되는 약속을 확장합니다. 즉,

관련 문제