<commit_before>﻿namespace Batch.Toolkit
open System
open System.Collections.Generic
open System.IO
open System.Text
open Microsoft.Azure.Batch
open Microsoft.Azure.Batch.FileStaging

module DSL =
    let ``:cmd`` = SimpleCommand

    let ``:with_params`` = None
    let ``:parametric_cmd`` command _ parameters = ParametrizedCommand { Command = command; Parameters = parameters }

    let ``:do`` c = {Try = c; OnError = None }
    
    let ``:with`` = None
    let ``:try`` c _ h = { Try = c; OnError = Some h }

    let ``:main`` = None
    let ``:admin`` = None
    let ``:finally`` = None
    let ``:files`` = None
    let ``:unit`` 
        _ runAsAdmin 
        _ mainBlock
        _ finallyBlock
        _ localFiles = 
        {
            WorkloadUnitCommandSet = { MainCommands = mainBlock; FinallyCommands = finallyBlock } 
            WorkloadUnitLocalFiles = localFiles |> LocalFiles
            WorkloadUnitRunElevated = runAsAdmin
        }
    
    let ``:over`` = None
    let ``:range`` parameterName _ parameterValues = 
        (parameterName, parameterValues)

    let ``:units`` = None
    let ``:arguments`` = None
    
    let ``:workload`` 
            _ workloadUnitTemplates 
            _ commonFiles 
            _ arguments =
        {
            WorkloadUnitTemplates = workloadUnitTemplates
            WorkloadCommonLocalFiles = commonFiles |> LocalFiles
            WorkloadArguments = arguments |> Map.ofSeq |> WorkloadArguments
        }

    let ``:exit`` = SimpleCommand "goto :EXIT"

    let CopyOutputToAzure = ``:cmd`` "echo 'Copying output to Azure'"
    let SayHelloWorld = ``:cmd`` "echo 'Hello, world!'"
    let SayGoodbye = ``:cmd`` "echo 'Goodbye'"
    let ReadItemFromQueue = ``:cmd_with_params`` "echo 'Reading from queue'" ``:params`` ["%queue_name%"]
    
    let workload =
        ``:workload``
            ``:units`` 
                [
                    (``:unit`` 
                        ``:admin`` true 
                        ``:main`` 
                            [
                                ``:do`` SayHelloWorld
                                ``:try`` 
                                    (``:cmd_with_params`` "echo 'Hello %user%'" ``:params`` ["%user%"]) <commit_msg>Move Sample DSL usage to separate module<commit_after>﻿namespace Batch.Toolkit
open System
open System.Collections.Generic
open System.IO
open System.Text
open Microsoft.Azure.Batch
open Microsoft.Azure.Batch.FileStaging

module DSL =
    let ``:cmd`` = SimpleCommand

    let ``:with_params`` = None
    let ``:parametric_cmd`` command _ parameters = ParametrizedCommand { Command = command; Parameters = parameters }

    let ``:do`` c = {Try = c; OnError = None }
    
    let ``:with`` = None
    let ``:try`` c _ h = { Try = c; OnError = Some h }

    let ``:main`` = None
    let ``:admin`` = None
    let ``:finally`` = None
    let ``:files`` = None
    let ``:unit`` 
        _ runAsAdmin 
        _ mainBlock
        _ finallyBlock
        _ localFiles = 
        {
            WorkloadUnitCommandSet = { MainCommands = mainBlock; FinallyCommands = finallyBlock } 
            WorkloadUnitLocalFiles = localFiles |> LocalFiles
            WorkloadUnitRunElevated = runAsAdmin
        }
    
    let ``:over`` = None
    let ``:range`` parameterName _ parameterValues = 
        (parameterName, parameterValues)

    let ``:units`` = None
    let ``:arguments`` = None
    
    let ``:workload`` 
            _ workloadUnitTemplates 
            _ commonFiles 
            _ arguments =
        {
            WorkloadUnitTemplates = workloadUnitTemplates
            WorkloadCommonLocalFiles = commonFiles |> LocalFiles
            WorkloadArguments = arguments |> Map.ofSeq |> WorkloadArguments
        }

    let ``:exit`` = SimpleCommand "goto :EXIT"

module internal Sample =
    open DSL

    let CopyOutputToAzure = ``:cmd`` "echo 'Copying output to Azure'"
    let SayHelloWorld = ``:cmd`` "echo 'Hello, world!'"
    let SayGoodbye = ``:cmd`` "echo 'Goodbye'"
    let ReadItemFromQueue = ``:parametric_cmd`` "echo 'Reading from queue'" ``:with_params`` ["%queue_name%"]
    
    let workload =
        ``:workload``
            ``:units`` 
                [
                    (``:unit`` 
                        ``:admin`` true 
                        ``:main`` 
                            [
                                ``:do`` SayHelloWorld
                                ``:try`` 
                                    (``:parametric_cmd`` "echo 'Hello %user%'" ``:with_params`` ["%user%"]) 
{'fraction_non_alphanumeric': 0.12220272049144361, 'fraction_numerical': 0.0, 'mean_word_length': 1.9186939820742637, 'pattern_counts': {'":': 0, '<': 3, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5425284', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1233, 'n_words': 325}