Beispiel #1
0
 public static void WritePlaybackSettings(PlaybackSettings settings)
 {
     settings.Metadata = new Metadata()
     {
         LastUpdated = DateTime.Now
     };
     lock (PlaylistManager._lockObj)
     {
         try
         {
             using (IsolatedStorageFile storeForApplication = IsolatedStorageFile.GetUserStoreForApplication())
             {
                 PlaylistManager.metadataAccessMutex.WaitOne();
                 using (BinaryWriter writer = new BinaryWriter((Stream)storeForApplication.CreateFile(PlaylistManager.SettingsMetadataFileName)))
                     writer.Write <Metadata>(settings.Metadata, false);
                 PlaylistManager.metadataAccessMutex.ReleaseMutex();
                 PlaylistManager.settingsAccessMutex.WaitOne();
                 using (BinaryWriter writer = new BinaryWriter((Stream)storeForApplication.CreateFile(PlaylistManager.PlaybackSettingsFileName)))
                     writer.Write <PlaybackSettings>(settings, false);
                 PlaylistManager.settingsAccessMutex.ReleaseMutex();
                 PlaylistManager._settingsCached = settings;
             }
         }
         catch (Exception ex)
         {
             Logger.Instance.Error("WritePlaybackSettings failed", ex);
         }
     }
 }
Beispiel #2
0
 public static PlaybackSettings ReadPlaybackSettings(bool allowCached = false)
 {
     lock (PlaylistManager._lockObj)
     {
         if (allowCached && PlaylistManager._settingsCached != null)
         {
             return(PlaylistManager._settingsCached);
         }
         PlaybackSettings playbackSettings = new PlaybackSettings();
         try
         {
             if (PlaylistManager._settingsCached != null && PlaylistManager._settingsCached.Metadata.LastUpdated == PlaylistManager.GetLastChangedDate(PlaylistManager.SettingsMetadataFileName))
             {
                 return(PlaylistManager._settingsCached);
             }
             using (IsolatedStorageFile storeForApplication = IsolatedStorageFile.GetUserStoreForApplication())
             {
                 PlaylistManager.settingsAccessMutex.WaitOne();
                 if (storeForApplication.FileExists(PlaylistManager.PlaybackSettingsFileName))
                 {
                     IsolatedStorageFileStream storageFileStream = storeForApplication.OpenFile(PlaylistManager.PlaybackSettingsFileName, FileMode.Open, FileAccess.Read);
                     if (storageFileStream != null)
                     {
                         using (BinaryReader reader = new BinaryReader((Stream)storageFileStream))
                             playbackSettings = reader.ReadGeneric <PlaybackSettings>();
                         PlaylistManager._settingsCached = playbackSettings;
                     }
                 }
                 PlaylistManager.settingsAccessMutex.ReleaseMutex();
             }
         }
         catch (Exception ex)
         {
             Logger.Instance.Error("ReadPlaybackSettings failed", ex);
         }
         return(playbackSettings);
     }
 }