// Copyright (C) Stichting Deltares 2019. All rights reserved.
//
// This file is part of the Dam Engine.
//
// The Dam Engine is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using System.IO;
using System.Reflection;
namespace Deltares.DamEngine.Calculators.KernelWrappers.Assemblers
{
public static class Common
{
///
/// Extracts an embedded file out of a given assembly.
///
/// The namespace of you assembly.
/// The name of the file to extract.
/// A stream containing the file data.
public static Stream GetEmbeddedFile(string assemblyName, string fileName)
{
try
{
Assembly a = Assembly.Load(assemblyName);
Stream str = a.GetManifestResourceStream(assemblyName + "." + fileName);
if (str == null)
throw new Exception("Could not locate embedded resource '" + fileName + "' in assembly '" + assemblyName + "'");
return str;
}
catch (Exception e)
{
throw new Exception(string.Format("{0}: {1}", assemblyName, e.Message));
}
}
///
/// Extracts an embedded file out of a given assembly.
///
/// The name of the resource which normally is the namespace of you assembly and the file.
/// A stream containing the file data.
public static Stream GetEmbeddedFile(Assembly assembly, string resourceName)
{
try
{
Stream str = assembly.GetManifestResourceStream(resourceName);
if (str == null)
throw new Exception(
string.Format("Could not locate embedded resource '{0}' in assembly '{1}'",
resourceName, assembly.GetName()));
return str;
}
catch (Exception e)
{
throw new Exception(string.Format("{0}: {1}", assembly.GetName(), e.Message));
}
}
}
}