/// <summary> /// Issues the notification events. /// </summary> /// <param name="gseResponse">The GetStreamingEvents response.</param> private void IssueNotificationEvents(GetStreamingEventsResponse gseResponse) { foreach (GetStreamingEventsResults.NotificationGroup events in gseResponse.Results.Notifications) { StreamingSubscription subscription = null; lock (this.lockObject) { // Client can do any good or bad things in the below event handler if (this.subscriptions != null && this.subscriptions.ContainsKey(events.SubscriptionId)) { subscription = this.subscriptions[events.SubscriptionId]; } } if (subscription != null) { NotificationEventArgs eventArgs = new NotificationEventArgs( subscription, events.Events); if (this.OnNotificationEvent != null) { this.OnNotificationEvent(this, eventArgs); } } } }
/// <summary> /// Initializes a new instance of the <see cref="NotificationEventArgs"/> class. /// </summary> /// <param name="subscription">The subscription for which notifications have been received.</param> /// <param name="events">The events that were received.</param> internal NotificationEventArgs( StreamingSubscription subscription, IEnumerable<NotificationEvent> events) { this.Subscription = subscription; this.Events = events; }
/// <summary> /// Initializes a new instance of the <see cref="NotificationEventArgs"/> class. /// </summary> /// <param name="subscription">The subscription for which notifications have been received.</param> /// <param name="events">The events that were received.</param> internal NotificationEventArgs( StreamingSubscription subscription, IEnumerable <NotificationEvent> events) { this.Subscription = subscription; this.Events = events; }
/// <summary> /// Initializes a new instance of the <see cref="SubscriptionErrorEventArgs"/> class. /// </summary> /// <param name="subscription">The subscription for which an error occurred. If subscription is null, the error applies to the entire connection.</param> /// <param name="exception">The exception representing the error. If exception is null, the connection was cleanly closed by the server.</param> internal SubscriptionErrorEventArgs( StreamingSubscription subscription, Exception exception) { this.Subscription = subscription; this.Exception = exception; }
/// <summary> /// Removes the specified streaming subscription from the connection. /// </summary> /// <param name="subscription">The subscription to remove.</param> /// <exception cref="InvalidOperationException">Thrown when RemoveSubscription is called while connected.</exception> public void RemoveSubscription(StreamingSubscription subscription) { this.ThrowIfDisposed(); EwsUtilities.ValidateParam(subscription, "subscription"); this.ValidateConnectionState(false, Strings.CannotRemoveSubscriptionFromLiveConnection); lock (this.lockObject) { this.subscriptions.Remove(subscription.Id); } }
/// <summary> /// Adds a subscription to this connection. /// </summary> /// <param name="subscription">The subscription to add.</param> /// <exception cref="InvalidOperationException">Thrown when AddSubscription is called while connected.</exception> public void AddSubscription(StreamingSubscription subscription) { this.ThrowIfDisposed(); EwsUtilities.ValidateParam(subscription, "subscription"); this.ValidateConnectionState(false, Strings.CannotAddSubscriptionToLiveConnection); lock (this.lockObject) { if (this.subscriptions.ContainsKey(subscription.Id)) { return; } this.subscriptions.Add(subscription.Id, subscription); } }
/// <summary> /// Issues the subscription failures. /// </summary> /// <param name="gseResponse">The GetStreamingEvents response.</param> private void IssueSubscriptionFailures(GetStreamingEventsResponse gseResponse) { ServiceResponseException exception = new ServiceResponseException(gseResponse); foreach (string id in gseResponse.ErrorSubscriptionIds) { StreamingSubscription subscription = null; lock (this.lockObject) { // Client can do any good or bad things in the below event handler if (this.subscriptions != null && this.subscriptions.ContainsKey(id)) { subscription = this.subscriptions[id]; } } if (subscription != null) { SubscriptionErrorEventArgs eventArgs = new SubscriptionErrorEventArgs( subscription, exception); if (this.OnSubscriptionError != null) { this.OnSubscriptionError(this, eventArgs); } } if (gseResponse.ErrorCode != ServiceError.ErrorMissedNotificationEvents) { // Client can do any good or bad things in the above event handler lock (this.lockObject) { if (this.subscriptions != null && this.subscriptions.ContainsKey(id)) { // We are no longer servicing the subscription. this.subscriptions.Remove(id); } } } } }