Esempio n. 1
0
        public async Task WriteHeader(StreamWriter outputStr, CmdOptions options)
        {
            string gitInfo = await this.getGitInfo(options.SlnFile);

            using SHA1Managed sha1 = new SHA1Managed();
            var    hashBytes = sha1.ComputeHash(await File.ReadAllBytesAsync(this.templatePath));
            var    hash      = string.Concat(hashBytes.Select(b => b.ToString("x2")));
            var    asm       = Assembly.GetExecutingAssembly();
            string appInfo   = $"({asm.GetName().Name} {asm.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion})";
            await outputStr.WriteLineAsync($"# Template created from {options.SlnFile.Name}{gitInfo} with {Path.GetFileName(this.templatePath)} (SHA:{hash}) on {DateTime.Now.ToShortDateString()} {appInfo}");

            await outputStr.WriteLineAsync($"# {Assembly.GetExecutingAssembly().GetName().CodeBase?.Split('/').Last()} {options.OriginalArgs}");
        }
Esempio n. 2
0
        private static async Task execute(CmdOptions options, DockerfileGenerator generator, SolutionData solutionsData, TestProvider testProvider, Logger logger)
        {
            object data;

            if (options.InputJson == null)
            {
                await solutionsData.Init();

                if (!options.NoAutoTest)
                {
                    var projects = testProvider.GetTests(solutionsData.GetSolution(), options.PublishedProject);
                    options.ProjectsToTest = options.ProjectsToTest.Concat(projects).Distinct().ToArray();
                }

                await solutionsData.Load(options);

                data = solutionsData.GetDockerData();
            }
            else
            {
                await using var inStr = options.InputJson == string.Empty ? Console.OpenStandardInput() : File.OpenRead(options.InputJson);
                data = await JsonSerializer.DeserializeAsync <object>(inStr);
            }

            await using var outputStr = options.OutputFile?.Open(FileMode.Create, FileAccess.Write) ?? Console.OpenStandardOutput();
            if (options.OutputJson)
            {
                await JsonSerializer.SerializeAsync(outputStr, data, new JsonSerializerOptions { WriteIndented = true });
            }
            else
            {
                await using var outputWriter = new StreamWriter(outputStr);
                if (!options.NoHeader)
                {
                    await generator.WriteHeader(outputWriter, options);
                }

                await generator.Generate(outputWriter, data);
            }

            if (options.OutputFile != null)
            {
                logger.Information("Output saved to " + options.OutputFile);
                outputStr.Close();
            }
        }
Esempio n. 3
0
        public async Task Load(CmdOptions dockerFileOptions)
        {
            if (this.options != null || dockerFileOptions.SlnFile != this.solutionFile)
            {
                throw new InvalidOperationException();
            }

            this.options = dockerFileOptions;

            Project[] projectsInOptions;
            (this.projectsToTest, projectsInOptions) = SolutionData.GetProjectsFromOptions(this.options, this.solution);

            this.allProjects = GetAllProjectsByFile(projectsInOptions, this.solution, this.options.OnlyLoadReferencedProjects);

            //foreach (var projFile in projectFilesToTest.Append(new FileInfoKey(this.options.PublishedProject)))
            //{
            //    if (!this.allProjects.ContainsKey(projFile))
            //    {
            //        this.allProjects.Add(projFile, await this.workspace.OpenProjectAsync(projFile.Info.FullName));
            //    }
            //}
            this.dependencyOrdering = new DependencyOrder(this.solution, this.solutionGraph, this.allProjects, this.options.DependencyOrder, this.logger);
        }
Esempio n. 4
0
        public static (FileInfoKey[] projectFilesToTest, Project[] projectsInOptions) GetProjectsFromOptions(CmdOptions options, Solution solution)
        {
            var projectFilesToTest = options.ProjectsToTest
                                     .Where(f => solution.Projects.Any(p => p.FilePath != null && p.FilePath.Equals(f.FullName)))
                                     .Select(f => new FileInfoKey(f)).ToArray();
            var projectsInOptions = projectFilesToTest.Append(new FileInfoKey(options.PublishedProject))
                                    .Select(i =>
                                            solution.Projects.SingleOrDefault(p => new FileInfoKey(p.FilePath).Equals(i)))
                                    .Where(p => p != null).ToArray();

            return(projectFilesToTest, projectsInOptions);
        }