<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using ManyConsole;
using TeamCityBuildChanges.Output;
using TeamCityBuildChanges.Testing;

namespace TeamCityBuildChanges.Commands
{
    public class TestTemplate : ConsoleCommand
    {
        private string _templateFile;
        private string _outputFilename;

        public TestTemplate()
        {
            IsCommand("testtemplate", "When run, will watch a template file, and regenerate a HTML file against a generated Model.");
            HasOption("o|output=", "Output filename.", s => _outputFilename = s);
            HasAdditionalArguments(1,"Provide the path to the template file to watch.");
        }
        public override int Run(string[] remainingArguments)
        {
            if (RemainingArgumentsCount != 1) throw new ArgumentException("Please provide the path to the template file to parse.");

            _templateFile = remainingArguments[0];

            if (!File.Exists(_templateFile)) throw new ArgumentException("Please provide a template file that exists.");

            var resolver = CreateMockedAggregateBuildDeltaResolver();

            var result = resolver.CreateChangeManifestFromBuildTypeId("bt1", null, "1.2", "1.6");
            var renderer = new RazorOutputRenderer(_templateFile);

            Console.WriteLine("Running Render on File Change - Hit ENTER to EXIT.");
            if (!File.Exists(_outputFilename ?? "Output.html")) TryToRender(renderer, result, "Rendering on first run...");

            var watcher = new FileSystemWatcher
                {
                    Path = Path.GetDirectoryName(Path.GetFullPath(_templateFile)), 
                    Filter = Path.GetFileName(_templateFile), 
                    EnableRaisingEvents = true,
                    NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.CreationTime
                };

            watcher.Changed += (o, e) => TryToRender(renderer, result, "Detected template has changed, running renderer...");

            Console.Read();
            return 0;
        }

        private void TryToRender(IOutputRenderer renderer, ChangeManifest result, string message)
        {<commit_msg>Fix Manifest creation for test NuGetPackageChanges<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using ManyConsole;
using TeamCityBuildChanges.Output;
using TeamCityBuildChanges.Testing;

namespace TeamCityBuildChanges.Commands
{
    public class TestTemplate : ConsoleCommand
    {
        private string _templateFile;
        private string _outputFilename;

        public TestTemplate()
        {
            IsCommand("testtemplate", "When run, will watch a template file, and regenerate a HTML file against a generated Model.");
            HasOption("o|output=", "Output filename.", s => _outputFilename = s);
            HasAdditionalArguments(1,"Provide the path to the template file to watch.");
        }
        public override int Run(string[] remainingArguments)
        {
            if (RemainingArgumentsCount != 1) throw new ArgumentException("Please provide the path to the template file to parse.");

            _templateFile = remainingArguments[0];

            if (!File.Exists(_templateFile)) throw new ArgumentException("Please provide a template file that exists.");

            var resolver = CreateMockedAggregateBuildDeltaResolver();

            var result = resolver.CreateChangeManifestFromBuildTypeId("bt1", null, "1.2", "1.4", false, true);

            var renderer = new RazorOutputRenderer(_templateFile);

            Console.WriteLine("Running Render on File Change - Hit ENTER to EXIT.");
            if (!File.Exists(_outputFilename ?? "Output.html")) TryToRender(renderer, result, "Rendering on first run...");

            var watcher = new FileSystemWatcher
                {
                    Path = Path.GetDirectoryName(Path.GetFullPath(_templateFile)), 
                    Filter = Path.GetFileName(_templateFile), 
                    EnableRaisingEvents = true,
                    NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.CreationTime
                };

            watcher.Changed += (o, e) => TryToRender(renderer, result, "Detected template has changed, running renderer...");

            Console.Read();
            return 0;
        }

        private void TryToRender(IOutputRenderer renderer, ChangeManifest result, string message)
        {
{'fraction_non_alphanumeric': 0.08801955990220049, 'fraction_numerical': 0.004000889086463659, 'mean_word_length': 2.6496350364963503, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6738200', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1055, 'n_words': 323}