<commit_before>﻿using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Xml;
using YamlDotNet.RepresentationModel;

namespace UpdateUtil
{
    abstract class FileTypeHandlerBase
    {
        public abstract void UpdateFiles(string prefix, VersionInfo versionInfo);
    }

    class SdkProjectFileTypeHandler : FileTypeHandlerBase
    {
        public override void UpdateFiles(string prefix, VersionInfo versionInfo)
        {
            NavigationHelper.GoUp(4);
            var version = versionInfo.VersionCore;
            var projectFiles =
                Directory.GetFiles(Directory.GetCurrentDirectory(), "*.csproj", SearchOption.AllDirectories);
            NavigationHelper.Cd("devops");
            NavigationHelper.NavigateToBin();

            foreach (var projectFile in projectFiles)
            {
                if (projectFile.Contains("templatepack"))
                {
                    continue;
                }
                var doc = new XmlDocument();
                doc.Load(projectFile);
                var firstPropertyGroup = doc.GetElementsByTagName("Project")[0]["PropertyGroup"];
                var targetFrameworkElement = firstPropertyGroup?.GetElementsByTagName("TargetFramework")[0];
                if (targetFrameworkElement == null)
                {
                    continue;
                }

                if (!targetFrameworkElement.InnerText.StartsWith("netcoreapp") &&
                    !targetFrameworkElement.InnerText.StartsWith("net5") &&
                    !targetFrameworkElement.InnerText.StartsWith("netstandard"))
                {
                    continue;
                }
                var versionElement = doc.GetElementsByTagName("Project")[0]["PropertyGroup"].GetElementsByTagName("Version")[0];
                if (versionElement != null)
                {
                    versionElement.InnerText = version;
                }
                doc.Save(projectFile);
            }
        }
    }

    class AssemblyInfoFileTypeHandler : FileTypeHandlerBase
    {
        public override void UpdateFiles(string prefix, VersionInfo versionInfo)
        {
            NavigationHelper.GoUp(4);
            var assemblyInfoFiles =
                Directory.GetFiles(Directory.GetCurrentDirectory(), "AssemblyInfo.cs", SearchOption.AllDirectories)
                    .Where(t => !t.Contains("obj") && t.Contains(prefix));
            NavigationHelper.Cd("devops");
            NavigationHelper.NavigateToBin();
            var ps1File = @"..\..\patch-assembly-info.ps1";

            foreach (var assemblyInfoFile in assemblyInfoFiles)
            {
                var startInfo = new ProcessStartInfo
                {
                    FileName = "powershell.exe",
                    Arguments = $"-NoProfile -ExecutionPolicy unrestricted -File \"{ps1File}\" \"{assemblyInfoFile}\" \"{versionInfo.VersionCore}\"",<commit_msg>chore: minor<commit_after>﻿using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Xml;
using YamlDotNet.RepresentationModel;

namespace UpdateUtil
{
    abstract class FileTypeHandlerBase
    {
        public abstract void UpdateFiles(string prefix, VersionInfo versionInfo);
    }

    class SdkProjectFileTypeHandler : FileTypeHandlerBase
    {
        public override void UpdateFiles(string prefix, VersionInfo versionInfo)
        {
            NavigationHelper.GoUp(4);
            var version = versionInfo.VersionCore;
            var projectFiles =
                Directory.GetFiles(Directory.GetCurrentDirectory(), "*.csproj", SearchOption.AllDirectories);
            NavigationHelper.Cd("devops");
            NavigationHelper.NavigateToBin();

            foreach (var projectFile in projectFiles)
            {
                if (projectFile.Contains("templatepack"))
                {
                    continue;
                }
                var doc = new XmlDocument();
                doc.Load(projectFile);
                var firstPropertyGroup = doc.GetElementsByTagName("Project")[0]["PropertyGroup"];
                var targetFrameworkElement = firstPropertyGroup?.GetElementsByTagName("TargetFramework")[0];
                if (targetFrameworkElement == null)
                {
                    continue;
                }

                if (!targetFrameworkElement.InnerText.StartsWith("netcoreapp") &&
                    !targetFrameworkElement.InnerText.StartsWith("net5") &&
                    !targetFrameworkElement.InnerText.StartsWith("netstandard"))
                {
                    continue;
                }
                var versionElement = doc.GetElementsByTagName("Project")[0]["PropertyGroup"].GetElementsByTagName("Version")[0];
                if (versionElement != null)
                {
                    versionElement.InnerText = version;
                }
                doc.Save(projectFile);
            }
        }
    }

    class AssemblyInfoFileTypeHandler : FileTypeHandlerBase
    {
        public override void UpdateFiles(string prefix, VersionInfo versionInfo)
        {
            NavigationHelper.GoUp(4);
            var assemblyInfoFiles =
                Directory.GetFiles(Directory.GetCurrentDirectory(), "AssemblyInfo.cs", SearchOption.AllDirectories)
                    .Where(t => !t.Contains("obj"));
            NavigationHelper.Cd("devops");
            NavigationHelper.NavigateToBin();
            var ps1File = @"..\..\patch-assembly-info.ps1";

            foreach (var assemblyInfoFile in assemblyInfoFiles)
            {
                var startInfo = new ProcessStartInfo
                {
                    FileName = "powershell.exe",
                    Arguments = $"-NoProfile -ExecutionPolicy unrestricted -File \"{ps1File}\" \"{assemblyInfoFile}\" \"{versionInfo.VersionCore}\"",
{'fraction_non_alphanumeric': 0.0939047293836435, 'fraction_numerical': 0.003414717432132491, 'mean_word_length': 1.8786240786240787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4618908', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1318, 'n_words': 245}