Ejemplo n.º 1
0
        /// <summary>
        /// Just a convenience method to get embedded resource using "path syntax".
        /// </summary>
        /// <param name="resourcePath">Embedded resource path (with / and \ separators)</param>
        /// <returns>Resource stream</returns>
        public Stream GetEmbeddedResource(string resourcePath)
        {
            var parsedResourcePath = ResourcePathParser.Parse(resourcePath);

            VerifyEmbeddedResourcePath(parsedResourcePath);
            return(GetResourceStream(parsedResourcePath));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads embedded resource and saves it as afile to a temporary folder.
        /// </summary>
        /// <param name="resourcePath">Embedded resource path (with / and \ separators)</param>
        /// <returns>The full path to the file deployed.</returns>
        public string DeployEmbeddedResource(string resourcePath)
        {
            var parsedResourcePath = ResourcePathParser.Parse(resourcePath);

            VerifyEmbeddedResourcePath(parsedResourcePath);

            using (Stream resourceStream = GetResourceStream(parsedResourcePath))
            {
                string deployToPath = GetTargetFilePath(parsedResourcePath);
                using (var fileOutputStream = new FileStream(deployToPath, FileMode.CreateNew))
                {
                    resourceStream.CopyTo(fileOutputStream);
                }

                return(deployToPath);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads embedded resource and saves it as afile to a temporary folder.
        /// </summary>
        /// <param name="resourcePath">Embedded resource path (with / and \ separators)</param>
        /// <param name="outputSubDirectory">
        /// Subdirectory where to deploy resource file (with / and \ separators)
        /// </param>
        /// <returns>The full path to the file deployed.</returns>
        public string DeployEmbeddedResource(string resourcePath, string outputSubDirectory)
        {
            var parsedResourcePath = ResourcePathParser.Parse(resourcePath);

            VerifyEmbeddedResourcePath(parsedResourcePath);

            var parsedOutputSubdirectory = ResourcePathParser.Parse(outputSubDirectory);

            if (parsedOutputSubdirectory.IsRoot)
            {
                throw new ArgumentException($"{nameof(outputSubDirectory)} should be relative, not root.");
            }

            using (Stream resourceStream = GetResourceStream(parsedResourcePath))
            {
                string deployToPath = GetTargetFilePath(parsedResourcePath, parsedOutputSubdirectory);
                using (var fileOutputStream = new FileStream(deployToPath, FileMode.CreateNew))
                {
                    resourceStream.CopyTo(fileOutputStream);
                }

                return(deployToPath);
            }
        }