Ejemplo n.º 1
0
 static Generator()
 {
     SerializerSettings.RegisterSerializerFactory(new ValueTupleSerializer());
     //SerializerSettings.RegisterSerializerFactory(new NullableSerializer());
     SerializerSettings.RegisterSerializerFactory(new YamlNodeSerializer());
     SerializerSettings.RegisterSerializerFactory(new PrimitiveSerializer());
     Serializer = new Serializer(SerializerSettings);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new instance of the loader.
        /// </summary>
        /// <param name="opts">Application configuration.</param>
        public YamlCtfConfigurationLoader(IOptions <ConfigurationRoot> opts)
        {
            var des = new SerializerSettings
            {
                ObjectFactory = new YamlObjectFactory()
            };

            des.RegisterSerializerFactory(new YamlTimeSpanConverter());
            des.RegisterSerializerFactory(new YamlDateTimeOffsetConverter());
            des.RegisterSerializerFactory(new YamlUriConverter());

            var deserializer = new Serializer(des);

            var optv = opts.Value;
            var fi   = new FileInfo(optv.EventConfiguration);

            using (var fs = fi.OpenRead())
                using (var sr = new StreamReader(fs, AbstractionUtilities.UTF8))
                {
                    var parser = new Parser(sr);
                    var er     = new EventReader(parser);
                    if (er.Expect <StreamStart>() == null)
                    {
                        throw new InvalidDataException("YAML configuration is malformed.");
                    }

                    this._eventConfig = ReadEvent(er, deserializer);
                    this._categories  = ReadCategories(er, deserializer);

                    foreach (var cat in this._categories)
                    {
                        foreach (var chall in cat.Challenges)
                        {
                            (chall as YamlCtfChallenge).Category = cat;
                        }
                    }
                }
        }
Ejemplo n.º 3
0
        public void RoundtripWithTypeConverter()
        {
            var buffer   = new StringWriter();
            var x        = new SomeCustomType("Yo");
            var settings = new SerializerSettings();

            settings.RegisterSerializerFactory(new CustomTypeConverter());
            var serializer = new Serializer(settings);

            serializer.Serialize(buffer, x);

            Dump.WriteLine(buffer);

            var bufferText = buffer.ToString();
            var copy       = serializer.Deserialize <SomeCustomType>(bufferText);

            Assert.AreEqual("Yo", copy.Value);
        }
Ejemplo n.º 4
0
 public AssetObjectSerializerBackend(SerializerSettings settings, IContentManager contentManager)
 {
     settings.RegisterTagMapping("!asset", typeof(AssetName));
     settings.RegisterSerializerFactory(new AssetNameFactory());
     this.contentManager = contentManager;
 }