// Token: 0x06001BD6 RID: 7126 RVA: 0x0006BC30 File Offset: 0x00069E30
        private List <SubscriptionResponseData> InternalSubscribe(IMailboxContext userContext)
        {
            List <SubscriptionResponseData> list = new List <SubscriptionResponseData>();

            SubscriptionData[] array = this.subscriptionData;
            for (int i = 0; i < array.Length; i++)
            {
                SubscriptionData subscription   = array[i];
                string           subscriptionId = subscription.SubscriptionId;
                try
                {
                    Stopwatch notificationLatency     = Stopwatch.StartNew();
                    SubscriptionResponseData response = new SubscriptionResponseData(subscriptionId, true);
                    OwaDiagnostics.SendWatsonReportsForGrayExceptions(delegate()
                    {
                        if (subscription.Parameters == null)
                        {
                            throw new ArgumentNullException("Subscription data parameters cannot be null");
                        }
                        ExTraceGlobals.NotificationsCallTracer.TraceDebug(0L, string.Format("[SubscribeToNotificationBase.InternalCreateASubscription] Creating subscription of type {0}.", subscription.Parameters.NotificationType));
                        this.metricType             = SubscribeToNotificationMetadata.Other;
                        NameValueCollection headers = this.CallContext.HttpContext.Request.Headers;
                        bool flag = RemoteRequestProcessor.IsRemoteRequest(headers);
                        if (flag && string.IsNullOrWhiteSpace(subscription.Parameters.ChannelId))
                        {
                            throw new OwaInvalidRequestException("ChannelId is null or empty. ChannelId is required for remote notification subscribe requests.");
                        }
                        this.InternalCreateASubscription(userContext, subscription, flag);
                        if (flag)
                        {
                            bool subscriptionExists;
                            RemoteNotificationManager.Instance.Subscribe(userContext.Key.ToString(), userContext.ExchangePrincipal.MailboxInfo.MailboxGuid.ToString(), subscription.SubscriptionId, subscription.Parameters.ChannelId, RemoteRequestProcessor.GetRequesterUserId(headers), subscription.Parameters.NotificationType, headers["X-OWA-Test-RemoteNotificationEndPoint"], out subscriptionExists);
                            response.SubscriptionExists = subscriptionExists;
                        }
                        if (!this.latenciesPerNotificationType.ContainsKey(this.metricType))
                        {
                            this.latenciesPerNotificationType.Add(this.metricType, 0);
                        }
                        Dictionary <SubscribeToNotificationMetadata, int> dictionary;
                        SubscribeToNotificationMetadata key;
                        (dictionary = this.latenciesPerNotificationType)[key = this.metricType] = dictionary[key] + (int)notificationLatency.ElapsedMilliseconds;
                    });
                    list.Add(response);
                }
                catch (GrayException ex)
                {
                    ExTraceGlobals.NotificationsCallTracer.TraceError <NotificationType, string, string>((long)this.GetHashCode(), "[SubscribeToNotificationBase.InternalSubscribe]: Exception thrown while creating subscription of type [{0}] with id {1}. Error: {2}", subscription.Parameters.NotificationType, subscriptionId, ex.ToString());
                    OwaServerTraceLogger.AppendToLog(new TraceLogEvent("SubErr", userContext, "SubscribeToNotificationBase.InternalSubscribe", ex.ToString()));
                    list.Add(new SubscriptionResponseData(subscriptionId, false)
                    {
                        ErrorInfo = ((ex.InnerException != null) ? ex.InnerException.Message : ex.Message)
                    });
                }
            }
            foreach (KeyValuePair <SubscribeToNotificationMetadata, int> keyValuePair in this.latenciesPerNotificationType)
            {
                base.CallContext.ProtocolLog.Set(keyValuePair.Key, keyValuePair.Value);
            }
            return(list);
        }
Exemple #2
0
        // Token: 0x06001BEA RID: 7146 RVA: 0x0006C5F4 File Offset: 0x0006A7F4
        protected override bool InternalExecute()
        {
            IMailboxContext mailboxContext = UserContextManager.GetMailboxContext(CallContext.Current.HttpContext, CallContext.Current.EffectiveCaller, false);

            if (mailboxContext.NotificationManager == null)
            {
                throw new OwaInvalidOperationException("UserContext.NotificationManager is null");
            }
            for (int i = 0; i < this.subscriptionData.Length; i++)
            {
                SubscriptionData subscriptionData = this.subscriptionData[i];
                bool             flag             = RemoteRequestProcessor.IsRemoteRequest(base.CallContext.HttpContext.Request.Headers);
                if (flag && string.IsNullOrWhiteSpace(subscriptionData.Parameters.ChannelId))
                {
                    throw new OwaInvalidRequestException("ChannelId is null or empty. ChannelId is required for remote notification unsubscribe requests.");
                }
                this.InternalUnsubscribeNotification(mailboxContext, subscriptionData);
                if (flag)
                {
                    RemoteNotificationManager.Instance.UnSubscribe(mailboxContext.Key.ToString(), subscriptionData.SubscriptionId, subscriptionData.Parameters.ChannelId, RemoteRequestProcessor.GetRequesterUserId(base.CallContext.HttpContext.Request.Headers));
                }
            }
            return(true);
        }