Exemple #1
0
        public void TestBasic()
        {
            var yaml = @"Id: Google.Chrome
Name: Chrome
Publisher: Google
Version: 78.0.3904.87
Homepage: https://www.google.com/chrome/
InstallerType: MSI
AppMoniker: chrome
License: Google Chrome and Chrome OS Additional Terms of Service
LicenseUrl: https://www.google.com/chrome/terms/

# ======================= Installers  ==================


Installers:
  - Arch: x64
    Url: https://dl.google.com/edgedl/chrome/install/GoogleChromeStandaloneEnterprise64.msi
    Sha256: F17FDA159EC69C0F9E96656642E5F2A5DE547BED784978A354C51D70E88C93DC
    Language: en-US";


            var reader = new YamlReader();

            using TextReader textReader = new StringReader(yaml);
            var deserialized = reader.Read(textReader);
            var writer       = new YamlWriter();

            using TextWriter textWriter = new StringWriter();
            writer.Write(deserialized, textWriter);
        }
Exemple #2
0
        public void RoundTrip_does_not_report_parsing_errors()
        {
            var builder = new StringBuilder();

            using (var writer = new StringWriter(builder))
            {
                YamlWriter.Write(writer, _objectUnderTest);
            }

            Assert.That(builder.ToString(), Does.Contain("parsingErrorsDetected: false"));
        }
Exemple #3
0
        private static string CreateYaml(File file)
        {
            var builder = new StringBuilder();

            using (var writer = new StringWriter(builder))
            {
                YamlWriter.Write(writer, file);
            }

            var yaml = builder.ToString();

            return(yaml);
        }
        public static async Task <int> Main(string[] args)
        {
            // check for GMaster or PlasticSCM or SemanticMerge arguments (to allow debugging without the tools)
            if (args.Length == 2)
            {
                var shell    = args[0]; // reserved for future usage
                var flagFile = args[1];

                SystemFile.WriteAllBytes(flagFile, new byte[] { 0x42 });
            }

            var watch   = Stopwatch.StartNew();
            var gcWatch = Stopwatch.StartNew();

            while (true)
            {
                var inputFile = await Console.In.ReadLineAsync();

                if (inputFile == null || "end".Equals(inputFile, StringComparison.OrdinalIgnoreCase))
                {
                    // session is done
                    Tracer.Trace($"Terminating as session was ended (instance {InstanceId:B})");
                    return(0);
                }

                var encodingToUse = await Console.In.ReadLineAsync();

                var outputFile = await Console.In.ReadLineAsync();

                try
                {
                    try
                    {
                        watch.Restart();

                        var file = Parser.Parse(inputFile, encodingToUse);

                        using (var writer = SystemFile.CreateText(outputFile))
                        {
                            YamlWriter.Write(writer, file);
                        }

                        var parseErrors = file.ParsingErrorsDetected == true;
                        if (parseErrors)
                        {
                            var parsingError = file.ParsingErrors[0];
                            Tracer.Trace(parsingError.ErrorMessage);
                            Tracer.Trace(parsingError.Location);
                        }

                        // clean-up after big files
                        if (IsBigFile(inputFile))
                        {
                            gcWatch.Restart();

                            GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
                            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, false, true);

                            Tracer.Trace($"Garbage collection took {gcWatch.Elapsed:s\\.fff} secs  (instance {InstanceId:B})");
                        }

                        Console.WriteLine(parseErrors ? "KO" : "OK");
                    }
                    finally
                    {
                        Tracer.Trace($"Parsing took {watch.Elapsed:s\\.fff} secs  (instance {InstanceId:B})");
                    }
                }
                catch (Exception ex)
                {
                    Tracer.Trace($"Exception: {ex}");

                    var stackTraceLines = ex.StackTrace?.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) ?? Enumerable.Empty <string>();
                    foreach (var stackTraceLine in stackTraceLines)
                    {
                        Tracer.Trace(stackTraceLine);
                    }

                    Console.WriteLine("KO");

                    throw;
                }
            }
        }
        public static async Task <int> Main(string[] args)
        {
            // check for GMaster or PlasticSCM or SemanticMerge arguments (to allow debugging without the tools)
            if (args.Length == 2)
            {
                var shell    = args[0]; // reserved for future usage
                var flagFile = args[1];

                SystemFile.WriteAllBytes(flagFile, new byte[] { 0x42 });
            }

            var watch   = Stopwatch.StartNew();
            var gcWatch = Stopwatch.StartNew();

            while (true)
            {
                var inputFile = await Console.In.ReadLineAsync();

                if (inputFile == null || "end".Equals(inputFile, StringComparison.OrdinalIgnoreCase))
                {
                    // session is done
                    Tracer.Trace($"Terminating as session was ended (instance {InstanceId:B})");
                    return(0);
                }

                var encodingToUse = await Console.In.ReadLineAsync();

                var outputFile = await Console.In.ReadLineAsync();

                try
                {
                    var parseErrors = false;
                    try
                    {
                        watch.Restart();

                        // we find a flavor here, as we want to support different main methods, based on file ending
                        var flavor = XmlFlavorFinder.Find(inputFile);

                        var file = Parser.Parse(inputFile, encodingToUse, flavor);

                        using (var writer = SystemFile.CreateText(outputFile))
                        {
                            YamlWriter.Write(writer, file);
                        }

                        parseErrors = file.ParsingErrorsDetected == true;
                        if (parseErrors)
                        {
                            var parsingError = file.ParsingErrors[0];
                            Tracer.Trace(parsingError.ErrorMessage);
                            Tracer.Trace(parsingError.Location);
                        }

                        // clean-up after big files
                        if (IsBigFile(inputFile))
                        {
                            gcWatch.Restart();

                            GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
                            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, false, true);

                            Tracer.Trace($"Garbage collection took {gcWatch.Elapsed:s\\.fff} secs  (instance {InstanceId:B})");
                        }

                        Console.WriteLine(parseErrors ? "KO" : "OK");
                    }
                    finally
                    {
                        Tracer.Trace($"Parsing took {watch.Elapsed:s\\.fff} secs  (instance {InstanceId:B}), errors found: {parseErrors}");
                    }
                }
                catch (Exception ex)
                {
                    Tracer.Trace($"Exception: {ex}", ex);

                    Console.WriteLine("KO");

                    return(0);
                }
            }
        }