コード例 #1
0
ファイル: ResourceCompiler.cs プロジェクト: labeuze/source
        public ResourceCompilerResult Compile(ResourceFile resource, string outputDir)
        {
            if (_resourceCompiler == null)
                throw new PBException("resource compiler is not defined");
            if (!zFile.Exists(_resourceCompiler))
                throw new PBException("resource compiler cannot be found \"{0}\"", _resourceCompiler);
            if (!zFile.Exists(resource.File))
                throw new PBException("resource file cannot be found \"{0}\"", resource.File);

            if (!zDirectory.Exists(outputDir))
                zDirectory.CreateDirectory(outputDir);

            //string resourceFile = resource.File;
            string resourceFilename = zPath.GetFileNameWithoutExtension(resource.File);
            //string nameSpace = null;
            //if (attributes.ContainsKey("namespace"))
            //    nameSpace = attributes["namespace"];
            string compiledResourceFile = resourceFilename + ".resources";
            if (resource.Namespace != null)
                compiledResourceFile = resource.Namespace + "." + compiledResourceFile;
            //"WRunSource.Class.PibLink."
            compiledResourceFile = zpath.PathSetDirectory(compiledResourceFile, outputDir);
            if (zFile.Exists(compiledResourceFile) && zFile.Exists(resource.File))
            {
                var fiResource = zFile.CreateFileInfo(resource.File);
                var fiCompiledResource = zFile.CreateFileInfo(compiledResourceFile);
                if (fiCompiledResource.LastWriteTime > fiResource.LastWriteTime)
                    //return pathCompiledResource;
                    return new ResourceCompilerResult { CompiledResourceFile = compiledResourceFile, Success = true };
            }

            _resourceCompiling = resource.File;
            _resourceResults = new ResourceCompilerResult { CompiledResourceFile = compiledResourceFile };

            //if (_resourceCompiler == null)
            //    throw new PBException("error resource compiler is not defined");
            //if (!zFile.Exists(_resourceCompiler))
            //    throw new PBException("error resource compiler cannot be found {0}", _resourceCompiler);
            ProcessStartInfo processStartInfo = new ProcessStartInfo();
            processStartInfo.FileName = _resourceCompiler;
            //    Resgen.exe PibLink_resource.resx PibLink.PibLink_resource.resources /str:cs,PibLink,PibLink_resource
            processStartInfo.Arguments = resource.File + " " + compiledResourceFile;
            if (resource.Namespace != null)
                processStartInfo.Arguments += " /str:cs," + resource.Namespace + "," + resourceFilename;
            //WriteLine(1, "  {0} {1}", _resourceCompiler, processStartInfo.Arguments);
            Trace.WriteLine("  {0} {1}", _resourceCompiler, processStartInfo.Arguments);
            processStartInfo.UseShellExecute = false;
            processStartInfo.RedirectStandardError = true;
            processStartInfo.WorkingDirectory = zPath.GetDirectoryName(resource.File);

            Process process = new Process();
            process.StartInfo = processStartInfo;
            //process.ErrorDataReceived += new DataReceivedEventHandler(CompileResource_EventErrorDataReceived);
            process.ErrorDataReceived += CompileResource_EventErrorDataReceived;
            process.Start();
            process.BeginErrorReadLine();

            while (!process.HasExited)
            {
            }

            if (process.ExitCode != 0)
            {
                _resourceResults.Messages.Add(new ResourceCompilerMessage { File = resource.File, Message = string.Format("error compiling resource, exit code {0}", process.ExitCode) });
                //_resourceResults.HasError = true;
            }
            else
                _resourceResults.Success = true;

            //return compiledResourceFile;
            return _resourceResults;
        }
コード例 #2
0
ファイル: ProjectCompiler.cs プロジェクト: labeuze/source
 public ResourceFile[] CompileResources(CompilerFile[] resources)
 {
     string outputDir = zPath.Combine(_finalOutputDir, _CompileResourceSubDirectory);
     ResourceFile[] compiledResources = new ResourceFile[resources.Length];
     int i = 0;
     foreach (CompilerFile resource in resources)
     {
         compiledResources[i++] = CompileResource(resource, outputDir);
     }
     return compiledResources;
 }
コード例 #3
0
ファイル: ProjectCompiler.cs プロジェクト: labeuze/source
        public ResourceFile CompileResource(CompilerFile resource, string outputDir)
        {
            string nameSpace = null;
            if (resource.Attributes.ContainsKey("namespace"))
                nameSpace = resource.Attributes["namespace"];
            ResourceFile resourceFile = new ResourceFile { File = resource.File, Namespace = nameSpace };

            ResourceCompilerResult result = _resourceCompiler.Compile(resourceFile, outputDir);
            if (!result.Success)
                _resourceError = true;
            foreach (ResourceCompilerMessage message in result.Messages)
                _resourceMessages.Add(message);
            resourceFile.File = result.CompiledResourceFile;
            return resourceFile;
        }
コード例 #4
0
ファイル: ProjectCompiler.cs プロジェクト: labeuze/source
 private IEnumerable<ResourceFile> GetCompiledResources(ResourceFile[] compiledResources)
 {
     foreach (ResourceFile compiledResource in compiledResources)
     {
         WriteLine(2, "  Resource              \"{0}\" namespace \"{1}\"", compiledResource.File, compiledResource.Namespace);
         yield return compiledResource;
     }
 }