<commit_before>﻿using Mono.Cecil;
using Mono.Cecil.Cil;
using System;
using System.IO;
using System.Threading.Tasks;

namespace DotvvmAcademy.Validation.CSharp.AssemblyAnalysis
{
    public class DefaultAssemblyRewriter : IAssemblyRewriter
    {
        public const string RewriterNamespace = "DotvvmAcademy.Validation.Rewritten";
        public const string ContainingClassPrefix = "SafeguardContainer";
        public const string SafeguardFieldName = "Safeguard";

        public Task Rewrite(Stream source, Stream target)
        {
            var rewriteId = Guid.NewGuid();
            return Task.Run(() =>
            {
                var assembly = AssemblyDefinition.ReadAssembly(source);
                foreach (var module in assembly.Modules)
                {
                    var safeguardField = InjectSafeguardField(rewriteId, module);
                    foreach (var type in module.Types)
                    {
                        foreach (var method in type.Methods)
                        {
                            InjectSafeguardIntoMethod(safeguardField, method, module);
                        }
                    }
                }
                assembly.Write(target);
                using (var file = new FileStream("C:/dev/ASP/test.dll", FileMode.Create))
                {
                    assembly.Write(file);
                }
            });<commit_msg>Remove debug EmittedAssembly FileStream<commit_after>﻿using Mono.Cecil;
using Mono.Cecil.Cil;
using System;
using System.IO;
using System.Threading.Tasks;

namespace DotvvmAcademy.Validation.CSharp.AssemblyAnalysis
{
    public class DefaultAssemblyRewriter : IAssemblyRewriter
    {
        public const string RewriterNamespace = "DotvvmAcademy.Validation.Rewritten";
        public const string ContainingClassPrefix = "SafeguardContainer";
        public const string SafeguardFieldName = "Safeguard";

        public Task Rewrite(Stream source, Stream target)
        {
            var rewriteId = Guid.NewGuid();
            return Task.Run(() =>
            {
                var assembly = AssemblyDefinition.ReadAssembly(source);
                foreach (var module in assembly.Modules)
                {
                    var safeguardField = InjectSafeguardField(rewriteId, module);
                    foreach (var type in module.Types)
                    {
                        foreach (var method in type.Methods)
                        {
                            InjectSafeguardIntoMethod(safeguardField, method, module);
                        }
                    }
                }
                assembly.Write(target);
            });
{'fraction_non_alphanumeric': 0.07318894697535475, 'fraction_numerical': 0.0, 'mean_word_length': 1.6472332015810276, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4446022', 'n_tokens_mistral': 686, 'n_tokens_neox': 606, 'n_words': 146}