<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;

namespace Clarius.TransformOnBuild.MSBuild.Task
{
    public class TransformOnBuildTask : Microsoft.Build.Utilities.Task
    {
        private ProjectInstance _projectInstance;
        private Dictionary<string, string> _properties;
        private string _commonProgramFiles;
        private string _textTransformPath;
        private string _transformExe;
        const BindingFlags BindingFlags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public;

        public override bool Execute()
        {
            _projectInstance = GetProjectInstance();
            _properties = _projectInstance.Properties.ToDictionary(p => p.Name, p => p.EvaluatedValue);

            InitPathProperties();

            if (!File.Exists(_transformExe))
            {
                Log.LogError("Failed to find TextTransform.exe tool at '{0}'.", _transformExe);
                return false;
            }

            var textTransform = _projectInstance.Items.Where(i =>
            {
                var comparer = StringComparer.InvariantCultureIgnoreCase;
                return comparer.Equals(i.ItemType, "None") &&
                       comparer.Equals(i.GetMetadataValue("Generator"), "TextTemplatingFileGenerator");
            });

            foreach (var templateItem in textTransform)
            {
                var templatePath = templateItem.GetMetadataValue("FullPath");
                var templateBackupPath = templatePath + ".bak_clarius";
                try
                {
                    File.Copy(templatePath, templateBackupPath, overwrite: true);

                    RewriteTemplateFile(templatePath);

                    var result = RunTransformTool(templatePath);

                    if (!result)
                        return false;
                }
                finally
                {
                    File.Copy(templateBackupPath, templatePath, overwrite: true);
                    File.Delete(templateBackupPath);
                }
            }
<commit_msg>Modify task to support Build Action = Content<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;

namespace Clarius.TransformOnBuild.MSBuild.Task
{
    public class TransformOnBuildTask : Microsoft.Build.Utilities.Task
    {
        private ProjectInstance _projectInstance;
        private Dictionary<string, string> _properties;
        private string _commonProgramFiles;
        private string _textTransformPath;
        private string _transformExe;
        const BindingFlags BindingFlags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public;

        public override bool Execute()
        {
            _projectInstance = GetProjectInstance();
            _properties = _projectInstance.Properties.ToDictionary(p => p.Name, p => p.EvaluatedValue);

            InitPathProperties();

            if (!File.Exists(_transformExe))
            {
                Log.LogError("Failed to find TextTransform.exe tool at '{0}'.", _transformExe);
                return false;
            }

            var textTransform = _projectInstance.Items.Where(i =>
            {
                var comparer = StringComparer.InvariantCultureIgnoreCase;
                return (comparer.Equals(i.ItemType, "None") || comparer.Equals(i.ItemType, "Content")) &&
                       comparer.Equals(i.GetMetadataValue("Generator"), "TextTemplatingFileGenerator");
            });

            foreach (var templateItem in textTransform)
            {
                var templatePath = templateItem.GetMetadataValue("FullPath");
                var templateBackupPath = templatePath + ".bak_clarius";
                try
                {
                    File.Copy(templatePath, templateBackupPath, overwrite: true);

                    RewriteTemplateFile(templatePath);

                    var result = RunTransformTool(templatePath);

                    if (!result)
                        return false;
                }
                finally
                {
                    File.Copy(templateBackupPath, templatePath, overwrite: true);
                    File.Delete(templateBackupPath);
                }
            }

{'fraction_non_alphanumeric': 0.08032786885245902, 'fraction_numerical': 0.0004098360655737705, 'mean_word_length': 2.1029879211697393, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '1094952', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1107, 'n_words': 238}