TheLolFx Extended Splash

TheLolFx release 1.3. I’ve updated TheLolFx to allow for unlimited local sound storage and along with that gained increased performance.

Previously I had been saving a json list of sounds that were available locally in a settings key which limited the number of local sounds to nine or ten before an untrapped exception would occur when I exceeded the maximum size of that key. I saved this list (actually an ObservableCollection) each time the collection changed – not a great design.

Note: I’ve used three different code snippet plugins for Windows Live writer. Which do you prefer?

Code Snippet
  1. ApplicationData.Current.LocalSettings.Values[“LocalSounds”] = _utility.Serialize(ExtendedLocalSounds);

In release 1.3 I’ve modified the behavior of TheLolFx to save ExtendedLocalSounds to a .json file in the local folder and only on suspending rather than each time the collection changed. Confession: I hurried the first release of TheLolFx to the store so I could qualify for a Samsung tablet – which I did! Thank you ThirtyToLaunch and @UserCommunity.

I added an ExtendedSplash screen, converting the settings key data to a .json file and removing the old settings key. I used some of what I’ve been learning from @Pete_Brown in his: “Windows 8 XAML in Action” book. Check it out. I like the way he introduces a subject with a simple example then refactors it towards a more real world example.

   1: private async void OnSplashScreenDismissed(SplashScreen sender, object args)

   2: {

   3:     // if the LocalSounds key exists then upgrade TheLolFx. 

   4:     // Convert from settings key to file storage to persist Local sounds that have been downloaded.

   5:     var localSettings = ApplicationData.Current.LocalSettings;

   6:     if (localSettings.Values.ContainsKey("LocalSounds"))

   7:     {

   8:         var localSounds = _utility.Deserialize<ObservableCollection<ExtendedSfx>>(Convert.ToString(ApplicationData.Current.LocalSettings.Values["LocalSounds"]));

   9:         var localFolder = ApplicationData.Current.LocalFolder;

  10:         var localSoundsFile = await localFolder.CreateFileAsync(Utility.JsonFileName, CreationCollisionOption.ReplaceExisting);

  11:         await FileIO.WriteTextAsync(localSoundsFile, _utility.Serialize(localSounds));

  12:         localSettings.Values.Remove("LocalSounds");

  13:     }

  14: // ...

  15: }

I persist the ExtendedLocalSounds to local storage in the App suspending event.

        private async void OnSuspending(object sender, SuspendingEventArgs e)
            var deferral = e.SuspendingOperation.GetDeferral();
            Debug.WriteLine(string.Format("{0} remaining", e.SuspendingOperation.Deadline - DateTime.Now));
            await AppHubViewModel.PersistLocalSoundsToJson(); 
            Debug.WriteLine(string.Format("{0} remaining after .json save", e.SuspendingOperation.Deadline - DateTime.Now));
Code Snippet
  1. publicstaticasyncTask PersistLocalSoundsToJson()
  2.     {
  3.         var lf = Windows.Storage.ApplicationData.Current.LocalFolder;
  4.         var localSoundsFile = await lf.CreateFileAsync(Utility.JsonFileName, CreationCollisionOption.ReplaceExisting);
  5.         awaitFileIO.WriteTextAsync(localSoundsFile, _utility.Serialize(_extendedLocalSounds));
  6.     }

This upgrade has me thinking about versioning my web api json data in the future. Got a good link to a discussion on that topic? Leave it in a comment please.

I also learned about ApplicationData.Version although I haven’t implemented as I’m not currently using ApplicationData other than the .json file.

Changes to web site.

Modified the Create (Upload) new sound capability to require authentication and require at least three characters in the sound name and description as well as automatically adding the account name of the upload and the time. Entity Framework Code first and migrations are pretty fun to code with for me.

I also added windows store meta data so that when using IE in the modern UI the ‘Get app for this site’ link in the page tools is available. Thanks @IrisClasson for that tip.

I note that my star rating plugin in not working correctly. I better get back to work… c ya… jeffa aka @jhalbrecht

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.