Esempio n. 1
0
 public static Playlist LoadTracksFromIsolatedStorage(bool allowCached = false)
 {
     Logger.Instance.Info("PlaylistManager.LoadTracksFromIsolatedStorage, allowCached = {0}", allowCached);
     lock (PlaylistManager._lockObj)
     {
         try
         {
             if (allowCached && PlaylistManager._playlistCached != null)
             {
                 Logger.Instance.Info("PlaylistManager.LoadTracksFromIsolatedStorage: returning data from 1st level cache");
                 return(PlaylistManager._playlistCached);
             }
             Logger.Instance.Info("PlaylistManager.LoadTracksFromIsolatedStorage: _playlistCached is not null? = {0}" + (PlaylistManager._playlistCached != null).ToString());
             if (PlaylistManager._playlistCached != null)
             {
                 Logger.Instance.Info("PlaylistManager.LoadTracksFromIsolatedStorage: _playlistCached.Metadata.LastUpdated = {0}", PlaylistManager._playlistCached.Metadata.LastUpdated);
                 DateTime lastChangedDate = PlaylistManager.GetLastChangedDate(PlaylistManager.PlaylistMetadataFileName);
                 Logger.Instance.Info("PlaylistManager.LoadTracksFromIsolatedStorage: Storemetadata.LastUpdated = {0}", lastChangedDate);
                 if (PlaylistManager._playlistCached.Metadata.LastUpdated == lastChangedDate)
                 {
                     Logger.Instance.Info("PlaylistManager.LoadTracksFromIsolatedStorage: returning data from 2nd level cache");
                     return(PlaylistManager._playlistCached);
                 }
             }
             using (IsolatedStorageFile storeForApplication = IsolatedStorageFile.GetUserStoreForApplication())
             {
                 try
                 {
                     PlaylistManager.playlistAccessMutex.WaitOne();
                     if (!storeForApplication.FileExists(PlaylistManager.PlaylistFileName))
                     {
                         return(new Playlist());
                     }
                     IsolatedStorageFileStream storageFileStream = storeForApplication.OpenFile(PlaylistManager.PlaylistFileName, FileMode.Open, FileAccess.Read);
                     if (storageFileStream == null)
                     {
                         return(new Playlist());
                     }
                     using (BinaryReader reader = new BinaryReader((Stream)storageFileStream))
                         return(PlaylistManager._playlistCached = reader.ReadGeneric <Playlist>());
                 }
                 finally
                 {
                     PlaylistManager.playlistAccessMutex.ReleaseMutex();
                 }
             }
         }
         catch (Exception ex)
         {
             Logger.Instance.Error("Failed to read playlist", ex);
         }
         return(new Playlist());
     }
 }
Esempio n. 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);
     }
 }
Esempio n. 3
0
 public static void SetAudioAgentPlaylist(List <AudioObj> tracks, StatisticsActionSource actionSource)
 {
     PlaylistManager.SetAudioAgentPlaylistImpl(tracks, actionSource);
 }