Exemplo n.º 1
0
    public static T Deserialize <T>(string yaml)
    {
        var deserializer = new YamlDotNet.Serialization.DeserializerBuilder().Build();
        var obj          = deserializer.Deserialize <T>(yaml);

        return(obj);
    }
        public IEnumerable <VpGameMap> GetMappings(string vp_game_map = @"C:\P-ROC\shared\vp_game_map.yaml")
        {
            //Create serializer and load the mapping file
            var builder = new YamlDotNet.Serialization.DeserializerBuilder()
                          .Build();
            var mapping = builder.Deserialize(File.OpenText(vp_game_map));

            //Get mapping as dict and remove rundir
            var gameMappingDict = mapping as Dictionary <object, object>;

            try
            {
                gameMappingDict.Remove("rundir");
            }
            catch { }

            //Convert the dict maps to list of VPGamemap
            var maps = new List <VpGameMap>();

            foreach (var gameMap in gameMappingDict)
            {
                var    valType = gameMap.Value as Dictionary <object, object>;
                var    kls     = valType["kls"].ToString();
                var    path    = valType["path"].ToString();
                var    yaml    = valType["yaml"].ToString();
                string table   = string.Empty;
                if (valType.ContainsKey("table"))
                {
                    table = valType["table"] != null ? valType["table"].ToString() : string.Empty;
                }
                maps.Add(new VpGameMap(gameMap.Key.ToString(), path, kls, yaml, table));
            }

            return(maps.OrderBy(x => x.Rom));
        }
Exemplo n.º 3
0
        public static bool LoadFromDefaultFile(out AppSettings settings)
        {
            if (!File.Exists(Files.ConfigFile))
            {
                settings = CreateNewConfig();
            }
            else
            {
                var content = File.ReadAllText(Files.ConfigFile);
                var builder = new YamlDotNet.Serialization.DeserializerBuilder();
                //builder.WithTagMapping("tag:yaml.org,2002:test", typeof(Test));
                var ymlDeserializer = builder.Build();
                try
                {
                    settings = ymlDeserializer.Deserialize <AppSettings>(content);
                    Load(settings);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    settings = null;
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        public void YamlTest()
        {
            var ys = new SerializerBuilder().Build();
            var s  = ys.Serialize(new { Field1 = "one", Field2 = "two", });

            Console.WriteLine(s);
            Assert.AreEqual($"Field1: one{Environment.NewLine}Field2: two{Environment.NewLine}", s);
            var x = new { Name = "None", Count = 4, };

            s = ys.Serialize(new { Field1 = "one", Field2 = "two", Az1 = x, Az2 = x, });
            Console.WriteLine(s);
            Assert.AreEqual($"Field1: one{Environment.NewLine}Field2: two{Environment.NewLine}Az1: &o0{Environment.NewLine}  Name: None{Environment.NewLine}  Count: 4{Environment.NewLine}Az2: *o0{Environment.NewLine}", s);

            var site = new IvrSiteSchema {
                HostedZoneDomain = "my.site.domain.net",
                SipProviders     = new List <string> {
                    "Twilio",
                },
                IngressPorts = new List <PortSpec> {
                    PortSpec.Parse("SIP 5060"), PortSpec.Parse("RTP 5064-6000"),
                },
                RdpProps = new RdpProps {
                    UserName = "******",
                    Password = "******",
                    Cidrs    = new List <string> {
                        "1.2.3.4/32",
                    }
                },
                HostGroups = new List <HostGroup> {
                    new HostGroup {
                        AllocateNewElasticIPs = true,
                        HostCount             = 2,
                        InstallS3i            = "https://raw.githubusercontent.com/OlegBoulanov/s3i/develop/Examples/Config.ini",
                    },
                    new HostGroup {
                        AllocateNewElasticIPs = false,
                        HostCount             = 16,
                        InstallS3i            = "https://raw.githubusercontent.com/OlegBoulanov/s3i/develop/Examples/Config.ini",
                    },
                },
            };

            s = ys.Serialize(site);
            Console.WriteLine(s);
            var yd    = new YamlDotNet.Serialization.DeserializerBuilder().Build();
            var site2 = yd.Deserialize <IvrSiteSchema>(s);

            Assert.AreEqual(2, site2.HostGroups.Count());

/*
 *          Console.WriteLine("******");
 *          using(var sr = new StreamReader($"{OSAgnostic.Home}/Projects/CdkTest-1.yaml")) {
 *              var site1 = yd.Deserialize<IvrSiteSchema>(sr.ReadToEnd());
 *              Console.WriteLine(ys.Serialize(site1));
 *          }
 */
        }
Exemplo n.º 5
0
        static T ParseYaml <T>(string configPath)
        {
            var deserializer = new YamlDotNet.Serialization.DeserializerBuilder()
                               .WithNamingConvention(UnderscoredNamingConvention.Instance)
                               .Build();

            return(deserializer.Deserialize <T>(
                       File.ReadAllText(configPath)));
        }
Exemplo n.º 6
0
        public static BuildConfigurationFIle Create(string text)
        {
            var deserializer = new YamlDotNet.Serialization.DeserializerBuilder()
                               .WithNamingConvention(CamelCaseNamingConvention.Instance)
                               .Build();
            var buildConfigFile = deserializer.Deserialize <BuildConfigurationFIle>(text);

            return(buildConfigFile);
        }
Exemplo n.º 7
0
        public static T FromYaml <T>(this string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(default(T));
            }
            var serializer = new YamlDotNet.Serialization.DeserializerBuilder()
                             .WithTypeConverter(new SystemTypeTypeConverter())
                             .Build();

            return(serializer.Deserialize <T>(value));
        }
Exemplo n.º 8
0
        private static int MergeToc(string mkdocsPath, string newTocPath)
        {
            var mkdocs = new YamlStream();

            using (var reader = new StreamReader(mkdocsPath))
            {
                mkdocs.Load(reader);
            }

            Toc toc = null;

            using (var reader = new StreamReader(newTocPath))
            {
                // Examine the new toc
                var deserializer = new YamlDotNet.Serialization.DeserializerBuilder().Build();
                toc = deserializer.Deserialize <Toc>(reader);
            }

            // the mkdocs format is not ammenable to object serialization unfortunately...
            var root = (YamlMappingNode)mkdocs.Documents[0].RootNode;

            // Examine the stream
            var items = (YamlSequenceNode)root.Children[new YamlScalarNode("nav")];

            var apitoc = items.Where(it => it is YamlMappingNode ym && ym.Children.Count > 0 &&
                                     ym.Children[0].Key is YamlScalarNode s && s.Value == "API documentation").FirstOrDefault() as YamlMappingNode;

            if (apitoc == null)
            {
                apitoc = new YamlMappingNode();
                items.Add(apitoc);
            }

            apitoc.Children.Clear();
            var s = new YamlSequenceNode();

            apitoc.Add(new YamlScalarNode("API documentation"), s);
            int count = AddLinks(s, toc.toc);

            // save the updated mkdocs
            using (var writer = new StreamWriter(mkdocsPath))
            {
                mkdocs.Save(writer, false);
            }

            Console.WriteLine("Added {0} api documentation links to the nav: section in {1}", count, mkdocsPath);

            return(0);
        }
Exemplo n.º 9
0
        public Atomic(string path, Dictionary <string, string> args = null)
        {
            if (args == null)
            {
                this.args = new Dictionary <string, string>();
            }
            else
            {
                this.args = args;
            }
            this.path = path;
            this.yaml = Utils.LoadYamlFromPath(path);

            var deserializer = new YamlDotNet.Serialization.DeserializerBuilder().Build();

            this.atomic_yaml = deserializer.Deserialize <AtomicYaml>(this.yaml);
        }
Exemplo n.º 10
0
        public static void WriteConfig(string outputFile, Dictionary <string, object> settingsOverride)
        {
            var deserializer = new YamlDotNet.Serialization.DeserializerBuilder()
                               .Build();
            var configYaml = File.ReadAllText(DefaultConfigFile);
            var config     = deserializer.Deserialize <Dictionary <string, object> >(configYaml);

            foreach (var s in settingsOverride)
            {
                config[s.Key] = s.Value;
            }

            var serializer = new YamlDotNet.Serialization.SerializerBuilder()
                             .WithEventEmitter(next => new FlowStyleIntegerSequences(next))
                             .Build();
            string newConfigYaml = null;

            newConfigYaml = serializer.Serialize(config);
            Directory.CreateDirectory(Path.GetDirectoryName(outputFile));
            File.WriteAllText(outputFile, newConfigYaml);
        }