locked
[EWS] StreamingNotification Calendar FolderEvent instead of ItemEvent ?? RRS feed

  • Question

  • Hi,

    I created a service that should catch modifications to calendar items. Here is my code :

    service.Credentials = new WebCredentials("blablabla", "blablabla", domain);
    service.Url = new Uri(ExchangeURL);
    
    FolderId folder1 = new FolderId(WellKnownFolderName.Calendar, new Mailbox("blablabla"));
    
    var trackedEvents = new EventType[] { EventType.Deleted, EventType.Modified, EventType.Moved, EventType.Created };
    
    var folderIds1 = new FolderId[] { folder1 };
    
    StreamingSubscription subscription1 = service.SubscribeToStreamingNotifications(folderIds1, trackedEvents);
    
    StreamingSubscriptionConnection connection = new StreamingSubscriptionConnection(service, 1);
    
    connection.AddSubscription(subscription1);
    connection.OnNotificationEvent += new StreamingSubscriptionConnection.NotificationEventDelegate(OnEvent);
    connection.OnSubscriptionError += new StreamingSubscriptionConnection.SubscriptionErrorDelegate(OnError);
    connection.OnDisconnect += new StreamingSubscriptionConnection.SubscriptionErrorDelegate(OnDisconnect);
    connection.Open();
    

    This is the code for the event :

    static void OnEvent(object sender, NotificationEventArgs args) {
        StreamingSubscription subscription = args.Subscription;
    
        foreach (NotificationEvent notifyEvt in args.Events) {
            if (notifyEvt is ItemEvent) {
                FolderEvent folderEvent = (FolderEvent)notifyEvt;
            }
        }
    }

    I have 2 questions about this.

    The most important: I'm really puzzled why the event I received is a FolderEvent instead of a ItemEvent. I would like to have the information about the calendar item, not the folder. There is really nothing usefull on that FolderId. What is important is the Id of the item, so I can bind that to the Appointment. Or in case of a deletion, just to know the Id. But it seems there is no way to achieve this? 

    Second question : I noticed that the OnEvent is sometimes not fired, and in case it's fired, there is sometimes a long delay. If not fired and I restart my application and do exactly the same thing, then the event is fired. I feel like it's a bit like unpredicatable.

    Many thanks in advance !

    Friday, May 10, 2019 10:14 AM

All replies

  • There is a mistake in the Event code :

    if (notifyEvt is ItemEvent) {
                FolderEvent folderEvent = (FolderEvent)notifyEvt;
            }

    It's never ItemEvent, always FolderEvent....

    Friday, May 10, 2019 10:16 AM