Exemple #1
0
        Stream GetResourceStream(ResourcePathParser.ParsedPath parsedResourcePath)
        {
            string pathToEmbeddedRes = string.Join(".", parsedResourcePath.Parts);

            var assembly = referenceObject as Assembly;

            if (assembly == null)
            {
                var type     = referenceObject.GetType();
                var typeInfo = type.GetTypeInfo();
                assembly = typeInfo.Assembly;
                if (!parsedResourcePath.IsRoot)
                {
                    pathToEmbeddedRes = string.Concat(type.Namespace, '.', pathToEmbeddedRes);
                }
            }

            Stream resourceStream = assembly.GetManifestResourceStream(pathToEmbeddedRes);

            if (resourceStream == null)
            {
                throw new ArgumentException(
                          $"Resource stream {pathToEmbeddedRes} was not found in {assembly.FullName}");
            }

            return(resourceStream);
        }
Exemple #2
0
 void VerifyEmbeddedResourcePath(ResourcePathParser.ParsedPath parsedResourcePath)
 {
     if (referenceObject is Assembly && !parsedResourcePath.IsRoot)
     {
         throw new ArgumentException(
                   "Resource path must start with / or \\ if you passed Assembly as constructor argument.");
     }
 }
Exemple #3
0
        string GetTargetFilePath(ResourcePathParser.ParsedPath parsedResourcePath)
        {
            string fileName = parsedResourcePath.Parts.Last();

            CreateDeploymentDirectory();
            string result = Path.Combine(DeploymentDirectory, fileName);

            return(result);
        }
Exemple #4
0
        string GetTargetFilePath(
            ResourcePathParser.ParsedPath parsedResourcePath,
            ResourcePathParser.ParsedPath parsedOutputSubdirectory)
        {
            string subDirectory = string.Join(
                Path.DirectorySeparatorChar.ToString(), parsedOutputSubdirectory.Parts);

            CreateDeploymentDirectory();
            string pathToSubdirectory = Path.Combine(DeploymentDirectory, subDirectory);

            Directory.CreateDirectory(pathToSubdirectory);

            string fileName = parsedResourcePath.Parts.Last();
            string result   = Path.Combine(pathToSubdirectory, fileName);

            return(result);
        }