<commit_before>﻿using RelhaxModpack.Common;
using RelhaxModpack.Database;
using RelhaxModpack.Settings;
using RelhaxModpack.Utilities.Enums;
using RelhaxModpack.Windows;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace RelhaxModpack.Automation.Tasks
{
    /// <summary>
    /// An AutomationTask represents an action to occur during an automation sequence, used for checking for and updating database package entries.
    /// </summary>
    public abstract class AutomationTask : IXmlSerializable, IComponentWithID
    {
        #region Xml serialization
        /// <summary>
        /// Defines a list of properties in the class to be serialized into xml attributes.
        /// </summary>
        /// <returns>A list of string property names.</returns>
        /// <remarks>Xml attributes will always be written, xml elements are optional.</remarks>
        public virtual string[] PropertiesForSerializationAttributes()
        {
            return new string[] { nameof(ID) };
        }

        /// <summary>
        /// Defines a list of properties in the class to be serialized into xml elements.
        /// </summary>
        /// <returns>A list of string property names.</returns>
        /// <remarks>Xml attributes will always be written, xml elements are optional.</remarks>
        public virtual string[] PropertiesForSerializationElements()
        {
            return new string[] { };
        }

        /// <summary>
        /// Gets a dictionary that maps a unique task command name in xml to the type of task object in the code.
        /// </summary>
        public static Dictionary<string, Type> TaskTypeMapper { get; } = new Dictionary<string, Type>()
        {
            { DownloadStaticTask.TaskCommandName, typeof(DownloadStaticTask) },
            { DownloadHtmlTask.TaskCommandName, typeof(DownloadHtmlTask) },
            { DownloadBrowserTask.TaskCommandName, typeof(DownloadBrowserTask) },
            { ShellExecuteTask.TaskCommandName, typeof(ShellExecuteTask) },
            { LoadDatabaseTask.TaskCommandName, typeof(LoadDatabaseTask) },
            { SaveDatabaseTask.TaskCommandName, typeof(SaveDatabaseTask) },
            { PackageDownloadTask.TaskCommandName, typeof(PackageDownloadTask) },
            { PackageUploadTask.TaskCommandName, typeof(PackageUploadTask) },
            { FileCompareTask.TaskCommandName, typeof(FileCompareTask) },
            { FileCompareInverseTask.TaskCommandName, typeof(FileCompareInverseTask) },
            { FileCopyTask.TaskCommandName, typeof(FileCopyTask) },
            { FileDeleteTask.TaskCommandName, typeof(FileDeleteTask) },
            { FileMoveTask.TaskCommandName, typeof(FileMoveTask) },
            { TaskImportTask.TaskCommandName, typeof(TaskImportTask) },
            { MacroImportTask.TaskCommandName, typeof(MacroImportTask) },
            { StartCompareTask.TaskCommandName, typeof(StartCompareTask) },
            { EndCompareTask.TaskCommandName, typeof(EndCompareTask) },
            { UpdatePackagePropertyTask.TaskCommandName, typeof(UpdatePackagePropertyTask) },
            { RetrievePackagePropertyTask.TaskCommandName, typeof(RetrievePackagePropertyTask) },
            { MacroDeleteTask.TaskCommandName, typeof(MacroDeleteTask) },
            { MacroCreateTask.TaskCommandName, typeof(MacroCreateTask) },
            { DirectoryCreateTask.TaskCommandName, typeof(DirectoryCreateTask) },
            { MacroStringSplitMacroTask.TaskCommandName, typeof(MacroStringSplitMacroTask) },
            { MacroStringSplitFilenameTask.TaskCommandName, typeof(MacroStringSplitFilenameTask) },
            { MacroStringSplitHtmlTask.TaskCommandName, typeof(MacroStringSplitHtmlTask) },
            { MacroStringSplitBrowserTask.TaskCommandName, typeof(MacroStringSplitBrowserTask) },
            { MacroSubstringMacroTask.TaskCommandName, typeof(MacroSubstringMacroTask) },
            { MacroSubstringFilenameTask.TaskCommandName, typeof(MacroSubstringFilenameTask) },
            { MacroSubstringHtmlTask.TaskCommandName, typeof(MacroSubstringHtmlTask) },
            { MacroSubstringBrowserTask.TaskCommandName, typeof(MacroSubstringBrowserTask) },
            { DirectoryListTask.TaskCommandName, typeof(DirectoryListTask) },
            { DirectoryCopyTask.TaskCommandName, typeof(DirectoryCopyTask) },
            { DirectoryDeleteTask.TaskCommandName, typeof(DirectoryDeleteTask) },
            { DirectoryCompareTask.TaskCommandName, typeof(DirectoryCompareTask) },
            { DirectoryCompareCountTask.TaskCommandName, typeof(DirectoryCompareCountTask) },
            { DirectoryCompareInverseTask.TaskCommandName, typeof(DirectoryCompareInverseTask) },
            { FileExistsTask.TaskCommandName, typeof(FileExistsTask) },
            { MacroStringInputMacroJsonTask.TaskCommandName, typeof(MacroStringInputMacroJsonTask) },
            { DirectoryMoveTask.TaskCommandName, typeof(DirectoryMoveTask) },
            { StartBrowserSessionTask.TaskCommandName, typeof(StartBrowserSessionTask) },
            { EndBrowserSessionTask.TaskCommandName, typeof(EndBrowserSessionTask) },
            { BrowserSessionSetHeaderTask.TaskCommandName, typeof(BrowserSessionSetHeaderTask) },
            { BrowserSessionRemoveHeaderTask.TaskCommandName, typeof(BrowserSessionRemoveHeaderTask) },
            { BrowserSessionGetTask.TaskCommandName, typeof(BrowserSessionGetTask) },
            { BrowserSessionPostTask.TaskCommandName, typeof(BrowserSessionPostTask) },
            { BrowserSessionDownloadFileTask.TaskCommandName, typeof(BrowserSessionDownloadFileTask) },
        };<commit_msg>organized task mapper in AutomationTask<commit_after>﻿using RelhaxModpack.Common;
using RelhaxModpack.Database;
using RelhaxModpack.Settings;
using RelhaxModpack.Utilities.Enums;
using RelhaxModpack.Windows;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace RelhaxModpack.Automation.Tasks
{
    /// <summary>
    /// An AutomationTask represents an action to occur during an automation sequence, used for checking for and updating database package entries.
    /// </summary>
    public abstract class AutomationTask : IXmlSerializable, IComponentWithID
    {
        #region Xml serialization
        /// <summary>
        /// Defines a list of properties in the class to be serialized into xml attributes.
        /// </summary>
        /// <returns>A list of string property names.</returns>
        /// <remarks>Xml attributes will always be written, xml elements are optional.</remarks>
        public virtual string[] PropertiesForSerializationAttributes()
        {
            return new string[] { nameof(ID) };
        }

        /// <summary>
        /// Defines a list of properties in the class to be serialized into xml elements.
        /// </summary>
        /// <returns>A list of string property names.</returns>
        /// <remarks>Xml attributes will always be written, xml elements are optional.</remarks>
        public virtual string[] PropertiesForSerializationElements()
        {
            return new string[] { };
        }

        /// <summary>
        /// Gets a dictionary that maps a unique task command name in xml to the type of task object in the code.
        /// </summary>
        public static Dictionary<string, Type> TaskTypeMapper { get; } = new Dictionary<string, Type>()
        {
            //download tasks
            { DownloadStaticTask.TaskCommandName, typeof(DownloadStaticTask) },
            { DownloadHtmlTask.TaskCommandName, typeof(DownloadHtmlTask) },
            { DownloadBrowserTask.TaskCommandName, typeof(DownloadBrowserTask) },

            //database tasks (load/save)
            { LoadDatabaseTask.TaskCommandName, typeof(LoadDatabaseTask) },
            { SaveDatabaseTask.TaskCommandName, typeof(SaveDatabaseTask) },

            //package transfer tasks
            { PackageDownloadTask.TaskCommandName, typeof(PackageDownloadTask) },
            { PackageUploadTask.TaskCommandName, typeof(PackageUploadTask) },

            //package property tasks
            { UpdatePackagePropertyTask.TaskCommandName, typeof(UpdatePackagePropertyTask) },
            { RetrievePackagePropertyTask.TaskCommandName, typeof(RetrievePackagePropertyTask) },

            //file tasks
            { FileCopyTask.TaskCommandName, typeof(FileCopyTask) },
            { FileDeleteTask.TaskCommandName, typeof(FileDeleteTask) },
            { FileMoveTask.TaskCommandName, typeof(FileMoveTask) },
            { FileExistsTask.TaskCommandName, typeof(FileExistsTask) },

            //compare tasks
            { StartCompareTask.TaskCommandName, typeof(StartCompareTask) },
            { EndCompareTask.TaskCommandName, typeof(EndCompareTask) },
            { FileCompareTask.TaskCommandName, typeof(FileCompareTask) },
            { FileCompareInverseTask.TaskCommandName, typeof(FileCompareInverseTask) },
            { DirectoryCompareTask.TaskCommandName, typeof(DirectoryCompareTask) },
            { DirectoryCompareCountTask.TaskCommandName, typeof(DirectoryCompareCountTask) },
            { DirectoryCompareInverseTask.TaskCommandName, typeof(DirectoryCompareInverseTask) },

            //macro tasks
            { MacroDeleteTask.TaskCommandName, typeof(MacroDeleteTask) },
            { MacroCreateTask.TaskCommandName, typeof(MacroCreateTask) },
            { MacroStringSplitMacroTask.TaskCommandName, typeof(MacroStringSplitMacroTask) },
            { MacroStringSplitFilenameTask.TaskCommandName, typeof(MacroStringSplitFilenameTask) },
            { MacroStringSplitHtmlTask.TaskCommandName, typeof(MacroStringSplitHtmlTask) },
            { MacroStringSplitBrowserTask.TaskCommandName, typeof(MacroStringSplitBrowserTask) },
            { MacroSubstringMacroTask.TaskCommandName, typeof(MacroSubstringMacroTask) },
            { MacroSubstringFilenameTask.TaskCommandName, typeof(MacroSubstringFilenameTask) },
            { MacroSubstringHtmlTask.TaskCommandName, typeof(MacroSubstringHtmlTask) },
            { MacroSubstringBrowserTask.TaskCommandName, typeof(MacroSubstringBrowserTask) },
            { MacroStringInputMacroJsonTask.TaskCommandName, typeof(MacroStringInputMacroJsonTask) },

            //directory tasks
            { DirectoryCreateTask.TaskCommandName, typeof(DirectoryCreateTask) },
            { DirectoryListTask.TaskCommandName, typeof(DirectoryListTask) },
            { DirectoryCopyTask.TaskCommandName, typeof(DirectoryCopyTask) },
            { DirectoryDeleteTask.TaskCommandName, typeof(DirectoryDeleteTask) },
            { DirectoryMoveTask.TaskCommandName, typeof(DirectoryMoveTask) },

            //browser session tasks
            { StartBrowserSessionTask.TaskCommandName, typeof(StartBrowserSessionTask) },
            { EndBrowserSessionTask.TaskCommandName, typeof(EndBrowserSessionTask) },
            { BrowserSessionSetHeaderTask.TaskCommandName, typeof(BrowserSessionSetHeaderTask) },
            { BrowserSessionRemoveHeaderTask.TaskCommandName, typeof(BrowserSessionRemoveHeaderTask) },
            { BrowserSessionGetTask.TaskCommandName, typeof(BrowserSessionGetTask) },
            { BrowserSessionPostTask.TaskCommandName, typeof(BrowserSessionPostTask) },
            { BrowserSessionDownloadFileTask.TaskCommandName, typeof(BrowserSessionDownloadFileTask) },

            //automation import tasks
            { TaskImportTask.TaskCommandName, typeof(TaskImportTask) },
            { MacroImportTask.TaskCommandName, typeof(MacroImportTask) },

            //other tasks
            { ShellExecuteTask.TaskCommandName, typeof(ShellExecuteTask) }
        };
{'fraction_non_alphanumeric': 0.08595988538681948, 'fraction_numerical': 0.0, 'mean_word_length': 3.264103485447359, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 21, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6742448', 'n_tokens_mistral': 2877, 'n_tokens_neox': 2848, 'n_words': 551}