Example #1
0
        public static YamlSequence ToYamlSequence(this IEnumerable enumerable)
        {
            YamlSequence seq = new YamlSequence();

            foreach (object obj in enumerable)
            {
                seq.Add(obj.ToYamlNode());
            }
            return(seq);
        }
Example #2
0
        public void TestChangingMappingKey()
        {
            var key = (YamlScalar)"def";
            var map = new YamlMapping(key, 3);

            key.Value = "ghi";
            Assert.IsTrue(map.ContainsKey(key));
            Assert.IsTrue(map.Remove(key));

            map[map] = 4;
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);

            var map2 = new YamlMapping(key, 3);

            map2[map2] = 2;
            map2[map]  = 4;
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            map[map2] = 2;
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);

            map.Tag = YamlNode.DefaultTagPrefix + "map";
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);

            var seq = new YamlSequence(map);

            map.Add(seq, 4);
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);
            seq.Add(map);
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);
        }
Example #3
0
        public void TrackerAssignmentTest()
        {
            var tracker = new YamlNodeTracker();
            var stream  = new YamlStream(tracker);

            var document = new YamlDocument();
            var sequence = new YamlSequence();

            document.Contents = sequence;

            var mapping = new YamlMapping();

            sequence.Add(mapping);

            var key   = new YamlValue("key");
            var value = new YamlValue("value");

            var eventList = new List <TrackerEventArgs>();

            tracker.TrackerEvent += (sender, args) => eventList.Add(args);

            mapping[key] = value;

            Assert.IsNull(document.Tracker);
            Assert.IsNull(sequence.Tracker);
            Assert.IsNull(mapping.Tracker);
            Assert.IsNull(key.Tracker);
            Assert.IsNull(value.Tracker);

            stream.Add(document);

            Assert.AreEqual(tracker, document.Tracker);
            Assert.AreEqual(tracker, sequence.Tracker);
            Assert.AreEqual(tracker, mapping.Tracker);
            Assert.AreEqual(tracker, key.Tracker);
            Assert.AreEqual(tracker, value.Tracker);

            Assert.AreEqual(4, eventList.Count);
            Assert.IsTrue(eventList[0] is MappingPairAdded);
            Assert.IsTrue(eventList[1] is SequenceElementAdded);
            Assert.IsTrue(eventList[2] is DocumentContentsChanged);
            Assert.IsTrue(eventList[3] is StreamDocumentAdded);

            eventList.Clear();

            var key2   = new YamlValue("key2");
            var value2 = new YamlValue("value2");

            mapping[key2] = value2;

            Assert.AreEqual(1, eventList.Count);
            Assert.IsTrue(eventList[0] is MappingPairAdded);
        }
Example #4
0
        public static YamlNode ToYamlNode(this object val)
        {
            Type                type       = val.GetType();
            YamlMapping         node       = new YamlMapping();
            List <PropertyInfo> properties = new List <PropertyInfo>(type.GetProperties());

            properties.Sort((l, r) => l.MetadataToken.CompareTo(r.MetadataToken));
            foreach (PropertyInfo property in properties)
            {
                object propVal = property.GetValue(val);
                if (propVal != null)
                {
                    if (property.IsEnumerable())
                    {
                        YamlSequence yamlSequence = new YamlSequence();
                        node.Add(property.Name, yamlSequence);
                        foreach (object v in ((IEnumerable)propVal))
                        {
                            yamlSequence.Add(v.ToYamlNode());
                        }
                    }
                    else
                    {
                        if (property.PropertyType == typeof(bool) ||
                            property.PropertyType == typeof(bool?) ||
                            property.PropertyType == typeof(int) ||
                            property.PropertyType == typeof(int?) ||
                            property.PropertyType == typeof(long) ||
                            property.PropertyType == typeof(long?) ||
                            property.PropertyType == typeof(decimal) ||
                            property.PropertyType == typeof(decimal?) ||
                            property.PropertyType == typeof(double) ||
                            property.PropertyType == typeof(double?) ||
                            property.PropertyType == typeof(string) ||
                            property.PropertyType == typeof(byte[]) ||
                            property.PropertyType == typeof(DateTime) ||
                            property.PropertyType == typeof(DateTime?))
                        {
                            node.Add(property.Name, new YamlScalar(propVal.ToString()));
                        }
                        else
                        {
                            node.Add(property.Name, propVal.ToYamlNode());
                        }
                    }
                }
            }
            return(node);
        }
Example #5
0
        private void SaveConfig()
        {
            var sec = new YamlSequence();

            foreach (var rf in RecentFiles)
            {
                sec.Add(new YamlScalar(rf));
            }

            YamlNode pnode =
                new YamlMapping(
                    "recentfiles", sec
                    );

            var path = Path.Combine(GetExecPath(), "cache.yml");

            pnode.ToYamlFile(path);
        }
Example #6
0
        public void ApplySettings(IActivityMonitor m)
        {
            if (!this.CheckCurrentBranch(m))
            {
                return;
            }
            YamlMapping firstMapping = GetFirstMapping(m, true);

            if (firstMapping == null)
            {
                return;
            }
            var solution = _driver.GetSolution(m, allowInvalidSolution: true);

            if (solution == null)
            {
                return;
            }

            // We don't use AppVeyor for private repositories.
            if (!GitFolder.IsPublic)
            {
                if (TextContent != null)
                {
                    m.Log(LogLevel.Info, "The project is private, so we don't use Appveyor and the Appveyor.yml is not needed.");
                    Delete(m);
                }
                return;
            }
            // We currently always use AppVeyor when the repository is public.
            YamlMapping env = FindOrCreateYamlElement(m, firstMapping, "environment");

            if (env == null)
            {
                return;
            }

            var passphrase = _keyStore.GetSecretKey(m, SolutionDriver.CODECAKEBUILDER_SECRET_KEY, false);

            if (passphrase != null)
            {
                var central = KeyVault.DecryptValues(_sharedState.CICDKeyVault, passphrase);
                if (central.TryGetValue(APPVEYOR_ENCRYPTED_CODECAKEBUILDER_SECRET_KEY, out var appveyorSecure))
                {
                    env[SolutionDriver.CODECAKEBUILDER_SECRET_KEY] = CreateKeyValue("secure", appveyorSecure);
                }
                else
                {
                    m.Warn($"Update of {SolutionDriver.CODECAKEBUILDER_SECRET_KEY} encrypted secure key has been skipped: {APPVEYOR_ENCRYPTED_CODECAKEBUILDER_SECRET_KEY} key should be defined in CICDKeyVault.");
                }
            }
            else
            {
                m.Info($"Update of {SolutionDriver.CODECAKEBUILDER_SECRET_KEY} encrypted secure skipped.");
            }
            // Remove obsolete environment variables definitions.
            env.Remove("NUGET_API_KEY");
            env.Remove("MYGET_RELEASE_API_KEY");
            env.Remove("MYGET_PREVIEW_API_KEY");
            env.Remove("MYGET_CI_API_KEY");
            env.Remove("CK_DB_TEST_MASTER_CONNECTION_STRING");
            env.Remove("AZURE_FEED_SIGNATURE_OPENSOURCE_PAT");
            env.Remove("AZURE_FEED_PAT");
            env.Remove("VSS_NUGET_EXTERNAL_FEED_ENDPOINTS");
            if (_solutionSpec.SqlServer != null)
            {
                env["SqlServer/MasterConnectionString"] = new YamlValue($"Server=(local)\\SQL{_solutionSpec.SqlServer.ToUpperInvariant()};Database=master;User ID=sa;Password=Password12!");
            }
            //
            firstMapping.Remove(new YamlValue("init"));
            if (_solutionSpec.SqlServer != null)
            {
                firstMapping["services"] = new YamlValue("mssql" + _solutionSpec.SqlServer.ToLowerInvariant());
            }
            var install = new YamlSequence();

            // Temporary: installs the 6.9.0 of npm.
            if (solution.GeneratedArtifacts.Any(g => g.Artifact.Type.Name == "NPM"))
            {
                install.Add(CreateKeyValue("cmd", "npm install -g [email protected]"));
                install.Add(CreateKeyValue("ps", "Install-Product node 12"));
            }
            firstMapping["install"] = install;

            firstMapping["version"]      = new YamlValue("build{build}");
            firstMapping["image"]        = new YamlValue("Visual Studio 2019");
            firstMapping["clone_folder"] = new YamlValue("C:\\CKli-World\\" + GitFolder.SubPath.Path.Replace('/', '\\'));
            EnsureDefaultBranches(firstMapping);
            SetSequence(firstMapping, "build_script", new YamlValue("dotnet run --project CodeCakeBuilder -nointeraction"));
            firstMapping["test"]      = new YamlValue("off");
            firstMapping["artifacts"] = new YamlSequence()
            {
                new YamlMapping()
                {
                    ["path"] = new YamlValue(@"'**\*.log'"),
                    ["name"] = new YamlValue("Log file")
                },
                new YamlMapping()
                {
                    ["path"] = new YamlValue(@"'**\*.trx'"),
                    ["name"] = new YamlValue("Visual studio test results file")
                },
                new YamlMapping()
                {
                    ["path"] = new YamlValue(@"'**\Tests\**\TestResult*.xml'"),
                    ["name"] = new YamlValue("NUnit tests result files")
                },
                new YamlMapping()
                {
                    ["path"] = new YamlValue(@"'**Tests\**\Logs\**\*'"),
                    ["name"] = new YamlValue("Log files")
                }
            };
            CreateOrUpdate(m, YamlMappingToString(m));
        }
        public void TestChangingMappingKey()
        {
            var key = (YamlScalar)"def";
            var map = new YamlMapping(key, 3);
            key.Value = "ghi";
            Assert.IsTrue(map.ContainsKey(key));
            Assert.IsTrue(map.Remove(key));

            map[map] = 4;
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);

            var map2 = new YamlMapping(key, 3);
            map2[map2] = 2;
            map2[map] = 4;
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            map[map2] = 2;
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);

            map.Tag = YamlNode.DefaultTagPrefix + "map";
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);

            var seq = new YamlSequence(map);
            map.Add(seq, 4);
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);
            seq.Add(map);
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);
        }