Building a Windows 8 Metro App, Part 3: Listing 3
The RestoreAsync method in LocalStorage
static async private Task RestoreAsync()
{
StorageFile sessionFile = await
ApplicationData.Current.LocalFolder.CreateFileAsync(filename,
CreationCollisionOption.OpenIfExists);
if (sessionFile == null)
{
return;
}
IInputStream sessionInputStream = await sessionFile.OpenForReadAsync();
DataContractSerializer sessionSerializer = new
DataContractSerializer(typeof(Dictionary<string, object>));
_data = (Dictionary<string, object>)sessionSerializer.ReadObject(sessionInputStream.AsStream());
}
About the Author
Eric Vogel is a Senior Software Developer for Red Cedar Solutions Group in Okemos, Michigan. He is the president of the Greater Lansing User Group for .NET. Eric enjoys learning about software architecture and craftsmanship, and is always looking for ways to create more robust and testable applications. Contact him at [email protected].