<commit_before>﻿using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;


namespace SyncTool.FileSystem
{
    //TODO: Rename to something without visitor in name (that's an implementation detail)
    public class CreateLocalDirectoryVisitor : BaseVisitor<string>
    {
        /// <summary>
        /// Creates the specified file system tree in the specified location
        /// </summary>
        /// <param name="toCreate">The file system tree to create</param>
        /// <param name="createIn">The path to create the tree in</param>
        /// <returns></returns>
        public ILocalDirectory CreateDirectory(IDirectory toCreate, string createIn)
        {
            if (toCreate == null)
            {
                throw new ArgumentNullException(nameof(toCreate));
            }

            ((dynamic)this).Visit((dynamic)toCreate, createIn);            
            return new LocalDirectory(Path.Combine(createIn, toCreate.Name));
        }

        public IFile CreateFile(IFile toCreate, string createIn)
        {
            if (toCreate == null)
            {
                throw new ArgumentNullException(nameof(toCreate));
            }

            ((dynamic)this).Visit((dynamic)toCreate, createIn);
            return new LocalFile(Path.Combine(createIn, toCreate.Name));
        }


        public void Visit(IFile file, string parentPath)
        {
            using (System.IO.File.Create(Path.Combine(parentPath, file.Name)))
            {
            }
        }

        public void Visit(IReadableFile file, string parentPath)
        {
            using (var outputStream = System.IO.File.Create(Path.Combine(parentPath, file.Name)))
            {
                using (var inputStream = file.Open(FileMode.Open))
                {
                    inputStream.CopyTo(outputStream);
                }
            }
        }


        public override void Visit(IDirectory directory, string parentPath)
        {
            var dirPath = Path.Combine(parentPath, directory.Name);

            var dirInfo = new DirectoryInfo(dirPath);

            if (!dirInfo.Exists)
            {
                dirInfo.Create();
            }

            base.Visit(directory, dirPath);

        }
    }
}<commit_msg>Minor code cleanup in CreateLocalDirectoryVisitor<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;


namespace SyncTool.FileSystem
{
    //TODO: Rename to something without visitor in name (that's an implementation detail)
    public class CreateLocalDirectoryVisitor : BaseVisitor<string>
    {

        /// <summary>
        /// Creates the specified file system tree in the specified location
        /// </summary>
        /// <param name="toCreate">The file system tree to create</param>
        /// <param name="createIn">The path to create the tree in</param>
        /// <returns></returns>
        public ILocalDirectory CreateDirectory(IDirectory toCreate, string createIn)
        {
            if (toCreate == null)
            {
                throw new ArgumentNullException(nameof(toCreate));
            }

            VisitDynamic(toCreate, createIn);
            return new LocalDirectory(Path.Combine(createIn, toCreate.Name));
        }

        public IFile CreateFile(IFile toCreate, string createIn)
        {
            if (toCreate == null)
            {
                throw new ArgumentNullException(nameof(toCreate));
            }

            VisitDynamic(toCreate, createIn);
            return new LocalFile(Path.Combine(createIn, toCreate.Name));
        }


        public void Visit(IFile file, string parentPath)
        {
            using (System.IO.File.Create(Path.Combine(parentPath, file.Name)))
            {
            }
        }

        public void Visit(IReadableFile file, string parentPath)
        {
            using (var outputStream = System.IO.File.Create(Path.Combine(parentPath, file.Name)))
            {
                using (var inputStream = file.Open(FileMode.Open))
                {
                    inputStream.CopyTo(outputStream);
                }
            }
        }

        public override void Visit(IDirectory directory, string parentPath)
        {
            var dirPath = Path.Combine(parentPath, directory.Name);

            var dirInfo = new DirectoryInfo(dirPath);

            if (!dirInfo.Exists)
            {
                dirInfo.Create();
            }

            base.Visit(directory, dirPath);
        }


        void VisitDynamic(dynamic arg, string parentPath)
        {
            ((dynamic)this).Visit(arg, parentPath);
        }
    }
}
{'fraction_non_alphanumeric': 0.09486583562222692, 'fraction_numerical': 0.0, 'mean_word_length': 1.8279569892473118, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '1695201', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1165, 'n_words': 283}