Serialize XML data (incremental storage) in Windows 8

advertisements

How to serialize XMl data in Windows8.For Metro the methos are asynchronous. For saving an action can be passed that will be called once the save operation is complete. When loading data you'll want to pass an action that will received the loaded data and an exception parameter that will be populated if the data could not be loaded. How is it possible.

Below is the code for serializing in wp7.. how is it poessible in windows 8??

private void SaveProfileData(Profiles profileData)
    {
        XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
        xmlWriterSettings.Indent = true;
        ProfileList = ReadProfileList();
        using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
        {
            using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("profile.xml", FileMode.Create))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(List<Profiles>));
                using (XmlWriter xmlWriter = XmlWriter.Create(stream, xmlWriterSettings))
                {
                    serializer.Serialize(xmlWriter, GenerateProfileData(profileData));
                }
            }
        }
    }


I build a Sudoku app and i have the same problem. I try to Change the code from wp7 to win 8 in visual studio 2012 but my app didn't work yet. Perhaps my code can be help you.

public void SaveToDisk()
        {
             if (Windows.Storage.ApplicationData.Current.LocalSettings.Values.ContainsKey(key))
                {
                    if (Windows.Storage.ApplicationData.Current.LocalSettings.Values[key].ToString() != null)
                    {
                        //do update
                        Windows.Storage.ApplicationData.Current.LocalSettings.Values[key] = value;
                    }
                }
             else
                {   // do create key and save value, first time only.

                    Windows.Storage.ApplicationData.Current.LocalSettings.CreateContainer(key, ApplicationDataCreateDisposition.Always);
                    if (Windows.Storage.ApplicationData.Current.LocalSettings.Values[key] == null)
                    {
                        Windows.Storage.ApplicationData.Current.LocalSettings.Values[key] = value;
                    }

                 using (StreamWriter writer = new StreamWriter(stream))
                    {
                        List<SquareViewModel> s = new List<SquareViewModel>();
                        foreach (SquareViewModel item in GameArray)
                            s.Add(item);

                        XmlSerializer serializer = new XmlSerializer(s.GetType());
                        serializer.Serialize(writer, s);
                    }
                 }                

        }