<commit_before>﻿namespace Toyertechnologies.Woodpecker.Processes
{
    using System;
    using System.Diagnostics;
    using System.Text;

    /// <summary>
    /// Base class to encapsulate the defaults for running a Process
    /// </summary>
    public abstract class ProcessBase
    {
        /// <summary>
        /// The Process created by this instance.
        /// </summary>
        private Process process;

        /// <summary>
        /// The ProcessStartInfo associated with this instance.
        /// </summary>
        private ProcessStartInfo startInfo;

        /// <summary>
        /// The StringBuilder of messages output for the process in the instance.
        /// </summary>
        private StringBuilder messageBuilder;

        /// <summary>
        /// The ConstructProcessDelegate for the process
        /// </summary>
        private ConstructProcessDelegate processConstruction;

        /// <summary>
        /// The ConstructStartInfoDelegate for the process
        /// </summary>
        private ConstructStartInfoDelegate startInfoConstruction;

        /// <summary>
        /// Initializes a new instance of the ProcessBase class.
        /// </summary>
        /// <param name="processLocation">The location of process to be executed</param>
        /// <param name="processArguments">The arguments that will be passed to the process</param>
        /// <param name="workingDirectory">The directory the process will execute within</param>
        public ProcessBase(string processLocation, string processArguments, string workingDirectory)
        {
            this.messageBuilder = new StringBuilder();
            this.process = new Process();
            this.ProcessLocation = processLocation;
            this.ProcessArguments = processArguments;
            this.WorkingDirectory = workingDirectory;
            this.processConstruction = new ConstructProcessDelegate(this.ConstructProcess);
            this.startInfoConstruction = new ConstructStartInfoDelegate(this.ConstructStartInfo);
        }

        /// <summary>
        /// Represents the method that will construct Process instance.
        /// </summary>
        /// <param name="startInformation">The start information the process will be constructed with</param>
        /// <returns>REturns a Process with the default values</returns>
        public delegate Process ConstructProcessDelegate(ProcessStartInfo startInformation);

        /// <summary>
        /// Represents the method that will construct the ProcessStartInfo for the Process instance
        /// </summary>
        /// <param name="processArguments">The arguments that will be passed to the process</param>
        /// <param name="workingDirectory">The directory the process will execute within</param>
        /// <returns>Returns a ProcessStartInfo containing the default start information for a process</returns>
        public delegate ProcessStartInfo ConstructStartInfoDelegate(string processArguments, string workingDirectory);

        /// <summary>
        /// Occurs when a message is output from the process
        /// </summary>
        public event DataReceivedEventHandler CustomMessageHandler;

        /// <summary>
        /// Occurs when the process exits.
        /// </summary>
        public event EventHandler ExitedHandler;

        /// <summary>
        /// Gets the exit code passed from the process
        /// </summary>
        public int ExitCode { get; private set; }

        /// <summary>
        /// Gets the location of process to be executed.
        /// </summary>
        public string ProcessLocation { get; private set; }

        /// <summary>
        /// Gets any arguments that will be passed to the process.
        /// </summary>
        public string ProcessArguments { get; private set; }

        /// <summary>
        /// Gets the directory the process will execute within.
        /// </summary>
        public string WorkingDirectory { get; private set; }

        /// <summary>
        /// Gets any messages returned when executing the process
        /// </summary>
        public string Messages
        {
            get
            {
                return this.messageBuilder.ToString();
            }
        }

        /// <summary>
        /// Overrides the default process creation method
        /// </summary>
        /// <param name="constructProcessMethod">The ConstructProcessDelegate implementation to replace the default with.</param>
        public void OverrideProcessConstruction(ConstructProcessDelegate constructProcessMethod)
        {
            this.processConstruction = constructProcessMethod;
        }

        /// <summary>
        /// Overrides the default start info creation method
        /// </summary>
        /// <param name="constructStartInfoMethod">The ConstructStartInfoDelegate implementation to replace the default with.</param>
        public void OverrideStartInfoConstruction(ConstructStartInfoDelegate constructStartInfoMethod)
        {
            this.startInfoConstruction = constructStartInfoMethod;
        }

        /// <summary>
        /// Run the process
        /// </summary>
        public void Run()
        {
            // Assemble the process
            this.AssembleProcess();

            // Run the process
            process.Start();
            process.BeginErrorReadLine();
            process.BeginOutputReadLine();
            process.WaitForExit();
        }

        /// <summary><commit_msg>Stylecop fix to the process base<commit_after>﻿namespace Toyertechnologies.Woodpecker.Processes
{
    using System;
    using System.Diagnostics;
    using System.Text;

    /// <summary>
    /// Base class to encapsulate the defaults for running a Process
    /// </summary>
    public abstract class ProcessBase
    {
        /// <summary>
        /// The Process created by this instance.
        /// </summary>
        private Process process;

        /// <summary>
        /// The ProcessStartInfo associated with this instance.
        /// </summary>
        private ProcessStartInfo startInfo;

        /// <summary>
        /// The StringBuilder of messages output for the process in the instance.
        /// </summary>
        private StringBuilder messageBuilder;

        /// <summary>
        /// The ConstructProcessDelegate for the process
        /// </summary>
        private ConstructProcessDelegate processConstruction;

        /// <summary>
        /// The ConstructStartInfoDelegate for the process
        /// </summary>
        private ConstructStartInfoDelegate startInfoConstruction;

        /// <summary>
        /// Initializes a new instance of the ProcessBase class.
        /// </summary>
        /// <param name="processLocation">The location of process to be executed</param>
        /// <param name="processArguments">The arguments that will be passed to the process</param>
        /// <param name="workingDirectory">The directory the process will execute within</param>
        public ProcessBase(string processLocation, string processArguments, string workingDirectory)
        {
            this.messageBuilder = new StringBuilder();
            this.process = new Process();
            this.ProcessLocation = processLocation;
            this.ProcessArguments = processArguments;
            this.WorkingDirectory = workingDirectory;
            this.processConstruction = new ConstructProcessDelegate(this.ConstructProcess);
            this.startInfoConstruction = new ConstructStartInfoDelegate(this.ConstructStartInfo);
        }

        /// <summary>
        /// Represents the method that will construct Process instance.
        /// </summary>
        /// <param name="startInformation">The start information the process will be constructed with</param>
        /// <returns>REturns a Process with the default values</returns>
        public delegate Process ConstructProcessDelegate(ProcessStartInfo startInformation);

        /// <summary>
        /// Represents the method that will construct the ProcessStartInfo for the Process instance
        /// </summary>
        /// <param name="processArguments">The arguments that will be passed to the process</param>
        /// <param name="workingDirectory">The directory the process will execute within</param>
        /// <returns>Returns a ProcessStartInfo containing the default start information for a process</returns>
        public delegate ProcessStartInfo ConstructStartInfoDelegate(string processArguments, string workingDirectory);

        /// <summary>
        /// Occurs when a message is output from the process
        /// </summary>
        public event DataReceivedEventHandler CustomMessageHandler;

        /// <summary>
        /// Occurs when the process exits.
        /// </summary>
        public event EventHandler ExitedHandler;

        /// <summary>
        /// Gets the exit code passed from the process
        /// </summary>
        public int ExitCode { get; private set; }

        /// <summary>
        /// Gets the location of process to be executed.
        /// </summary>
        public string ProcessLocation { get; private set; }

        /// <summary>
        /// Gets any arguments that will be passed to the process.
        /// </summary>
        public string ProcessArguments { get; private set; }

        /// <summary>
        /// Gets the directory the process will execute within.
        /// </summary>
        public string WorkingDirectory { get; private set; }

        /// <summary>
        /// Gets any messages returned when executing the process
        /// </summary>
        public string Messages
        {
            get
            {
                return this.messageBuilder.ToString();
            }
        }

        /// <summary>
        /// Overrides the default process creation method
        /// </summary>
        /// <param name="constructProcessMethod">The ConstructProcessDelegate implementation to replace the default with.</param>
        public void OverrideProcessConstruction(ConstructProcessDelegate constructProcessMethod)
        {
            this.processConstruction = constructProcessMethod;
        }

        /// <summary>
        /// Overrides the default start info creation method
        /// </summary>
        /// <param name="constructStartInfoMethod">The ConstructStartInfoDelegate implementation to replace the default with.</param>
        public void OverrideStartInfoConstruction(ConstructStartInfoDelegate constructStartInfoMethod)
        {
            this.startInfoConstruction = constructStartInfoMethod;
        }

        /// <summary>
        /// Run the process
        /// </summary>
        public void Run()
        {
            // Assemble the process
            this.AssembleProcess();

            // Run the process
            this.process.Start();
            this.process.BeginErrorReadLine();
            this.process.BeginOutputReadLine();
            this.process.WaitForExit();
        }

        /// <summary>
{'fraction_non_alphanumeric': 0.0940132234399058, 'fraction_numerical': 0.0, 'mean_word_length': 2.0418732782369147, 'pattern_counts': {'":': 0, '<': 121, '<?xml version=': 0, '>': 121, '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': '2252017', 'n_tokens_mistral': 2396, 'n_tokens_neox': 2333, 'n_words': 804}