Is it possible to have different IsolStorageSettings.ApplicationSettings settings?

I have a problem with the fact that the changes I make with my applications are not updated in my ApplicationSettings settings for AudioPlayerAgents, which should be the same ?!

My program looks like this:

In my MainPage.xaml.cs in OnNavigatedTo I create two arrays of audio files

Audio[] aud = new Audio[2]; Audio[] aud1 = new Audio[2]; aud[0] = new Audio(new Uri("1.mp3", UriKind.Relative), "Test1", "Test1", new Uri("Images/Covers/0000000018724345_256x256_large.jpg", UriKind.Relative)); aud[1] = new Audio(new Uri("2.mp3", UriKind.Relative), "Test2", "Test2", new Uri("Images/Covers/0000000018698018_256x256_large.jpg", UriKind.Relative)); aud1[0] = new Audio(new Uri("3.mp3", UriKind.Relative), "Test3", "Test3", new Uri("Images/Covers/0000000018465020_256x256_large.jpg", UriKind.Relative)); aud1[1] = new Audio(new Uri("http://traffic.libsyn.com/wpradio/WPRadio_29.mp3", UriKind.Absolute), "Episode 29", "Windows Phone Radio", new Uri("Images/Covers/0000000018844939_256x256_large.jpg", UriKind.Relative)); 

Then I save one of these arrays in ApplicationSettings

 IsolatedStorageSettings.ApplicationSettings["tracklist"] = aud; IsolatedStorageSettings.ApplicationSettings.Save(); 

Then I close and run BackgroundAudioPlayer.

 BackgroundAudioPlayer.Instance.Close(); BackgroundAudioPlayer.Instance.Play(); 

In my AudioPlayer, I load previously saved ApplicationSettings that work fine.

 Audio[] aud; IsolatedStorageSettings.ApplicationSettings.TryGetValue<Audio[]>("tracklist", out aud); 

But when I later want to replace ApplicationSettings in my MainPage.xaml.cs with another array

  IsolatedStorageSettings.ApplicationSettings["tracklist"] = aud1; IsolatedStorageSettings.ApplicationSettings.Save(); 

And load the values ​​again in my AudioPlayer, are there still old values ​​in my ApplicationSettings, and should AudioPlayerAgent and MainPage use the same ApplicationSettings permissions? In fact, the first time it is saved and available for AudioPlayerAgent, so what am I missing?

My Audio class is as follows

 [DataContractAttribute] public class Audio { [DataMember] public Uri TrackUrl { get; set; } [DataMember] public string Title { get; set; } [DataMember] public string Artist { get; set; } [DataMember] public Uri CoverURL { get; set; } public Audio(Uri trackUrl, string title, string artist, Uri coverUrl) { TrackUrl = trackUrl; Title = title; Artist = artist; CoverURL = coverUrl; } } 
+4
source share
3 answers

I have the feeling that you have MusicPlayerAgent in a different assembly / dll. If you do this, this will explain the problem, since each assembly has its own isolated storage. If they are in the same assembly, I don’t know why this will not work, since I do it myself in almost all of my phones that I have. Here is the best read on isolated storage that I read. If anything, I hope the link reads well. Link

+1
source

I ran into the same problem. It seems to me that IsolatedStorageSettings are "cached" into something static. That is, until both background and foreground processes are executed, each of them will use its own version of IsolStorageSettings. Getting into the source code, I found the following:

 public sealed class IsolatedStorageSettings : ... { private static IsolatedStorageSettings s_appSettings; ... public static IsolatedStorageSettings ApplicationSettings { get { if (IsolatedStorageSettings.s_appSettings == null) { IsolatedStorageSettings.s_appSettings = new IsolatedStorageSettings(false); } return IsolatedStorageSettings.s_appSettings; } } ... private IsolatedStorageSettings(bool useSiteSettings) { if (useSiteSettings) { throw new NotSupportedException(); } this._appStore = IsolatedStorageFile.GetUserStoreForApplication(); this.Reload(); } 

Here you can see that IsolatedStorageSettings are loaded only once per process (as a static variable) in the Reload method. Looking through the code, I did not find other places where Reload is called.

I can offer everyone who faces the same problem to use their own storage settings for exchanging dynamic data between AudioAgent and the App (as Filiéippe said in his last comment )

From what I know, it is best to use the AudioTrack.Tag property.

+1
source

I do not understand how IsolStorage was chained to work on the phone. The same namespace in PC applications has an explicit Scope property, so you can at least determine if there are separate parent folders.

If you cannot merge two projects into one, just uploading all the files from one to the other, at least you could add a class or method to one of the projects that loads the class from IsolStorage and returns an instance, then call it from another project. adding a link (in the Links folder in Solution Explorer) to the first project in the second so that you can call it.

0
source

Source: https://habr.com/ru/post/1380795/


All Articles