<commit_before>﻿#r "System.Xml"
#r "System.Xml.Linq"
#r "System.IO.Compression"
#r "System.IO.Compression.FileSystem"

using Nake.FS;
using Nake.Run;
using Nake.Log;
using Nake.Env;
using Nake.App;

using System.Linq;
using System.Net;
using System.Xml.Linq;
using System.Diagnostics;
using System.IO.Compression;

const string CoreProject = "Orleankka";
const string AzureProject = "Orleankka.Azure";
const string TestKitProject = "Orleankka.TestKit";
const string FSharpProject = "Orleankka.FSharp";

const string RootPath = "$NakeScriptDirectory$";
const string OutputPath = RootPath + @"\Output";

var PackagePath = @"{OutputPath}\Package";
var ReleasePath = @"{PackagePath}\Release";

var AppVeyor = Var["APPVEYOR"] == "True";
var GES = "EventStore-OSS-Win-v3.0.3";

/// Installs dependencies and builds sources in Debug mode
[Task] void Default()
{
    Install();
    Build();
}

/// Wipeout all build output and temporary build files
[Step] void Clean(string path = OutputPath)
{
    Delete(@"{path}\*.*|-:*.vshost.exe");
    RemoveDir(@"**\bin|**\obj|{path}\*|-:*.vshost.exe");
}

/// Builds sources using specified configuration and output path
[Step] void Build(string config = "Debug", string outDir = OutputPath)
{    
    Clean(outDir);

    Exec(@"$ProgramFiles(x86)$\MSBuild\14.0\Bin\MSBuild.exe", 
          "{CoreProject}.sln /p:Configuration={config};OutDir={outDir};ReferencePath={outDir}");
}

/// Runs unit tests 
[Step] void Test(string outDir = OutputPath, bool slow = false)
{
    Build("Debug", outDir);

    var tests = new FileSet{@"{outDir}\*.Tests.dll"}.ToString(" ");
    var results = @"{outDir}\nunit-test-results.xml";

    try
    {
        Cmd(@"Packages\NUnit.Runners.2.6.3\tools\nunit-console.exe " + 
            @"/xml:{results} /framework:net-4.0 /noshadow /nologo {tests} " +
            (AppVeyor||slow ? "/include:Always,Slow" : ""));
    }
    finally
    {    	
	    if (AppVeyor)
	        new WebClient().UploadFile("https://ci.appveyor.com/api/testresults/nunit/$APPVEYOR_JOB_ID$", results);
	}
}

/// Builds official NuGet packages 
[Step] void Package()
{
    Test(@"{PackagePath}\Debug");
    Build("Package", ReleasePath);

    Pack(CoreProject);    
    Pack(TestKitProject, "core_version={Version(CoreProject)}");
    Pack(AzureProject,   "core_version={Version(CoreProject)}");
    Pack(FSharpProject,  "core_version={Version(CoreProject)}");
}

void Pack(string project, string properties = null)
{
    Cmd(@"Tools\Nuget.exe pack Build\{project}.nuspec -Version {Version(project)} " +
         "-OutputDirectory {PackagePath} -BasePath {RootPath} -NoPackageAnalysis " + 
         (properties != null ? "-Properties {properties}" : ""));
}

/// Publishes package to NuGet gallery
[Step] void Publish(string project)
{
    switch (project)
    {
        case "core": 
            Push(CoreProject); 
            break;
        case "azure": 
            Push(AzureProject); 
            break;
        case "testkit": 
            Push(TestKitProject); 
            break;        
        case "fsharp": 
            Push(FSharpProject); 
            break;
        case "all":
            Push(CoreProject); 
            Push(AzureProject); 
            Push(TestKitProject); 
            Push(FSharpProject);  
            break;      
        default:
            throw new ArgumentException("Available values are: core, azure, testkit, fsharp or all");   
    }
}

void Push(string project)
{
    Cmd(@"Tools\Nuget.exe push {PackagePath}\{project}.{Version(project)}.nupkg $NuGetApiKey$");
}

string Version(string project)
{
    return FileVersionInfo
            .GetVersionInfo(@"{ReleasePath}\{project}.dll")
            .FileVersion;
}

/// Installs dependencies (packages) 
[Task] void Install()
{
    InstallPackages();
    InstallBinaries();
}

void InstallPackages()
{
    Cmd(@"Tools\NuGet.exe restore {CoreProject}.sln");
    Cmd(@"Tools\NuGet.exe install Build/Packages.config -o {RootPath}\Packages");
}

void InstallBinaries()
{
    var packagesDir = @"{RootPath}\Packages";

    if (!Directory.Exists(@"{packagesDir}\{GES}"))
    {
        Info("EventStore binaries were not found. Downloading ...");

        new WebClient().DownloadFile(
            "http://download.geteventstore.com/binaries/{GES}.zip", 
            @"{packagesDir}\{GES}.zip"
        );

        Info("Success! Extracting ...");

        ZipFile.ExtractToDirectory(@"{packagesDir}\{GES}.zip", @"{packagesDir}\{GES}");
        File.Delete(@"{packagesDir}\{GES}.zip");

        Info("Done!");
    }
}

/// Runs software, on which samples are dependent
[Task] void Run(string what = "ges")
{
    var packagesDir = @"{RootPath}\Packages";

    switch (what)
    {
        case "ges":
            Cmd(@"start {packagesDir}/{GES}/EventStore.ClusterNode.exe"); 
            break;
        default:
            throw new ArgumentException("Available values are: ges, ...");   
    }
}<commit_msg>Add azure emulator to local run<commit_after>﻿#r "System.Xml"
#r "System.Xml.Linq"
#r "System.IO.Compression"
#r "System.IO.Compression.FileSystem"

using Nake.FS;
using Nake.Run;
using Nake.Log;
using Nake.Env;
using Nake.App;

using System.Linq;
using System.Net;
using System.Xml.Linq;
using System.Diagnostics;
using System.IO.Compression;

const string CoreProject = "Orleankka";
const string AzureProject = "Orleankka.Azure";
const string TestKitProject = "Orleankka.TestKit";
const string FSharpProject = "Orleankka.FSharp";

const string RootPath = "$NakeScriptDirectory$";
const string OutputPath = RootPath + @"\Output";

var PackagePath = @"{OutputPath}\Package";
var ReleasePath = @"{PackagePath}\Release";

var AppVeyor = Var["APPVEYOR"] == "True";
var GES = "EventStore-OSS-Win-v3.0.3";

/// Installs dependencies and builds sources in Debug mode
[Task] void Default()
{
    Install();
    Build();
}

/// Wipeout all build output and temporary build files
[Step] void Clean(string path = OutputPath)
{
    Delete(@"{path}\*.*|-:*.vshost.exe");
    RemoveDir(@"**\bin|**\obj|{path}\*|-:*.vshost.exe");
}

/// Builds sources using specified configuration and output path
[Step] void Build(string config = "Debug", string outDir = OutputPath)
{    
    Clean(outDir);

    Exec(@"$ProgramFiles(x86)$\MSBuild\14.0\Bin\MSBuild.exe", 
          "{CoreProject}.sln /p:Configuration={config};OutDir={outDir};ReferencePath={outDir}");
}

/// Runs unit tests 
[Step] void Test(string outDir = OutputPath, bool slow = false)
{
    Build("Debug", outDir);

    var tests = new FileSet{@"{outDir}\*.Tests.dll"}.ToString(" ");
    var results = @"{outDir}\nunit-test-results.xml";

    try
    {
        Cmd(@"Packages\NUnit.Runners.2.6.3\tools\nunit-console.exe " + 
            @"/xml:{results} /framework:net-4.0 /noshadow /nologo {tests} " +
            (AppVeyor||slow ? "/include:Always,Slow" : ""));
    }
    finally
    {    	
	    if (AppVeyor)
	        new WebClient().UploadFile("https://ci.appveyor.com/api/testresults/nunit/$APPVEYOR_JOB_ID$", results);
	}
}

/// Builds official NuGet packages 
[Step] void Package()
{
    Test(@"{PackagePath}\Debug");
    Build("Package", ReleasePath);

    Pack(CoreProject);    
    Pack(TestKitProject, "core_version={Version(CoreProject)}");
    Pack(AzureProject,   "core_version={Version(CoreProject)}");
    Pack(FSharpProject,  "core_version={Version(CoreProject)}");
}

void Pack(string project, string properties = null)
{
    Cmd(@"Tools\Nuget.exe pack Build\{project}.nuspec -Version {Version(project)} " +
         "-OutputDirectory {PackagePath} -BasePath {RootPath} -NoPackageAnalysis " + 
         (properties != null ? "-Properties {properties}" : ""));
}

/// Publishes package to NuGet gallery
[Step] void Publish(string project)
{
    switch (project)
    {
        case "core": 
            Push(CoreProject); 
            break;
        case "azure": 
            Push(AzureProject); 
            break;
        case "testkit": 
            Push(TestKitProject); 
            break;        
        case "fsharp": 
            Push(FSharpProject); 
            break;
        case "all":
            Push(CoreProject); 
            Push(AzureProject); 
            Push(TestKitProject); 
            Push(FSharpProject);  
            break;      
        default:
            throw new ArgumentException("Available values are: core, azure, testkit, fsharp or all");   
    }
}

void Push(string project)
{
    Cmd(@"Tools\Nuget.exe push {PackagePath}\{project}.{Version(project)}.nupkg $NuGetApiKey$");
}

string Version(string project)
{
    return FileVersionInfo
            .GetVersionInfo(@"{ReleasePath}\{project}.dll")
            .FileVersion;
}

/// Installs dependencies (packages) 
[Task] void Install()
{
    InstallPackages();
    InstallBinaries();
}

void InstallPackages()
{
    Cmd(@"Tools\NuGet.exe restore {CoreProject}.sln");
    Cmd(@"Tools\NuGet.exe install Build/Packages.config -o {RootPath}\Packages");
}

void InstallBinaries()
{
    var packagesDir = @"{RootPath}\Packages";

    if (!Directory.Exists(@"{packagesDir}\{GES}"))
    {
        Info("EventStore binaries were not found. Downloading ...");

        new WebClient().DownloadFile(
            "http://download.geteventstore.com/binaries/{GES}.zip", 
            @"{packagesDir}\{GES}.zip"
        );

        Info("Success! Extracting ...");

        ZipFile.ExtractToDirectory(@"{packagesDir}\{GES}.zip", @"{packagesDir}\{GES}");
        File.Delete(@"{packagesDir}\{GES}.zip");

        Info("Done!");
    }
}

/// Runs 3rd party software, on which samples are dependent upon
[Task] void Run(string what = "all")
{
    switch (what)
    {
        case "all":
            RunAzure();
            RunGES();
            break;            
        case "ges":
            RunGES();
            break;
        case "azure":
            RunAzure(); 
            break;            
        default:
            throw new ArgumentException("Available values are: all, ges, azure ...");
    }
}

void RunGES() 
{
    if (IsRunning("EventStore.ClusterNode"))
        return;

    Info("Starting local GES node ...");
    Exec(@"{RootPath}/Packages/{GES}/EventStore.ClusterNode.exe", "");
}

void RunAzure()
{
    if (IsRunning("AzureStorageEmulator"))
        return;

    Info("Starting storage emulator ...");
    Exec(@"C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe", "start");
}

bool IsRunning(string processName)
{
    var processes = Process.GetProcesses().Select(x => x.ProcessName).ToList();
    return (processes.Any(p => p == processName));
}
{'fraction_non_alphanumeric': 0.15749669124598223, 'fraction_numerical': 0.00274153904329741, 'mean_word_length': 2.8595403137541044, 'pattern_counts': {'":': 14, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '269006', 'n_tokens_mistral': 3472, 'n_tokens_neox': 3247, 'n_words': 682}