Exemple #1
0
        public static void ExtractResourceToDirectory(string outputDirectory, Assembly assembly, string resourceName, string fileName)
        {
            ValidateCommonArguments(outputDirectory, assembly, resourceName);

            fileName = fileName ?? resourceName;
            string fullResourceName = new AssemblyName(assembly.FullName).Name + ".Resources." + resourceName;

            using (Stream inputStream = assembly.GetManifestResourceStream(fullResourceName))
            {
                if (inputStream == null)
                {
                    throw new TaupoInfrastructureException("Embedded resource " + fullResourceName + " not found in " + assembly.FullName);
                }

                using (Stream outputStream = File.Create(Path.Combine(outputDirectory, fileName)))
                {
                    IOHelpers.CopyStream(inputStream, outputStream);
                }
            }
        }
Exemple #2
0
        public static void ExtractCompressedResourceToDirectory(string outputDirectory, Assembly assembly, string resourceName)
        {
            ValidateCommonArguments(outputDirectory, assembly, resourceName);

            string fullResourceName = new AssemblyName(assembly.FullName).Name + ".Resources." + resourceName + ".gz";

            using (Stream compressedInputStream = assembly.GetManifestResourceStream(fullResourceName))
            {
                if (compressedInputStream == null)
                {
                    throw new TaupoInfrastructureException("Embedded resource " + fullResourceName + " not found in " + assembly.FullName);
                }

                using (GZipStream decompressedInputStream = new GZipStream(compressedInputStream, CompressionMode.Decompress))
                {
                    using (Stream outputStream = File.Create(Path.Combine(outputDirectory, resourceName)))
                    {
                        IOHelpers.CopyStream(decompressedInputStream, outputStream);
                    }
                }
            }
        }