private static Stream GenerateResources(ResourceFile resourceFile)
 {
     var stream = new MemoryStream();
     ResourceFileGenerator.Generate(resourceFile, stream);
     stream.Position = 0;
     return stream;
 }
示例#2
0
        public static void Generate(ResourceFile sourceFile, Stream outputStream)
        {
            if (outputStream == null) throw new ArgumentNullException(nameof(outputStream));
            using (var input = sourceFile.File.OpenRead())
            {
                var document = XDocument.Load(input);
                var data = document.Root.Elements("data");
                if (data.Any())
                {
                    var rw = new ResourceWriter(outputStream);

                    foreach (var e in data)
                    {
                        var name = e.Attribute("name").Value;
                        var value = e.Element("value").Value;
                        rw.AddResource(name, value);
                    }

                    rw.Generate();
                }
            }
        }
        public static bool GenerateCultureResourceAssemblies(Project project, List <CompilerUtility.CultureResgenIO> cultureResgenFiles, List <string> referencePaths, IList <string> diagnostics)
        {
            foreach (var resgenFile in cultureResgenFiles)
            {
                var resourceOutputPath = Paths.GetParentFolderPath(resgenFile.OutputFile);
                Directory.CreateDirectory(resourceOutputPath);

                var inputResourceFiles = resgenFile.InputFileToMetadata
                                         .Select(fileToMetadata => new ResourceSource(ResourceFile.Create(fileToMetadata.Key), fileToMetadata.Value))
                                         .ToArray();

                var outputResourceFile = ResourceFile.Create(resgenFile.OutputFile);

                if (outputResourceFile.Type != ResourceFileType.Dll)
                {
                    diagnostics.Add("Resource output type not supported");
                    return(false);
                }

                using (var outputStream = outputResourceFile.File.Create())
                {
                    var metadata = new AssemblyInfoOptions
                    {
                        Culture         = resgenFile.Culture,
                        AssemblyVersion = project.Version.Version.ToString(),
                    };

                    ResourceAssemblyGenerator.Generate(inputResourceFiles,
                                                       outputStream,
                                                       metadata,
                                                       Path.GetFileNameWithoutExtension(outputResourceFile.File.Name),
                                                       referencePaths.ToArray(),
                                                       diagnostics);
                }
            }

            return(true);
        }