using System.IO;
using System.Linq;
using System.Reflection;


namespace XlsioSlowCalculate_16_2.Files
{
    public static class EmbeddedFiles
    {
        public const string ExcelDocumentName = "LargeWorkbook.xlsx";

        /// <summary>
        /// Opens the specified file found in the embedded resources.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        /// <exception cref="FileNotFoundException">Could not locate file in executing assembly</exception>
        public static Stream OpenFile( string fileName )
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            string resourceKey = assembly.GetManifestResourceNames().FirstOrDefault( s => s.Contains( fileName ) );

            if ( resourceKey == null )
                throw new FileNotFoundException( "Could not locate file in executing assembly", fileName );

            return assembly.GetManifestResourceStream( resourceKey );
        }
    }
}
