private static void InitializeIfNeeded()
 {
     if (!FederationTrustCache.IsInitialized())
     {
         lock (FederationTrustCache.locker)
         {
             if (!FederationTrustCache.IsInitialized())
             {
                 FederationTrustCache.timeout = DateTime.UtcNow + FederationTrustCache.ExpirationTime;
                 try
                 {
                     FederationTrustCache.LoadFederationTrust();
                     FederationTrustCache.SubscribeForNotifications();
                 }
                 catch (LocalizedException arg)
                 {
                     FederationTrustCache.Tracer.TraceError <LocalizedException>(0L, "FederationTrustCache: Unable to initialize due exception: {0}", arg);
                 }
                 if (FederationTrustCache.notification != null)
                 {
                     FederationTrustCache.timeout = DateTime.MaxValue;
                 }
                 FederationTrustCache.initialized = true;
             }
         }
     }
 }
        public static FederationTrust GetFederationTrust(string name)
        {
            FederationTrustCache.InitializeIfNeeded();
            FederationTrust result;

            if (FederationTrustCache.dictionaryByCommonName.TryGetValue(name, out result))
            {
                return(result);
            }
            return(null);
        }
        public static FederationTrust GetFederationTrust(ADObjectId id)
        {
            FederationTrustCache.InitializeIfNeeded();
            FederationTrust result;

            if (FederationTrustCache.dictionaryByADObjectId.TryGetValue(id, out result))
            {
                return(result);
            }
            return(null);
        }
 private static void NotificationHandler(ADNotificationEventArgs args)
 {
     FederationTrustCache.Tracer.TraceDebug(0L, "FederationTrustCache: changes detected in configuration in AD.");
     try
     {
         FederationTrustCache.LoadFederationTrust();
     }
     catch (LocalizedException arg)
     {
         FederationTrustCache.Tracer.TraceError <LocalizedException>(0L, "FederationTrustCache: failed to read federation trust from AD due exception: {0}", arg);
         return;
     }
     if (FederationTrustCache.Change != null)
     {
         FederationTrustCache.Tracer.TraceDebug(0L, "FederationTrustCache: notifying subscribers of change.");
         FederationTrustCache.Change();
     }
 }
 internal static void Initialize()
 {
     FederationTrustCache.LoadFederationTrust();
 }
 public static IEnumerable <FederationTrust> GetFederationTrusts()
 {
     FederationTrustCache.InitializeIfNeeded();
     return(new List <FederationTrust>(FederationTrustCache.dictionaryByADObjectId.Values));
 }