<commit_before>﻿using System;
using System.IO;
using System.Xml;

namespace ProjectsGenerator
{
    class Program
    {
        private static readonly string ProjectName = "Lambda2Js";

        static void Main(string[] args)
        {
            Console.WriteLine($"Environment.CurrentDirectory = {Environment.CurrentDirectory}");

            // TEST PROJECTS:
            //
            // Test projects are generated from the main multi-targeted test project:
            // "{ProjectName}.Tests.csproj" file.

            {

                var l2jsTests = new XmlDocument();
                l2jsTests.Load($"../{ProjectName}.Tests/{ProjectName}.Tests.csproj");

                var targetsElement = l2jsTests.SelectNodes("//TargetFrameworks");
                Console.WriteLine(targetsElement[0].InnerText);
                var targets = targetsElement[0].InnerText.Split(";");
                foreach (var target in targets)
                {
                    if (File.Exists($"../{ProjectName}.Tests/{ProjectName}.Tests.{target}.csproj"))
                        continue;

                    var l2jsTestNew = (XmlDocument)l2jsTests.Clone();
                    var node = l2jsTestNew.SelectSingleNode("//TargetFrameworks");
                    var targetElement = l2jsTestNew.CreateElement("TargetFramework");
                    targetElement.InnerText = target;
                    node.ParentNode.ReplaceChild(targetElement, node);
                    l2jsTestNew.Save($"../{ProjectName}.Tests/{ProjectName}.Tests.{target}.csproj");
                }

            }

            // SIGNED ASSEMBLY
            //
            // Signed assembly is generated from the main "{ProjectName}.csproj" file.

            {

                var l2js = new XmlDocument();
                l2js.Load($"../{ProjectName}/{ProjectName}.csproj");

                var sig = (XmlDocument)l2js.Clone();
                var sigMain = sig.SelectSingleNode("//TargetFrameworks").ParentNode;
                var ver = sigMain.SelectSingleNode("Version").InnerText;

                sigMain.SelectSingleNode("AssemblyVersion").InnerText = $"{ver}.0";
                sigMain.SelectSingleNode("FileVersion").InnerText = $"{ver}.0";
                sigMain.SelectSingleNode("PackageId").InnerText += ".Signed";
                sigMain.AppendChild(sig.CreateElement("SignAssembly").With(x => x.InnerText = "true"));
                sigMain.AppendChild(sig.CreateElement("AssemblyOriginatorKeyFile").With(x => x.InnerText = $@"..\{ProjectName}.snk"));

                if (sigMain.SelectSingleNode("RootNamespace") == null)
                    sigMain.AppendChild(sig.CreateElement("RootNamespace").With(x => x.InnerText = $"{ProjectName}"));

                if (sigMain.SelectSingleNode("AssemblyName") == null)
                    sigMain.AppendChild(sig.CreateElement("AssemblyName").With(x => x.InnerText = $"{ProjectName}.Signed"));
                else
                    sigMain.SelectSingleNode("AssemblyName").InnerText += ".Signed";

                foreach (XmlNode doc in sig.SelectNodes("//DocumentationFile"))
                    doc.InnerText = doc.InnerText.Replace($"{ProjectName}.xml", $"{ProjectName}.Signed.xml");

                sig.Save($"../{ProjectName}/{ProjectName}.Signed.csproj");

            }

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
    }

    static class ObjectExtensions
    {
        public static T With<T>(this T obj, Action<T> action)
        {
            action(obj);
            return obj;<commit_msg>Visual Studio seems to have changed the directory to run .Net Core 2: before - run from csproj dir; now - run from \bin dir<commit_after>﻿using System;
using System.IO;
using System.Xml;

namespace ProjectsGenerator
{
    class Program
    {
        private static readonly string ProjectName = "Lambda2Js";

        static void Main(string[] args)
        {
            // TEST PROJECTS:
            //
            // Test projects are generated from the main multi-targeted test project:
            // "{ProjectName}.Tests.csproj" file.

            {

                var testsProjXml = new XmlDocument();
                var pathProj = $"../{ProjectName}.Tests/{ProjectName}.Tests.csproj";

                FindAndSetCurrentPath(pathProj);
                Console.WriteLine($"Environment.CurrentDirectory = {Environment.CurrentDirectory}");

                testsProjXml.Load(pathProj);

                var targetsElement = testsProjXml.SelectNodes("//TargetFrameworks");
                Console.WriteLine(targetsElement[0].InnerText);
                var targets = targetsElement[0].InnerText.Split(";");
                foreach (var target in targets)
                {
                    if (File.Exists($"../{ProjectName}.Tests/{ProjectName}.Tests.{target}.csproj"))
                        continue;

                    var testProjXml_2 = (XmlDocument)testsProjXml.Clone();
                    var node = testProjXml_2.SelectSingleNode("//TargetFrameworks");
                    var targetElement = testProjXml_2.CreateElement("TargetFramework");
                    targetElement.InnerText = target;
                    node.ParentNode.ReplaceChild(targetElement, node);
                    testProjXml_2.Save($"../{ProjectName}.Tests/{ProjectName}.Tests.{target}.csproj");
                }

            }

            // SIGNED ASSEMBLY
            //
            // Signed assembly is generated from the main "{ProjectName}.csproj" file.

            {

                var projXml = new XmlDocument();
                projXml.Load($"../{ProjectName}/{ProjectName}.csproj");

                var sig = (XmlDocument)projXml.Clone();
                var sigMain = sig.SelectSingleNode("//TargetFrameworks").ParentNode;
                var ver = sigMain.SelectSingleNode("Version").InnerText;

                sigMain.SelectSingleNode("AssemblyVersion").InnerText = $"{ver}.0";
                sigMain.SelectSingleNode("FileVersion").InnerText = $"{ver}.0";
                sigMain.SelectSingleNode("PackageId").InnerText += ".Signed";
                sigMain.AppendChild(sig.CreateElement("SignAssembly").With(x => x.InnerText = "true"));
                sigMain.AppendChild(sig.CreateElement("AssemblyOriginatorKeyFile").With(x => x.InnerText = $@"..\{ProjectName}.snk"));

                if (sigMain.SelectSingleNode("RootNamespace") == null)
                    sigMain.AppendChild(sig.CreateElement("RootNamespace").With(x => x.InnerText = $"{ProjectName}"));

                if (sigMain.SelectSingleNode("AssemblyName") == null)
                    sigMain.AppendChild(sig.CreateElement("AssemblyName").With(x => x.InnerText = $"{ProjectName}.Signed"));
                else
                    sigMain.SelectSingleNode("AssemblyName").InnerText += ".Signed";

                foreach (XmlNode doc in sig.SelectNodes("//DocumentationFile"))
                    doc.InnerText = doc.InnerText.Replace($"{ProjectName}.xml", $"{ProjectName}.Signed.xml");

                sig.Save($"../{ProjectName}/{ProjectName}.Signed.csproj");

            }

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }

        private static void FindAndSetCurrentPath(string pathProj)
        {
            while (true)
            {
                try
                {
                    if (File.Exists(pathProj))
                        break;
                }
                catch (Exception)
                {
                }

                Environment.CurrentDirectory = Path.GetDirectoryName(Environment.CurrentDirectory);
            }
        }
    }

    static class ObjectExtensions
    {
        public static T With<T>(this T obj, Action<T> action)
        {
            action(obj);
            return obj;
{'fraction_non_alphanumeric': 0.12398373983739837, 'fraction_numerical': 0.0033028455284552847, 'mean_word_length': 1.851503078594712, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '747096', 'n_tokens_mistral': 2076, 'n_tokens_neox': 1925, 'n_words': 342}