private static void DefaultTokenCache_AfterAccess(TokenCacheNotificationArgs args)
 {
     if (DefaultShared.HasStateChanged)
     {
         try
         {
             var localSettings = ApplicationData.Current.LocalSettings;
             localSettings.CreateContainer(LocalSettingsContainerName, ApplicationDataCreateDisposition.Always);
             LocalSettingsHelper.SetCacheValue(localSettings.Containers[LocalSettingsContainerName].Values, DefaultShared.Serialize());
             DefaultShared.HasStateChanged = false;
         }
         catch (Exception ex)
         {
             Logger.Information(null, "Failed to save cache: " + ex);
         }
     }
 }
 private static void DefaultTokenCache_BeforeAccess(TokenCacheNotificationArgs args)
 {
     try
     {
         var localSettings = ApplicationData.Current.LocalSettings;
         localSettings.CreateContainer(LocalSettingsContainerName, ApplicationDataCreateDisposition.Always);
         byte[] state = LocalSettingsHelper.GetCacheValue(localSettings.Containers[LocalSettingsContainerName].Values);
         if (state != null)
         {
             DefaultShared.Deserialize(state);
         }
     }
     catch (Exception ex)
     {
         Logger.Information(null, "Failed to load cache: " + ex);
         // Ignore as the cache seems to be corrupt
     }
 }