2011-05-23 24 views
4

我一直在尋找一個EWS pullsubscription示例,該示例允許我獲取自啓動訂閱以來爲用戶創建或修改的日曆事件的列表。我有工作代碼來獲取收件箱的這些信息,但我還沒有找到一個很好的例子來說明如何爲日曆做到這一點。EWS PullSubscription用於新建或修改的日曆活動

下面是收件箱的示例;任何人都可以向我提供鏈接或代碼示例,以使用Exchange Web服務請求訂閱爲日曆事件或約會完成相同的事情?

ExchangeService service; 
    PullSubscription subscriptionInbox; 

    private void SetService() { 
     service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); 
     service.Url = new Uri("https://mail.myserver.com/EWS/Exchange.asmx"); 
    } 

    private void SetSubscription() { 
     if(service == null) { 
      SetService(); 
     } 
     // Subscribe to pull notifications in the Inbox folder, and get notified when 
     // a new mail is received, when an item or folder is created, or when an item 
     // or folder is deleted. 
     subscriptionInbox = service.SubscribeToPullNotifications(
     new FolderId[] { WellKnownFolderName.Inbox }, 
     5 /* timeOut: the subscription will end if the server is not polled within 5 minutes. */, 
     null /* watermark: null to start a new subscription. */, 
     EventType.NewMail, EventType.Modified); 
    } 

    private void btnGetLatestMessages_Click(object sender, EventArgs e) { 
     if(subscriptionInbox == null) { 
      SetSubscription(); 
     } 
     GetEventsResults eventsInbox = subscriptionInbox.GetEvents(); 
     EmailMessage message; 
     // Loop through all item-related events. 
     foreach(ItemEvent itemEvent in eventsInbox.ItemEvents) { 
      switch(itemEvent.EventType) { 
       case EventType.NewMail: 
        try { 
         Item item = Item.Bind(service, itemEvent.ItemId); 
         if(item.ItemClass.ToLower() == "IPM.Note".ToLower()) { 
          message = EmailMessage.Bind(service, itemEvent.ItemId); 
          MessageBox.Show("Inbox/NewMail - " + message.Subject); 
         } 
        } catch(Exception ex) { 
         MessageBox.Show("EventType.NewMail - " + itemEvent.ItemId); 
        } 
        break; 
       case EventType.Modified: 
        try { 
         Item item = Item.Bind(service, itemEvent.ItemId); 
         if(item.ItemClass.ToLower() == "IPM.Note".ToLower()) { 
          message = EmailMessage.Bind(service, itemEvent.ItemId); 
          MessageBox.Show("Inbox/Modified - " + message.Subject); 
         } 
        } catch(Exception ex) { 
         MessageBox.Show("EventType.NewMail - " + itemEvent.ItemId); 
        } 
        break; 
      } 
     } 
    } 
+0

你的問題有我的問題的答案;) – 2012-06-21 14:55:58

回答

6

只需訂閱日曆,而不是指定事件類型的收件箱。

var subscriptionCalendar = service.SubscribeToPullNotifications(
    new[] { new FolderId(WellKnownFolderName.Calendar) }, 
    1440, 
    null, 
    EventType.Created, EventType.Modified); 

或者,您可以創建FolderId(WellKnownFolderName.Inbox)FolderId(WellKnownFolderName.Calendar)一個拉通知與EventType的你想要的。