Virtu/Virtu/Wpf/Services/WpfStorageService.cs
Sean Fausett 7b713e6aaa Cosmetic changes.
Set svn properties on files.

--HG--
extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4044493
2010-04-04 00:12:01 +00:00

69 lines
1.9 KiB
C#

using System;
using System.Deployment.Application;
using System.IO;
using System.IO.IsolatedStorage;
namespace Jellyfish.Virtu.Services
{
public sealed class WpfStorageService : StorageService
{
public WpfStorageService(Machine machine) :
base(machine)
{
}
public override void Load(string path, Action<Stream> reader)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
}
try
{
using (var store = GetStore())
{
using (var stream = new IsolatedStorageFileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, store))
{
reader(stream);
}
}
}
catch (FileNotFoundException)
{
}
catch (IsolatedStorageException)
{
}
}
public override void Save(string path, Action<Stream> writer)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
}
try
{
using (var store = GetStore())
{
using (var stream = new IsolatedStorageFileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, store))
{
writer(stream);
}
}
}
catch (IsolatedStorageException)
{
}
}
private static IsolatedStorageFile GetStore()
{
return ApplicationDeployment.IsNetworkDeployed ? // clickonce
IsolatedStorageFile.GetUserStoreForApplication() : IsolatedStorageFile.GetUserStoreForAssembly();
}
}
}