Beispiel #1
0
        static async Task UpgradeLatest(SolutionInfo solution)
        {
            //download templates and traditional bridge source
            //replace templates and traditional bridge source
            var traditionalBridgeFiles = Directory.GetFiles(
                solution.SolutionDir,
                "RoutineDispatcher.dbl",
                SearchOption.AllDirectories);

            var templateFiles = Directory.GetFiles(
                solution.SolutionDir,
                "*.tpl",
                SearchOption.AllDirectories);

            var hasTraditionalBridge    = (traditionalBridgeFiles?.Length ?? 0) > 0;
            var traditionalBridgeFolder = hasTraditionalBridge ? Path.GetDirectoryName(traditionalBridgeFiles[0]) : string.Empty;

            var distinctTemplateFolders = templateFiles.Select(fileName => Path.GetDirectoryName(fileName)).Distinct().OrderBy(folder => folder.Length).ToList();

            if (distinctTemplateFolders.Count > 0)
            {
                Console.WriteLine("Updating template files in {0}", distinctTemplateFolders.First());
                foreach (var distinctFolder in distinctTemplateFolders.Skip(1))
                {
                    Console.WriteLine("Found template files in {0}", distinctFolder);
                }
            }

            if (hasTraditionalBridge)
            {
                Console.WriteLine("Updating traditional bridge files in {0}", traditionalBridgeFolder);
            }

            await GitHubRelease.GetAndUnpackLatest(hasTraditionalBridge, traditionalBridgeFolder, distinctTemplateFolders, solution);

            UpgradeProjects(solution);
        }
Beispiel #2
0
        static async Task UpgradeLatest(SolutionInfo solution)
        {
            //download templates and traditional bridge source
            //replace templates and traditional bridge source
            var traditionalBridgeFiles = Directory.GetFiles(
                solution.SolutionDir,
                "RoutineDispatcher.dbl",
                SearchOption.AllDirectories);

            var templateFiles = Directory.GetFiles(
                solution.SolutionDir,
                "*.tpl",
                SearchOption.AllDirectories);

            var hasTraditionalBridge    = (traditionalBridgeFiles?.Length ?? 0) > 0;
            var traditionalBridgeFolder = hasTraditionalBridge ? Path.GetDirectoryName(traditionalBridgeFiles[0]) : string.Empty;

            var distinctTemplateFolders = templateFiles.Select(fileName => Path.GetDirectoryName(fileName)).Distinct().OrderBy(folder => folder.Length).ToList();

            if (distinctTemplateFolders.Count > 0)
            {
                Console.WriteLine("Updating template files in {0}", distinctTemplateFolders.First());
                foreach (var distinctFolder in distinctTemplateFolders.Skip(1))
                {
                    Console.WriteLine("Found template files in {0}", distinctFolder);
                }
            }

            if (hasTraditionalBridge)
            {
                Console.WriteLine("Updating traditional bridge files in {0}", traditionalBridgeFolder);
            }

            var client           = new HttpClient();
            var targeturl        = $"https://github.com/Synergex/HarmonyCore/archive/{CurrentVersionTag}.zip";
            var sourceDistStream = await client.GetStreamAsync(targeturl);

            var normalizer = new Regex(@"\r\n|\n\r|\n|\r", RegexOptions.Compiled);

            using (var zip = new ZipArchive(sourceDistStream, ZipArchiveMode.Read))
            {
                foreach (var entry in zip.Entries)
                {
                    if (entry.CompressedLength > 0 && entry.FullName.Contains("Templates"))
                    {
                        if (distinctTemplateFolders.Count > 0)
                        {
                            var targetFileName = Path.Combine(distinctTemplateFolders.First(), entry.FullName.Replace($"HarmonyCore-{CurrentVersionTag}/Templates/", "").Replace("/", "\\").Replace("\\\\", "\\"));

                            if (targetFileName.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
                            {
                                continue;
                            }

                            Directory.CreateDirectory(Path.GetDirectoryName(targetFileName));
                            if (File.Exists(targetFileName))
                            {
                                File.Delete(targetFileName);
                            }

                            using (var stream = entry.Open())
                            {
                                using (var reader = new StreamReader(stream))
                                {
                                    File.WriteAllText(targetFileName, normalizer.Replace(reader.ReadToEnd(), "\r\n"));
                                }
                            }
                        }
                    }
                    else if (entry.CompressedLength > 0 && hasTraditionalBridge && entry.FullName.StartsWith($"HarmonyCore-{CurrentVersionTag}/TraditionalBridge/"))
                    {
                        var targetFileName = Path.Combine(traditionalBridgeFolder, Path.GetFileName(entry.FullName.Replace($"HarmonyCore-{CurrentVersionTag}", "").Replace("/", "\\").Replace("\\\\", "\\")));
                        if (File.Exists(targetFileName))
                        {
                            File.Delete(targetFileName);
                        }

                        using (var stream = entry.Open())
                        {
                            using (var reader = new StreamReader(stream))
                            {
                                File.WriteAllText(targetFileName, normalizer.Replace(reader.ReadToEnd(), "\r\n"));
                            }
                        }
                    }
                }
            }

            UpgradeProjects(solution);
        }
        public static async Task GetAndUnpackLatest(bool hasTraditionalBridge, string traditionalBridgeFolder, List <string> distinctTemplateFolders, SolutionInfo solution)
        {
            var client        = new HttpClient();
            var octoClient    = new Octokit.GitHubClient(new Octokit.ProductHeaderValue("Synergex"));
            var latestRelease = await octoClient.Repository.Release.GetLatest("Synergex", "HarmonyCore");

            var CurrentVersionTag = latestRelease.TagName;

            var targeturl        = $"https://github.com/Synergex/HarmonyCore/archive/{CurrentVersionTag}.zip";
            var sourceDistStream = await client.GetStreamAsync(targeturl);

            var normalizer = new Regex(@"\r\n|\n\r|\n|\r", RegexOptions.Compiled);

            using (var zip = new ZipArchive(sourceDistStream, ZipArchiveMode.Read))
            {
                foreach (var entry in zip.Entries)
                {
                    if (entry.CompressedLength > 0 && entry.FullName.StartsWith($"HarmonyCore-{CurrentVersionTag}/Templates/"))
                    {
                        if (distinctTemplateFolders.Count > 0)
                        {
                            var targetFileName = Path.Combine(distinctTemplateFolders.First(), entry.FullName.Replace($"HarmonyCore-{CurrentVersionTag}/Templates/", "", StringComparison.CurrentCultureIgnoreCase).Replace("/", "\\").Replace("\\\\", "\\"));

                            if (targetFileName.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
                            {
                                continue;
                            }

                            Directory.CreateDirectory(Path.GetDirectoryName(targetFileName));
                            if (File.Exists(targetFileName))
                            {
                                File.Delete(targetFileName);
                            }

                            using (var stream = entry.Open())
                            {
                                using (var reader = new StreamReader(stream))
                                {
                                    File.WriteAllText(targetFileName, normalizer.Replace(reader.ReadToEnd(), "\r\n"));
                                }
                            }
                        }
                    }
                    else if (entry.CompressedLength > 0 && hasTraditionalBridge && entry.FullName.StartsWith($"HarmonyCore-{CurrentVersionTag}/TraditionalBridge/") && entry.FullName.EndsWith(".dbl"))
                    {
                        var targetFileName = Path.Combine(traditionalBridgeFolder, Path.GetFileName(entry.FullName.Replace($"HarmonyCore-{CurrentVersionTag}", "", StringComparison.CurrentCultureIgnoreCase).Replace("/", "\\").Replace("\\\\", "\\")));
                        if (File.Exists(targetFileName))
                        {
                            File.Delete(targetFileName);
                        }

                        using (var stream = entry.Open())
                        {
                            using (var reader = new StreamReader(stream))
                            {
                                File.WriteAllText(targetFileName, normalizer.Replace(reader.ReadToEnd(), "\r\n"));
                            }
                        }
                    }
                    else if (entry.CompressedLength > 0 && entry.FullName == $"HarmonyCore-{CurrentVersionTag}/regen.bat")
                    {
                        var targetFileName = Path.Combine(solution.SolutionDir, "regen.bat.example");
                        if (File.Exists(targetFileName))
                        {
                            File.Delete(targetFileName);
                        }

                        using (var stream = entry.Open())
                        {
                            using (var reader = new StreamReader(stream))
                            {
                                File.WriteAllText(targetFileName, normalizer.Replace(reader.ReadToEnd(), "\r\n"));
                            }
                        }
                    }

                    else if (entry.CompressedLength > 0 && entry.FullName == $"HarmonyCore-{CurrentVersionTag}/UserDefinedTokens.tkn")
                    {
                        var targetFileName = Path.Combine(solution.SolutionDir, "UserDefinedTokens.tkn.example");
                        if (File.Exists(targetFileName))
                        {
                            File.Delete(targetFileName);
                        }

                        using (var stream = entry.Open())
                        {
                            using (var reader = new StreamReader(stream))
                            {
                                File.WriteAllText(targetFileName, normalizer.Replace(reader.ReadToEnd(), "\r\n"));
                            }
                        }
                    }
                }
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var(handle, mode) = GetConsoleState();
            var versionOverride = Environment.GetEnvironmentVariable("HC_VERSION");

            if (!string.IsNullOrWhiteSpace(versionOverride))
            {
                HCBuildVersion = versionOverride;
            }

            LatestNugetReferences = new Dictionary <string, string>(StringComparer.CurrentCultureIgnoreCase)
            {
                { "Harmony.Core", HCBuildVersion },
                { "HarmonyCore.CodeDomProvider", CodeDomProviderVersion },
                { "Harmony.Core.EF", HCBuildVersion },
                { "Harmony.Core.OData", HCBuildVersion },
                { "Harmony.Core.AspNetCore", HCBuildVersion },
                { "Synergex.SynergyDE.synrnt", "11.1.1070" },
                { "Synergex.SynergyDE.Build", BuildPackageVersion },
                { "Microsoft.AspNetCore.Mvc.NewtonsoftJson", "3.1.6" },
                { "Microsoft.AspNetCore.Mvc.Testing", "3.1.6" },
                { "Microsoft.Extensions.DependencyInjection", "3.1.6" },
                { "Microsoft.Extensions.Logging.Console", "3.1.6" },
                { "Microsoft.AspNetCore.SignalR.Client", "3.1.6" },
                { "Microsoft.EntityFrameworkCore", "3.1.6" },
                { "IdentityServer4.AccessTokenValidation", "3.0.1" },
                { "Microsoft.AspNetCore.OData", "7.4.1" },
                { "Microsoft.OData.Core", "7.7.0" },
                { "Microsoft.AspNetCore.JsonPatch", "3.1.6" },
                { "Microsoft.VisualStudio.Threading", "16.6.13" },
                { "StreamJsonRpc", "2.4.48" },
                { "IdentityModel", "4.1.1" },
                { "Microsoft.OData.Edm", "7.7.0" },
                { "Microsoft.Spatial", "7.7.0" },
                { "Swashbuckle.AspNetCore", "5.5.1" },
                { "SSH.NET", "2016.1.0" },
                { "Microsoft.AspNetCore.Mvc.Versioning", "4.1.1" },
                { "Microsoft.AspNetCore.OData.Versioning.ApiExplorer", "4.1.1" },
                { "Nito.AsyncEx", "5.0.0" },
                { "System.Linq.Dynamic.Core", "1.1.8" },
                { "system.text.encoding.codepages", "4.7.1" },
            };

            var solutionDir = Environment.GetEnvironmentVariable("SolutionDir") ?? Environment.CurrentDirectory;

            Console.WriteLine("Scanning '{0}' for HarmonyCore project files", solutionDir);
            string[] synprojFiles = new string[0];
            try
            {
                synprojFiles = Directory.GetFiles(
                    solutionDir,
                    "*.synproj",
                    SearchOption.AllDirectories);
            }
            catch (Exception ex)
            {
                Console.WriteLine("error while searching for project files: {0}", ex.Message);
                return;
            }
            var solutionInfo = new SolutionInfo(synprojFiles, solutionDir);

            ResetConsoleMode(handle, mode);

            _ = Parser.Default.ParseArguments <UpgradeLatestOptions, CodegenListOptions, CodegenAddOptions, CodegenRemoveOptions, RpsOptions, RegenOptions, XMLGenOptions, GUIOptions>(args)
                .MapResult <UpgradeLatestOptions, CodegenListOptions, CodegenAddOptions, CodegenRemoveOptions, RpsOptions, RegenOptions, XMLGenOptions, GUIOptions, int>(

                (UpgradeLatestOptions opts) =>
            {
                Console.WriteLine("This utility will make significant changes to projects and other source files in your Harmony Core development environment. Before running this tool we recommend checking the current state of your development environment into your source code repository, taking a backup copy of the environment if you don't use source code control.\n\n");


                Console.WriteLine("Type YES to proceed: ");
                if (string.Compare(Console.ReadLine(), "YES", true) != 0)
                {
                    Console.WriteLine("exiting without changes");
                    return(1);
                }


                if (opts.ProjectOnly)
                {
                    UpgradeProjects(solutionInfo);
                }
                else
                {
                    UpgradeLatest(solutionInfo).Wait();
                }
                return(0);
            },
                new CodegenCommand(solutionInfo).List,
                new CodegenCommand(solutionInfo).Add,
                new CodegenCommand(solutionInfo).Remove,
                new RPSCommand(solutionInfo).Run,
                new RegenCommand(solutionInfo).Run,
                new XMLGenCommand().Run,
                new GUICommand(solutionInfo).Run,
                errs =>
            {
                foreach (var error in errs)
                {
                    Console.WriteLine(error);
                }
                return(1);
            });
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            var  handle      = GetStdHandle(STD_INPUT_HANDLE);
            uint currentMode = 0;

            GetConsoleMode(handle, out currentMode);

            var solutionDir = Environment.GetEnvironmentVariable("SolutionDir") ?? Environment.CurrentDirectory;

            Console.WriteLine("Scanning '{0}' for HarmonyCore project files", solutionDir);
            string[] synprojFiles = new string[0];
            try
            {
                synprojFiles = Directory.GetFiles(
                    solutionDir,
                    "*.synproj",
                    SearchOption.AllDirectories);
            }
            catch (Exception ex)
            {
                Console.WriteLine("error while searching for project files: {0}", ex.Message);
                return;
            }
            var solutionInfo = new SolutionInfo(synprojFiles, solutionDir);

            if (!SetConsoleMode(handle, currentMode))
            {
                throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
            }


            CommandLine.Parser.Default.ParseArguments <UpgradeLatestOptions, CodegenListOptions, CodegenAddOptions, CodegenRemoveOptions, RpsOptions, RegenOptions>(args)
            .MapResult <UpgradeLatestOptions, CodegenListOptions, CodegenAddOptions, CodegenRemoveOptions, RpsOptions, RegenOptions, int>(

                (UpgradeLatestOptions opts) =>
            {
                Console.WriteLine("This utility will make significant changes to projects and other source files in your Harmony Core development environment. Before running this tool we recommend checking the current state of your development environment into your source code repository, taking a backup copy of the environment if you don't use source code control.\n\n");


                Console.WriteLine("Type YES to proceed: ");
                if (string.Compare(Console.ReadLine(), "YES", true) != 0)
                {
                    Console.WriteLine("exiting without changes");
                    return(1);
                }


                if (opts.ProjectOnly)
                {
                    UpgradeProjects(solutionInfo);
                }
                else
                {
                    UpgradeLatest(solutionInfo).Wait();
                }
                return(0);
            },
                new CodegenCommand(solutionInfo).List,
                new CodegenCommand(solutionInfo).Add,
                new CodegenCommand(solutionInfo).Remove,
                new RPSCommand(solutionInfo).Run,
                new RegenCommand(solutionInfo).Run,
                errs =>
            {
                foreach (var error in errs)
                {
                    Console.WriteLine(error);
                }
                return(1);
            });
        }