コード例 #1
0
        public void TransfromDirectory(string projectDirectory)
        {
            using (var scope = _containerFactory.CreateScope())
            {
                var logStream             = scope.Resolve <ILogStream>();
                var projectTransformation = scope.Resolve <IQuokkaProjectTransformation>();

                var config            = QuokkaConfigLoader.Load(projectDirectory);
                var projectPath       = CSharpProject.GetSingleProjectFromFolder(projectDirectory);
                var projectReferences = CSharpProject.RecursiveCollectProjectReferences(projectPath);
                var projectFolders    = projectReferences.Select(p => Path.GetDirectoryName(p));

                var codeFiles = projectFolders.Select(folder =>
                {
                    var allFiles = new List <string>();
                    CSharpProject.CollectFiles(folder, allFiles);

                    return(allFiles.Select(f =>
                    {
                        var content = "";
                        FileTools.TryReadAllText(f, out content);

                        return new SourceFileSnapshot()
                        {
                            ProjectName = CSharpProject.GetSingleProjectFromFolder(folder),
                            FullPath = f,
                            Content = content
                        };
                    }));
                }).SelectMany(s => s);


                var transformedCode = new SourceCodeSnapshot(
                    projectTransformation.Transform(
                        new TransformationRequest()
                {
                    Sources        = codeFiles.ToList(),
                    Configurations = config.Configurations
                }).Result.Result);

                new QuartusProjectTools(logStream).SaveCodeSnapshot(
                    transformedCode,
                    config.Project,
                    config.ProjectLocation,
                    config.Configurations.Select(c => c.Name).ToHashSet());
            }
        }
コード例 #2
0
        public void SaveCodeSnapshot(
            SourceCodeSnapshot codeSnapshot,
            string project,
            string projectLocation,
            HashSet <string> configurations)
        {
            var generatedFilesLocation = Path.Combine(projectLocation, "generated", project);
            var data = new Dictionary <string, string>();

            FileTools.CreateDirectoryRecursive(generatedFilesLocation);

            var stage = new CarryUserCode(_logStream);

            foreach (var pair in codeSnapshot)
            {
                var fileName     = Path.GetFileName(pair.FullPath);
                var existingFile = Path.Combine(generatedFilesLocation, fileName);

                if (File.Exists(existingFile))
                {
                    data[pair.FullPath] = stage.Transform(pair.Content, File.ReadAllText(existingFile));
                }
                else
                {
                    data[pair.FullPath] = pair.Content;
                }
            }

            foreach (var file in Directory.EnumerateFiles(generatedFilesLocation, "*.*"))
            {
                _logStream.WriteLine(eContentDomain.Public, ConsoleColor.DarkYellow, $"Deleting {Path.GetFileName(file)}");
                FileTools.DeleteFile(_logStream, file);
            }

            foreach (var pair in data.OrderBy(p => p.Key))
            {
                _logStream.WriteLine(eContentDomain.Public, ConsoleColor.Green, $"Writing {Path.GetFileName(pair.Key)}");
                File.WriteAllText(Path.Combine(generatedFilesLocation, pair.Key), pair.Value);
            }

            _logStream.WriteLine(eContentDomain.Public, $"Extracted {data.Count} files");

            SetupQSF(project, projectLocation, configurations);
        }