Local Database

redbullqwe

New member
Apr 5, 2013
1
0
0
Hi,

I'm fairly new to windows phone programming.

I need to store data on the phone when the app closes, and load the data when the app starts.

Specificly BitmapImages, dictionaries of all types and simple integers, bool etc.

At the moment i have implemented a different method for every different type of data, that converts the dictionary to json, and then saves it as a .json file on the phone.

BitmapImages are of course not converted to json, they are saved in the way described in the WP documentary.

This technique is very painful, because every time I need to save data thats of a new type, i have to implement a method for that first.

Now my question, do you know any way to accomplish this task, thats more robust and flexible than mine?

I found an article about a local database on WP here and I'm now experimenting a bit with that, but I'm not sure if it can really do what I want.

I would really appreciate any help, because I have been stuck with this task a long time now ;)
 
Personally I make my custom classes serializable with [DataContract] keywords and save them using IsolatedStorageSettings. It seemed much easier to me than a local actual database. Example from my cPlayer application:

Code:
    [DataContract]
    [KnownType(typeof(RootItem))]
    [KnownType(typeof(MediaServerItem))]
    [KnownType(typeof(FolderItem))]
    [KnownType(typeof(MovieItem))]
    [KnownType(typeof(SubtitlesItem))]
    [KnownType(typeof(UnknownFileItem))]
    public abstract class FileSystemItem : INotifyPropertyChanged
    {
        [DataMember]
        public string _icon;
        [DataMember]
        public string _iconpath = "Resources/Icons/";
        [DataMember]
        public string guid = "";
        [DataMember]
        public string _title;
        [DataMember]
        public string _titlelower;
        [DataMember]
        public string _parentid;
        [DataMember]
        public string _id;
        [DataMember]
        public string _type;
        [DataMember]
        public string _actionurl;
        [DataMember]
        public bool _showcheckbox = false;
        [DataMember]
        public bool _selected = false;
        [DataMember]
        public string _information;
        [DataMember]
        public DateTime _lastplayed;
        [DataMember]
        public int _filesize;
        [DataMember]
        public List<SubtitlesItem> Subs { get; set; }

        //below are methods, they don't need to be seralized

    }

Instances of the above class are saved in IsolatedStorageSettings. RootItem, MediaServerItem, FolderItem, MovieItem, SubtitlesItem, UnknownFileItem are subclasses of FileSystemItem.
 

Members online

Forum statistics

Threads
339,125
Messages
2,262,150
Members
428,748
Latest member
old codger