Implementation
// GetEventsResults GetEvents(string subscriptionId, string watermark)
// {
// return this.BuildGetEventsRequest(subscriptionId, watermark).Execute()[0].Results;
// }
/// <summary>
/// Begins an asynchronous request to retrieve the latests events associated with a pull subscription. Calling this method results in a call to EWS.
/// </summary>
/// <param name="callback">The AsyncCallback delegate.</param>
/// <param name="state">An object that contains state information for this request.</param>
/// <param name="subscriptionId">The Id of the pull subscription for which to get the events.</param>
/// <param name="watermark">The watermark representing the point in time where to start receiving events.</param>
/// <returns>An IAsyncResult that references the asynchronous request.</returns>
// IAsyncResult BeginGetEvents(
// AsyncCallback callback,
// object state,
// string subscriptionId,
// string watermark)
// {
// return this.BuildGetEventsRequest(subscriptionId, watermark).BeginExecute(callback, state);
// }
/// <summary>
/// Ends an asynchronous request to retrieve the latests events associated with a pull subscription.
/// </summary>
/// <param name="asyncResult">An IAsyncResult that references the asynchronous request.</param>
/// <returns>A GetEventsResults containing a list of events associated with the subscription.</returns>
// GetEventsResults EndGetEvents(IAsyncResult asyncResult)
// {
// var request = AsyncRequestResult.ExtractServiceRequest<GetEventsRequest>(this, asyncResult);
//
// return request.EndExecute(asyncResult)[0].Results;
// }
/// <summary>
/// Builds an request to retrieve the latests events associated with a pull subscription.
/// </summary>
/// <param name="subscriptionId">The Id of the pull subscription for which to get the events.</param>
/// <param name="watermark">The watermark representing the point in time where to start receiving events.</param>
/// <returns>An request to retrieve the latests events associated with a pull subscription. </returns>
//GetEventsRequest BuildGetEventsRequest(
// string subscriptionId,
// string watermark)
// {
// EwsUtilities.ValidateParam(subscriptionId, "subscriptionId");
// EwsUtilities.ValidateParam(watermark, "watermark");
//
// GetEventsRequest request = new GetEventsRequest(this);
//
// request.SubscriptionId = subscriptionId;
// request.Watermark = watermark;
//
// return request;
// }
/// <summary>
/// Subscribes to push notifications. Calling this method results in a call to EWS.
/// </summary>
/// <param name="folderIds">The Ids of the folder to subscribe to.</param>
/// <param name="url">The URL of the Web Service endpoint the Exchange server should push events to.</param>
/// <param name="frequency">The frequency, in minutes, at which the Exchange server should contact the Web Service endpoint. Frequency must be between 1 and 1440.</param>
/// <param name="watermark">An optional watermark representing a previously opened subscription.</param>
/// <param name="eventTypes">The event types to subscribe to.</param>
/// <returns>A PushSubscription representing the new subscription.</returns>
//PushSubscription SubscribeToPushNotifications(
// Iterable<FolderId> folderIds,
// Uri url,
// int frequency,
// string watermark,
// params EventType[] eventTypes)
// {
// EwsUtilities.ValidateParamCollection(folderIds, "folderIds");
//
// return this.BuildSubscribeToPushNotificationsRequest(
// folderIds,
// url,
// frequency,
// watermark,
// null,
// null, // AnchorMailbox
// eventTypes).Execute()[0].Subscription;
// }
/// <summary>
/// Begins an asynchronous request to subscribe to push notifications. Calling this method results in a call to EWS.
/// </summary>
/// <param name="callback">The AsyncCallback delegate.</param>
/// <param name="state">An object that contains state information for this request.</param>
/// <param name="folderIds">The Ids of the folder to subscribe to.</param>
/// <param name="url">The URL of the Web Service endpoint the Exchange server should push events to.</param>
/// <param name="frequency">The frequency, in minutes, at which the Exchange server should contact the Web Service endpoint. Frequency must be between 1 and 1440.</param>
/// <param name="watermark">An optional watermark representing a previously opened subscription.</param>
/// <param name="eventTypes">The event types to subscribe to.</param>
/// <returns>An IAsyncResult that references the asynchronous request.</returns>
//IAsyncResult BeginSubscribeToPushNotifications(
// AsyncCallback callback,
// object state,
// Iterable<FolderId> folderIds,
// Uri url,
// int frequency,
// string watermark,
// params EventType[] eventTypes)
// {
// EwsUtilities.ValidateParamCollection(folderIds, "folderIds");
//
// return this.BuildSubscribeToPushNotificationsRequest(
// folderIds,
// url,
// frequency,
// watermark,
// null,
// null, // AnchorMailbox
// eventTypes).BeginExecute(callback, state);
// }
/// <summary>
/// Subscribes to push notifications on all folders in the authenticated user's mailbox. Calling this method results in a call to EWS.
/// </summary>
/// <param name="url">The URL of the Web Service endpoint the Exchange server should push events to.</param>
/// <param name="frequency">The frequency, in minutes, at which the Exchange server should contact the Web Service endpoint. Frequency must be between 1 and 1440.</param>
/// <param name="watermark">An optional watermark representing a previously opened subscription.</param>
/// <param name="eventTypes">The event types to subscribe to.</param>
/// <returns>A PushSubscription representing the new subscription.</returns>
//PushSubscription SubscribeToPushNotificationsOnAllFolders(
// Uri url,
// int frequency,
// string watermark,
// params EventType[] eventTypes)
// {
// EwsUtilities.ValidateMethodVersion(
// this,
// ExchangeVersion.Exchange2010,
// "SubscribeToPushNotificationsOnAllFolders");
//
// return this.BuildSubscribeToPushNotificationsRequest(
// null,
// url,
// frequency,
// watermark,
// null,
// null, // AnchorMailbox
// eventTypes).Execute()[0].Subscription;
// }
/// <summary>
/// Begins an asynchronous request to subscribe to push notifications on all folders in the authenticated user's mailbox. Calling this method results in a call to EWS.
/// </summary>
/// <param name="callback">The AsyncCallback delegate.</param>
/// <param name="state">An object that contains state information for this request.</param>
/// <param name="url"></param>
/// <param name="frequency">The frequency, in minutes, at which the Exchange server should contact the Web Service endpoint. Frequency must be between 1 and 1440.</param>
/// <param name="watermark">An optional watermark representing a previously opened subscription.</param>
/// <param name="eventTypes">The event types to subscribe to.</param>
/// <returns>An IAsyncResult that references the asynchronous request.</returns>
//IAsyncResult BeginSubscribeToPushNotificationsOnAllFolders(
// AsyncCallback callback,
// object state,
// Uri url,
// int frequency,
// string watermark,
// params EventType[] eventTypes)
// {
// EwsUtilities.ValidateMethodVersion(
// this,
// ExchangeVersion.Exchange2010,
// "BeginSubscribeToPushNotificationsOnAllFolders");
//
// return this.BuildSubscribeToPushNotificationsRequest(
// null,
// url,
// frequency,
// watermark,
// null,
// null, // AnchorMailbox
// eventTypes).BeginExecute(callback, state);
// }
/// <summary>
/// Subscribes to push notifications. Calling this method results in a call to EWS.
/// </summary>
/// <param name="folderIds">The Ids of the folder to subscribe to.</param>
/// <param name="url">The URL of the Web Service endpoint the Exchange server should push events to.</param>
/// <param name="frequency">The frequency, in minutes, at which the Exchange server should contact the Web Service endpoint. Frequency must be between 1 and 1440.</param>
/// <param name="watermark">An optional watermark representing a previously opened subscription.</param>
/// <param name="callerData">Optional caller data that will be returned the call back.</param>
/// <param name="eventTypes">The event types to subscribe to.</param>
/// <returns>A PushSubscription representing the new subscription.</returns>
//PushSubscription SubscribeToPushNotifications(
// Iterable<FolderId> folderIds,
// Uri url,
// int frequency,
// string watermark,
// string callerData,
// params EventType[] eventTypes)
// {
// EwsUtilities.ValidateParamCollection(folderIds, "folderIds");
//
// return this.BuildSubscribeToPushNotificationsRequest(
// folderIds,
// url,
// frequency,
// watermark,
// callerData,
// null, // AnchorMailbox
// eventTypes).Execute()[0].Subscription;
// }
/// <summary>
/// Begins an asynchronous request to subscribe to push notifications. Calling this method results in a call to EWS.
/// </summary>
/// <param name="callback">The AsyncCallback delegate.</param>
/// <param name="state">An object that contains state information for this request.</param>
/// <param name="folderIds">The Ids of the folder to subscribe to.</param>
/// <param name="url">The URL of the Web Service endpoint the Exchange server should push events to.</param>
/// <param name="frequency">The frequency, in minutes, at which the Exchange server should contact the Web Service endpoint. Frequency must be between 1 and 1440.</param>
/// <param name="watermark">An optional watermark representing a previously opened subscription.</param>
/// <param name="callerData">Optional caller data that will be returned the call back.</param>
/// <param name="eventTypes">The event types to subscribe to.</param>
/// <returns>An IAsyncResult that references the asynchronous request.</returns>
//IAsyncResult BeginSubscribeToPushNotifications(
// AsyncCallback callback,
// object state,
// Iterable<FolderId> folderIds,
// Uri url,
// int frequency,
// string watermark,
// string callerData,
// params EventType[] eventTypes)
// {
// EwsUtilities.ValidateParamCollection(folderIds, "folderIds");
//
// return this.BuildSubscribeToPushNotificationsRequest(
// folderIds,
// url,
// frequency,
// watermark,
// callerData,
// null, // AnchorMailbox
// eventTypes).BeginExecute(callback, state);
// }
/// <summary>
/// Subscribes to push notifications on a group mailbox. Calling this method results in a call to EWS.
/// </summary>
/// <param name="groupMailboxSmtp">The smtpaddress of the group mailbox to subscribe to.</param>
/// <param name="url">The URL of the Web Service endpoint the Exchange server should push events to.</param>
/// <param name="frequency">The frequency, in minutes, at which the Exchange server should contact the Web Service endpoint. Frequency must be between 1 and 1440.</param>
/// <param name="watermark">An optional watermark representing a previously opened subscription.</param>
/// <param name="callerData">Optional caller data that will be returned the call back.</param>
/// <param name="eventTypes">The event types to subscribe to.</param>
/// <returns>A PushSubscription representing the new subscription.</returns>
//PushSubscription SubscribeToGroupPushNotifications(
// string groupMailboxSmtp,
// Uri url,
// int frequency,
// string watermark,
// string callerData,
// params EventType[] eventTypes)
// {
// var folderIds = new FolderId[] { new FolderId(WellKnownFolderName.Inbox, new Mailbox(groupMailboxSmtp)) };
// return this.BuildSubscribeToPushNotificationsRequest(
// folderIds,
// url,
// frequency,
// watermark,
// callerData,
// groupMailboxSmtp, // AnchorMailbox
// eventTypes).Execute()[0].Subscription;
// }
/// <summary>
/// Begins an asynchronous request to subscribe to push notifications. Calling this method results in a call to EWS.
/// </summary>
/// <param name="callback">The AsyncCallback delegate.</param>
/// <param name="state">An object that contains state information for this request.</param>
/// <param name="groupMailboxSmtp">The smtpaddress of the group mailbox to subscribe to.</param>
/// <param name="url">The URL of the Web Service endpoint the Exchange server should push events to.</param>
/// <param name="frequency">The frequency, in minutes, at which the Exchange server should contact the Web Service endpoint. Frequency must be between 1 and 1440.</param>
/// <param name="watermark">An optional watermark representing a previously opened subscription.</param>
/// <param name="callerData">Optional caller data that will be returned the call back.</param>
/// <param name="eventTypes">The event types to subscribe to.</param>
/// <returns>An IAsyncResult that references the asynchronous request.</returns>
//IAsyncResult BeginSubscribeToGroupPushNotifications(
// AsyncCallback callback,
// object state,
// string groupMailboxSmtp,
// Uri url,
// int frequency,
// string watermark,
// string callerData,
// params EventType[] eventTypes)
// {
// var folderIds = new FolderId[] { new FolderId(WellKnownFolderName.Inbox, new Mailbox(groupMailboxSmtp)) };
// return this.BuildSubscribeToPushNotificationsRequest(
// folderIds,
// url,
// frequency,
// watermark,
// callerData,
// groupMailboxSmtp, // AnchorMailbox
// eventTypes).BeginExecute(callback, state);
// }
/// <summary>
/// Subscribes to push notifications on all folders in the authenticated user's mailbox. Calling this method results in a call to EWS.
/// </summary>
/// <param name="url">The URL of the Web Service endpoint the Exchange server should push events to.</param>
/// <param name="frequency">The frequency, in minutes, at which the Exchange server should contact the Web Service endpoint. Frequency must be between 1 and 1440.</param>
/// <param name="watermark">An optional watermark representing a previously opened subscription.</param>
/// <param name="callerData">Optional caller data that will be returned the call back.</param>
/// <param name="eventTypes">The event types to subscribe to.</param>
/// <returns>A PushSubscription representing the new subscription.</returns>
//PushSubscription SubscribeToPushNotificationsOnAllFolders(
// Uri url,
// int frequency,
// string watermark,
// string callerData,
// params EventType[] eventTypes)
// {
// EwsUtilities.ValidateMethodVersion(
// this,
// ExchangeVersion.Exchange2010,
// "SubscribeToPushNotificationsOnAllFolders");
//
// return this.BuildSubscribeToPushNotificationsRequest(
// null,
// url,
// frequency,
// watermark,
// callerData,
// null, // AnchorMailbox
// eventTypes).Execute()[0].Subscription;
// }
/// <summary>
/// Begins an asynchronous request to subscribe to push notifications on all folders in the authenticated user's mailbox. Calling this method results in a call to EWS.
/// </summary>
/// <param name="callback">The AsyncCallback delegate.</param>
/// <param name="state">An object that contains state information for this request.</param>
/// <param name="url"></param>
/// <param name="frequency">The frequency, in minutes, at which the Exchange server should contact the Web Service endpoint. Frequency must be between 1 and 1440.</param>
/// <param name="watermark">An optional watermark representing a previously opened subscription.</param>
/// <param name="callerData">Optional caller data that will be returned the call back.</param>
/// <param name="eventTypes">The event types to subscribe to.</param>
/// <returns>An IAsyncResult that references the asynchronous request.</returns>
//IAsyncResult BeginSubscribeToPushNotificationsOnAllFolders(
// AsyncCallback callback,
// object state,
// Uri url,
// int frequency,
// string watermark,
// string callerData,
// params EventType[] eventTypes)
// {
// EwsUtilities.ValidateMethodVersion(
// this,
// ExchangeVersion.Exchange2010,
// "BeginSubscribeToPushNotificationsOnAllFolders");
//
// return this.BuildSubscribeToPushNotificationsRequest(
// null,
// url,
// frequency,
// watermark,
// callerData,
// null, // AnchorMailbox
// eventTypes).BeginExecute(callback, state);
// }
/// <summary>
/// Ends an asynchronous request to subscribe to push notifications in the authenticated user's mailbox.
/// </summary>
/// <param name="asyncResult">An IAsyncResult that references the asynchronous request.</param>
/// <returns>A PushSubscription representing the new subscription.</returns>
//PushSubscription EndSubscribeToPushNotifications(IAsyncResult asyncResult)
// {
// var request = AsyncRequestResult.ExtractServiceRequest<SubscribeToPushNotificationsRequest>(this, asyncResult);
//
// return request.EndExecute(asyncResult)[0].Subscription;
// }
/// <summary>
/// Ends an asynchronous request to subscribe to push notifications in a group mailbox.
/// </summary>
/// <param name="asyncResult">An IAsyncResult that references the asynchronous request.</param>
/// <returns>A PushSubscription representing the new subscription.</returns>
//PushSubscription EndSubscribeToGroupPushNotifications(IAsyncResult asyncResult)
// {
// var request = AsyncRequestResult.ExtractServiceRequest<SubscribeToPushNotificationsRequest>(this, asyncResult);
//
// return request.EndExecute(asyncResult)[0].Subscription;
// }
/// <summary>
/// Set a TeamMailbox
/// </summary>
/// <param name="emailAddress">TeamMailbox email address</param>
/// <param name="sharePointSiteUrl">SharePoint site URL</param>
/// <param name="state">TeamMailbox lifecycle state</param>
//void SetTeamMailbox(EmailAddress emailAddress, Uri sharePointSiteUrl, TeamMailboxLifecycleState state)
// {
// EwsUtilities.ValidateMethodVersion(this, ExchangeVersion.Exchange2013, "SetTeamMailbox");
//
// if (emailAddress == null)
// {
// throw new ArgumentNullException("emailAddress");
// }
//
// if (sharePointSiteUrl == null)
// {
// throw new ArgumentNullException("sharePointSiteUrl");
// }
//
// SetTeamMailboxRequest request = new SetTeamMailboxRequest(this, emailAddress, sharePointSiteUrl, state);
// request.Execute();
// }
/// <summary>
/// Unpin a TeamMailbox
/// </summary>
/// <param name="emailAddress">TeamMailbox email address</param>
//void UnpinTeamMailbox(EmailAddress emailAddress)
// {
// EwsUtilities.ValidateMethodVersion(this, ExchangeVersion.Exchange2013, "UnpinTeamMailbox");
//
// if (emailAddress == null)
// {
// throw new ArgumentNullException("emailAddress");
// }
//
// UnpinTeamMailboxRequest request = new UnpinTeamMailboxRequest(this, emailAddress);
// request.Execute();
// }
/// <summary>
/// Builds an request to request to subscribe to push notifications in the authenticated user's mailbox.
/// </summary>
/// <param name="folderIds">The Ids of the folder to subscribe to.</param>
/// <param name="url">The URL of the Web Service endpoint the Exchange server should push events to.</param>
/// <param name="frequency">The frequency, in minutes, at which the Exchange server should contact the Web Service endpoint. Frequency must be between 1 and 1440.</param>
/// <param name="watermark">An optional watermark representing a previously opened subscription.</param>
/// <param name="callerData">Optional caller data that will be returned the call back.</param>
/// <param name="anchorMailbox">The smtpaddress of the mailbox to subscribe to.</param>
/// <param name="eventTypes">The event types to subscribe to.</param>
/// <returns>A request to request to subscribe to push notifications in the authenticated user's mailbox.</returns>
//SubscribeToPushNotificationsRequest BuildSubscribeToPushNotificationsRequest(
// Iterable<FolderId> folderIds,
// Uri url,
// int frequency,
// string watermark,
// string callerData,
// string anchorMailbox,
// EventType[] eventTypes)
// {
// EwsUtilities.ValidateParam(url, "url");
//
// if (frequency < 1 || frequency > 1440)
// {
// throw new ArgumentOutOfRangeException("frequency", Strings.FrequencyMustBeBetween1And1440);
// }
//
// EwsUtilities.ValidateParamCollection(eventTypes, "eventTypes");
//
// SubscribeToPushNotificationsRequest request = new SubscribeToPushNotificationsRequest(this);
// request.AnchorMailbox = anchorMailbox;
//
// if (folderIds != null)
// {
// request.FolderIds.AddRange(folderIds);
// }
//
// request.Url = url;
// request.Frequency = frequency;
// request.EventTypes.AddRange(eventTypes);
// request.Watermark = watermark;
// request.CallerData = callerData;
//
// return request;
// }
/// <summary>
/// Subscribes to streaming notifications. Calling this method results in a call to EWS.
/// </summary>
/// <param name="folderIds">The Ids of the folder to subscribe to.</param>
/// <param name="eventTypes">The event types to subscribe to.</param>
/// <returns>A StreamingSubscription representing the new subscription.</returns>
Future<StreamingSubscription> SubscribeToStreamingNotifications(
Iterable<FolderId> folderIds, List<EventType> eventTypes) async {
EwsUtilities.ValidateMethodVersion(this, ExchangeVersion.Exchange2010_SP1,
"SubscribeToStreamingNotifications");
EwsUtilities.ValidateParamCollection(folderIds, "folderIds");
final ServiceResponseCollection<SubscribeResponse<StreamingSubscription>>
response = await this
.BuildSubscribeToStreamingNotificationsRequest(
folderIds, eventTypes)
.Execute();
return response[0].Subscription;
}