public void RegisterSample(uint heartbeatInterval, INotificationManagerContext context)
 {
     if (context.DeviceIdentity.DeviceType.StartsWith("TestActiveSyncConnectivity"))
     {
         return;
     }
     lock (this.hbiSamples)
     {
         uint num = this.hbiSamples[this.insertionIndex];
         this.hbiSamples[this.insertionIndex] = heartbeatInterval;
         this.insertionIndex = (this.insertionIndex + 1) % this.hbiSamples.Length;
         this.hbiSum        += heartbeatInterval;
         this.hbiSum        -= num;
         if ((ulong)this.numSamples == (ulong)((long)this.hbiSamples.Length))
         {
             uint num2 = this.hbiSum / this.numSamples;
             if ((ulong)num2 <= (ulong)((long)this.heartbeatAlertThreshold))
             {
                 string text = context.CommandType.ToString();
                 AirSyncDiagnostics.LogPeriodicEvent(AirSyncEventLogConstants.Tuple_AverageHbiTooLow, text, new string[]
                 {
                     num2.ToString(CultureInfo.InvariantCulture),
                     text,
                     this.heartbeatAlertThreshold.ToString(CultureInfo.InvariantCulture)
                 });
             }
         }
         else
         {
             this.numSamples += 1U;
         }
     }
 }
        public static NotificationManager CreateNotificationManager(INotificationManagerContext context, IAsyncCommand command)
        {
            string text = NotificationManager.GetUniqueId(context);
            uint   num  = context.PolicyKey;
            int    mailboxPolicyHash = context.MailboxPolicyHash;
            NotificationManager notificationManager = new NotificationManager(command, text, mailboxPolicyHash, num);
            NotificationManager notificationManager2;

            lock (NotificationManager.notificationManagerCache)
            {
                if (NotificationManager.notificationManagerCache.TryGetValue(text, out notificationManager2))
                {
                    NotificationManager.cacheContentionsPerMinute.Add(1U);
                    notificationManager2.EnqueueDiagOperation(NotificationManager.DiagnosticEvent.Removed);
                    NotificationManager.notificationManagerCache.Remove(text);
                    NotificationManager.removedInstances[text] = notificationManager2;
                }
                NotificationManager.createsPerMinute.Add(1U);
                notificationManager.EnqueueDiagOperation(NotificationManager.DiagnosticEvent.Cached);
                NotificationManager.notificationManagerCache.Add(text, notificationManager);
                AirSyncCounters.NumberOfNotificationManagerInCache.RawValue = (long)NotificationManager.notificationManagerCache.Count;
            }
            if (notificationManager2 != null)
            {
                AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.ThreadingTracer, notificationManager, "Disposing existing NotificationManager for {0}", text);
                notificationManager2.EnqueueEvent(new NotificationManager.AsyncEvent(NotificationManager.AsyncEventType.Acquire, null));
                notificationManager2.EnqueueDispose();
            }
            AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.ThreadingTracer, notificationManager, "Created notification manager for {0}", text);
            return(notificationManager);
        }
 private static string GetUniqueId(INotificationManagerContext context)
 {
     return(string.Format(CultureInfo.InvariantCulture, "{0}:{1}:{2}", new object[]
     {
         context.MailboxGuid.ToString(),
         context.DeviceIdentity,
         context.CommandType.ToString()
     }));
 }
        public static NotificationManager GetOrCreateNotificationManager(INotificationManagerContext context, IAsyncCommand command, out bool wasTakenOver)
        {
            string text = NotificationManager.GetUniqueId(context);
            uint   num  = context.PolicyKey;
            int    mailboxPolicyHash = context.MailboxPolicyHash;

            wasTakenOver = false;
            NotificationManager notificationManager  = null;
            NotificationManager notificationManager2 = null;

            lock (NotificationManager.notificationManagerCache)
            {
                bool flag2 = NotificationManager.notificationManagerCache.TryGetValue(text, out notificationManager2);
                if (flag2)
                {
                    NotificationManager.hitsPerMinute.Add(1U);
                }
                if (flag2 && notificationManager2.subscriptionCanBeTaken && !notificationManager2.MailboxLoggingEnabled && mailboxPolicyHash == notificationManager2.policyHashCode && num == notificationManager2.policyKey)
                {
                    wasTakenOver = true;
                }
                else
                {
                    if (flag2)
                    {
                        NotificationManager.cacheContentionsPerMinute.Add(1U);
                        notificationManager2.EnqueueDiagOperation(NotificationManager.DiagnosticEvent.Removed);
                        NotificationManager.notificationManagerCache.Remove(text);
                        NotificationManager.removedInstances[text] = notificationManager2;
                        notificationManager = notificationManager2;
                    }
                    notificationManager2 = new NotificationManager(command, text, mailboxPolicyHash, num);
                    NotificationManager.createsPerMinute.Add(1U);
                    notificationManager2.EnqueueDiagOperation(NotificationManager.DiagnosticEvent.Cached);
                    NotificationManager.notificationManagerCache.Add(text, notificationManager2);
                    AirSyncCounters.NumberOfNotificationManagerInCache.RawValue = (long)NotificationManager.notificationManagerCache.Count;
                }
            }
            if (notificationManager != null)
            {
                AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.ThreadingTracer, notificationManager2, "Disposing existing NotificationManager for {0}", text);
                notificationManager.EnqueueEvent(new NotificationManager.AsyncEvent(NotificationManager.AsyncEventType.Acquire, null));
                notificationManager.EnqueueDispose();
                notificationManager = null;
            }
            if (wasTakenOver)
            {
                NotificationManager.AsyncEvent evt = new NotificationManager.AsyncEvent(NotificationManager.AsyncEventType.Acquire, command);
                if (!notificationManager2.EnqueueEvent(evt))
                {
                    AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.ThreadingTracer, notificationManager2, "A NotificationManager was attempted to be taken over but failed for {0}", text);
                    wasTakenOver         = false;
                    notificationManager2 = NotificationManager.CreateNotificationManager(context, command);
                }
                else
                {
                    notificationManager2.EnqueueDiagOperation(NotificationManager.DiagnosticEvent.Stolen);
                    NotificationManager.stealsPerMinute.Add(1U);
                }
            }
            AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.ThreadingTracer, notificationManager2, "Got or created notification manager for {0}", text);
            return(notificationManager2);
        }