示例#1
0
        public void Write(TargetFile targetfile)
        {
            try
            {
                string filepath = GetOutputFilePath(targetfile);

                using (FileStream fs = new FileStream(filepath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        Write(targetfile, sw);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException($"Failed to write target file '{targetfile.Name}'.", ex);
            }
        }
示例#2
0
        internal IEnumerable <TargetFile> GenerateTargetFilesList(IEnumerable <SrcDoc> sourceFiles)
        {
            Dictionary <string, TargetFile> targetfiles = new Dictionary <string, TargetFile>(StringComparer.OrdinalIgnoreCase);

            foreach (var srcdoc in sourceFiles)
            {
                PackerDirectiveNode targetfileDirective = null;

                try { targetfileDirective = srcdoc.PackerDirectives?.SingleOrDefault(_ => _.Name == "targetFile"); }
                catch (InvalidOperationException ex)
                {
                    throw new ApplicationException(
                              $"The file '{srcdoc.Document.Name}' has multiple targetfile packer directives.",
                              ex);
                }

                if (targetfileDirective == null)
                {
                    targetfileDirective = new PackerDirectiveNode {
                        Name    = "targetFile",
                        Options = PackOptions.TargetFile ?? "lib.cs"
                    };
                }

                if (targetfiles.ContainsKey(targetfileDirective.Options) == false)
                {
                    //add new targetfile to targetfiles list
                    var targetfile = new TargetFile(targetfileDirective.Options);
                    targetfiles.Add(targetfileDirective.Options, targetfile);

                    if (PackOptions.Verbose)
                    {
                        Console.WriteLine($"New target file: {targetfile.Name}");
                    }
                }

                //add this sourcedoc to targetfile
                targetfiles[targetfileDirective.Options].SourceDocs.Add(srcdoc);
            }

            return(targetfiles.Values);
        }
示例#3
0
        public void Write(TargetFile targetFile, TextWriter writer)
        {
            writer.WriteLine("//packed");

            //write global usings
            foreach (var usingStatement in targetFile.GlobalUsings)
            {
                writer.WriteLine($"using {usingStatement};");
            }
            if (targetFile.GlobalUsings.Count > 0)
            {
                writer.WriteLine();
            }

            //write source docs
            foreach (var srcdoc in targetFile.SourceDocs)
            {
                writer.WriteLine($"//packed:{srcdoc.Document.Name}");

                srcdoc.SyntaxTree.GetText().Write(writer);

                writer.WriteLine($"//packed:{srcdoc.Document.Name}");
            }
        }
示例#4
0
        public string GetOutputFilePath(TargetFile targetfile)
        {
            string filepath = Path.Combine(_outputPath, _baseName + targetfile.Name);

            return(filepath);
        }