Virtu/Virtu/Services/StorageService.cs
Sean Fausett 365e5723c1 Deleted all svn:eol-style properties on files.
--HG--
extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4050811
2010-08-28 11:34:14 +00:00

39 lines
1.4 KiB
C#

using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using Jellyfish.Virtu.Properties;
namespace Jellyfish.Virtu.Services
{
public abstract class StorageService : MachineService
{
protected StorageService(Machine machine) :
base(machine)
{
}
[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
public static Stream GetResourceStream(string resourceName, int resourceSize = 0)
{
var resourceManager = new ResourceManager("Jellyfish.Virtu.g", Assembly.GetExecutingAssembly()) { IgnoreCase = true };
var resourceStream = (Stream)resourceManager.GetObject(resourceName);
if (resourceStream == null)
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings.ResourceNotFound, resourceName));
}
if ((resourceSize > 0) && (resourceStream.Length != resourceSize))
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings.ResourceInvalid, resourceName));
}
return resourceStream;
}
public abstract void Load(string path, Action<Stream> reader);
public abstract void Save(string path, Action<Stream> writer);
}
}