// Token: 0x06002580 RID: 9600 RVA: 0x000BB5E0 File Offset: 0x000B97E0 public static ModConfigType Deserialize(string configfile) { ModConfigType result; try { DeserializerBuilder deserializerBuilder = new DeserializerBuilder().IgnoreUnmatchedProperties().IgnoreFields(); string input = File.ReadAllText(configfile); result = deserializerBuilder.Build().Deserialize <ModConfigType>(input); } catch (Exception ex) { ServerConsole.AddLog(string.Concat(new string[] { "[ERROR] [CONFIG] ", "Exception: ", ex.GetType().ToString(), "\nMessage: ", ex.Message, "\nStackTrace: ", ex.StackTrace })); result = new ModConfigType(); } return(result); }
/// <summary> /// Adds and configures an YamlDotNet <see cref="ISerializer"/> and <see cref="IDeserializer"/> /// </summary> /// <param name="services">The <see cref="IServiceCollection"/> to configure</param> /// <param name="serializerConfiguration">The <see cref="Action{T}"/> used to configure the <see cref="ISerializer"/> to add</param> /// <param name="deserializerConfiguration">The <see cref="Action{T}"/> used to configure the <see cref="IDeserializer"/> to add</param> /// <returns>The configured <see cref="IServiceCollection"/></returns> public static IServiceCollection AddYamlDotNet(this IServiceCollection services, Action <SerializerBuilder> serializerConfiguration = null, Action <DeserializerBuilder> deserializerConfiguration = null) { services.TryAddSingleton(provider => { SerializerBuilder builder = new SerializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance); serializerConfiguration?.Invoke(builder); return(builder.Build()); }); services.TryAddSingleton(provider => { DeserializerBuilder builder = new DeserializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) .WithNodeDeserializer( inner => new JArrayDeserializer(inner), syntax => syntax.InsteadOf <ArrayNodeDeserializer>()) .WithNodeDeserializer( inner => new AbstractTypeDeserializer(inner), syntax => syntax.InsteadOf <ObjectNodeDeserializer>()) .WithNodeDeserializer( inner => new JTokenDeserializer(inner), syntax => syntax.InsteadOf <DictionaryNodeDeserializer>()) .WithObjectFactory(new NonPublicConstructorObjectFactory()) .IncludeNonPublicProperties(); deserializerConfiguration?.Invoke(builder); return(builder.Build()); }); return(services); }
private static object ConvertDataTableWithYamlColumns(Dictionary <string, Dictionary <string, object> > datatable, IEnumerable <string> yamlColumnNames = null) { var builder = new DeserializerBuilder(); var deserializer = builder.Build(); return(datatable.ToDictionary( pair => pair.Key, pair => pair.Value.ToDictionary( _pair => _pair.Key, _pair => { if (_pair.Value == null) { return null; } else if (yamlColumnNames.Contains(_pair.Key)) { return deserializer.Deserialize(new StringReader(_pair.Value.ToString())); } else { return _pair.Value; } } ) )); }
/// <summary> /// Reads WinGet definition from a text reader. /// </summary> /// <param name="textReader">The input textReader.</param> /// <returns>The WinGet definition.</returns> public YamlDefinition Read(TextReader textReader) { var deserializerBuilder = new DeserializerBuilder().IgnoreUnmatchedProperties(); var deserializer = deserializerBuilder.Build(); return(deserializer.Deserialize <YamlDefinition>(textReader)); }
public static IDeserializer GetDeserializer(string filePath = null) { // if (_desrializer != null) { // return _desrializer; // } var builder = new DeserializerBuilder(); builder = builder .IgnoreFields() .IgnoreUnmatchedProperties() .WithNamingConvention(CamelCaseNamingConvention.Instance); if (RegisteredTags?.Count > 0) { foreach (var t in RegisteredTags) { var type = t.GetType(); var tagKey = type.GetCustomAttributes(typeof(YamlTagAttribute), true) .FirstOrDefault() is YamlTagAttribute att ? att.TagName : null; builder = builder.WithTagMapping($"!{tagKey}", type); } builder = builder .WithTypeConverter( new FileTypeConverter(RegisteredTags, filePath), s => s.OnTop()); } // _desrializer = builder.Build(); // return _desrializer; return(builder.Build()); }
private async Task LoadAsync() { var deserializer = DeserializerBuilder.Build(); try { await _ioLock.WaitAsync(); var deserialized = deserializer.Deserialize <TYamlSettings>(await this.ReadAllTextAsync()); _ioLock.Release(); if (deserialized != null && deserialized.IsValid()) { FromYaml(deserialized); } else { var @default = Default; await SaveAsync(@default); FromYaml(@default); } } catch (YamlException) { await SaveAsync(Default); await _ioLock.WaitAsync(); FromYaml(deserializer.Deserialize <TYamlSettings>(await this.ReadAllTextAsync()) ?? Default); _ioLock.Release(); } }
static void Main(string[] args) { DeserializerBuilder deserializerBuilder = new DeserializerBuilder(); Deserializer deserializer = deserializerBuilder.Build(); config = deserializer.Deserialize <ConfigModel>(new StringReader(File.ReadAllText("config.yaml"))); Console.WriteLine($"Web Server MySql Connection String: {config.ConnString}"); ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); }; SteamIds = FetchSteamIds(); DiscordIds = FetchDiscordIds(); TwitchIds = FetchTwitchIds(); IpAddresses = FetchIpAddresses(); Console.WriteLine($"SteamIds: {String.Join(", ", SteamIds)}"); Console.WriteLine($"DiscordIds: {String.Join(", ", DiscordIds)}"); Console.WriteLine($"TwitchIds: {String.Join(", ", TwitchIds)}"); Console.WriteLine($"IpAddresses: {String.Join(", ", IpAddresses)}"); RunEvery(PropagateNewUsers); RunEvery(ParseNewSteamIds); RunEvery(ParseNewDiscordIds); RunEvery(ParseNewTwitchIds); RunEvery(ParseNewSteamIds); bool _quitFlag = false; while (!_quitFlag) { var keyInfo = Console.ReadKey(); _quitFlag = keyInfo.Key == ConsoleKey.C && keyInfo.Modifiers == ConsoleModifiers.Control; } }
public static GameJoltYaml Deserialize(string data) { var deserializer = DeserializerBuilder.Build(); try { return(deserializer.Deserialize <GameJoltYaml>(data)); } catch (YamlException) { return(null); } }
/// <summary> /// Verifies the content of the given file, treating it as a transformation file. /// </summary> /// <param name="file">The path to the file.</param> /// <typeparam name="T">The class to verify the file as.</typeparam> /// <returns>A condition result, which may or may not have succeeded.</returns> public static Result VerifyFile <T>(string file) { using var sr = new StreamReader(File.OpenRead(file)); var builder = new DeserializerBuilder() .WithTypeConverter(new ColourYamlConverter()) .WithTypeConverter(new EnumYamlConverter <Pattern>()) .WithTypeConverter(new NullableEnumYamlConverter <Pattern>()) .WithNodeDeserializer(i => new ValidatingNodeDeserializer(i), s => s.InsteadOf <ObjectNodeDeserializer>()) .WithNamingConvention(UnderscoredNamingConvention.Instance); if (typeof(T) != typeof(Species)) { builder = builder.WithTypeConverter(new RawSpeciesYamlConverter()); } var deserializer = builder.Build(); var content = sr.ReadToEnd(); try { deserializer.Deserialize <T>(content); } catch (YamlException yex) { return(yex); } return(Result.FromSuccess()); }
public static Func <UnityBinaryReader, DynamicAsset> GenDeserializerWithAssembly(SerializedType sertype) { string name = ""; var nodes = sertype.TypeTree.Nodes; if (sertype.ClassID == (int)ClassIDType.MonoBehaviour) { name = "MonoBehaviour" + BitConverter.ToString(sertype.ScriptID) + "Deserializer" + gendeserializerwithcount.ToString(); } else { name = nodes[0].Type + "Deserializer" + gendeserializerwithcount.ToString(); } gendeserializerwithcount++; AssemblyName assemblyname = new AssemblyName { Name = name }; AssemblyBuilder assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyname, AssemblyBuilderAccess.RunAndSave); ModuleBuilder module = assembly.DefineDynamicModule(name, name + ".dll", true); TypeBuilder type = module.DefineType(name, TypeAttributes.Public); MethodBuilder method = type.DefineMethod( "Deserialize", MethodAttributes.Public | MethodAttributes.Static, typeof(DynamicAsset), new Type[] { typeof(UnityBinaryReader) }); DeserializerBuilder builder = new DeserializerBuilder(nodes); builder.Build(method.GetILGenerator()); Type completed = type.CreateType(); return((Func <UnityBinaryReader, DynamicAsset>)Delegate.CreateDelegate(typeof(Func <UnityBinaryReader, DynamicAsset>), completed.GetMethod("Deserialize"))); }
static ManagedGameObjectIO() { var serializer_ = new SerializerBuilder(); var typeInspectorFactories_ = serializer_.GetType().GetField("typeInspectorFactories", BindingFlags.NonPublic | BindingFlags.Instance); var typeInspectorFactories = typeInspectorFactories_.GetValue(serializer_); var Add = typeInspectorFactories.GetType().GetMethod("Add", BindingFlags.Public | BindingFlags.Instance); Add.Invoke(typeInspectorFactories, new object[] { typeof(YamlAttributesTypeInspector), new Func <ITypeInspector, ITypeInspector>((ITypeInspector inner) => new YamlAttributesTypeInspector(inner)) }); var Remove = typeInspectorFactories.GetType().GetMethod("Remove", BindingFlags.Public | BindingFlags.Instance); Remove.Invoke(typeInspectorFactories, new object[] { typeof(YamlDotNet.Serialization.YamlAttributesTypeInspector) }); #if DEBUG var _namingConvention = serializer_.GetType().GetField("namingConvention", BindingFlags.NonPublic | BindingFlags.Instance); var namingConvention = _namingConvention.GetValue(serializer_) as INamingConvention; var objectGraphTraversalStrategyFactory = (ObjectGraphTraversalStrategyFactory)((ITypeInspector typeInspector, ITypeResolver typeResolver, IEnumerable <IYamlTypeConverter> typeConverters, int maximumRecursion) => new Debug_TraversalStrategy(typeInspector, typeResolver, maximumRecursion, namingConvention)); serializer_.WithObjectGraphTraversalStrategyFactory(objectGraphTraversalStrategyFactory); #endif m_Serializer = serializer_.Build(); var deserializer_ = new DeserializerBuilder(); var BuildTypeInspector = deserializer_.GetType().GetMethod("BuildTypeInspector", BindingFlags.NonPublic | BindingFlags.Instance); deserializer_.WithNodeDeserializer(new ManagedGameObject_Deserializer(BuildTypeInspector.Invoke(deserializer_, new object[] { }) as ITypeInspector)); m_Deserializer = deserializer_.Build(); }
public void SetupRootDirectories() { // ENHANCEMENT: Execute git commands when TeamCity environment variables are present // to filter the set of files we run against based on changes in a given PR var currentDirectory = TestContext.CurrentContext.TestDirectory; DocsRootPath = Path.GetFullPath(Path.Combine(currentDirectory, "..", "..", "..", "..", "..")); RootDirectories = new[] { DocsRootPath }; var componentsYamlPath = Path.Combine(DocsRootPath, "components", "components.yaml"); var componentsText = File.ReadAllText(componentsYamlPath); var builder = new DeserializerBuilder(); var deserializer = builder.Build(); var allData = deserializer.Deserialize <List <ComponentMetadata> >(componentsText); ComponentMetadata = allData.ToDictionary(m => m.Key, StringComparer.OrdinalIgnoreCase); NugetAliases = new Dictionary <string, string>(); var nugetAliasesPath = Path.Combine(DocsRootPath, "components", "nugetAlias.txt"); var nugetAliasesText = File.ReadLines(nugetAliasesPath); foreach (var aliasLine in nugetAliasesText) { var aliasAndNuget = aliasLine.Split(":", StringSplitOptions.RemoveEmptyEntries); NugetAliases.Add(aliasAndNuget[0].Trim(), aliasAndNuget[1].Trim()); } }
private static IDeserializer CreateYamlDeserializer() { var builder = new DeserializerBuilder() .WithNamingConvention(new CamelCaseNamingConvention()); return(builder.Build()); }
/// <summary> /// Verifies the content of the given file, treating it as a transformation file. /// </summary> /// <param name="file">The path to the file.</param> /// <typeparam name="T">The class to verify the file as.</typeparam> /// <returns>A condition result, which may or may not have succeeded.</returns> public DetermineConditionResult VerifyFile <T>(string file) { using var sr = new StreamReader(File.OpenRead(file)); var deserB = new DeserializerBuilder() .WithTypeConverter(new ColourYamlConverter()) .WithNodeDeserializer(i => new ValidatingNodeDeserializer(i), s => s.InsteadOf <ObjectNodeDeserializer>()) .WithNamingConvention(UnderscoredNamingConvention.Instance); if (typeof(T) != typeof(Species)) { deserB = deserB.WithTypeConverter(new RawSpeciesYamlConverter()); } var deser = deserB.Build(); var content = sr.ReadToEnd(); try { deser.Deserialize <T>(content); } catch (YamlException yex) { return(DetermineConditionResult.FromError(yex, Path.GetFileName(file))); } return(DetermineConditionResult.FromSuccess()); }
private void Load() { var deserializer = DeserializerBuilder.Build(); try { _ioLock.Wait(); var deserialized = deserializer.Deserialize <TYamlSettings>(this.ReadAllText()); _ioLock.Release(); if (deserialized != null && deserialized.IsValid()) { FromYaml(deserialized); } else { var @default = Default; Save(@default); FromYaml(@default); } } catch (YamlException) { Save(Default); _ioLock.Wait(); FromYaml(deserializer.Deserialize <TYamlSettings>(this.ReadAllText()) ?? Default); _ioLock.Release(); } }
/// <summary> /// Loads Kube Config from string /// </summary> /// <param name="kubeconfig">Kube config file contents</param> /// <returns>Instance of the <see cref="K8SConfiguration"/> class</returns> private static K8SConfiguration LoadKubeConfig(string kubeconfig) { var deserializeBuilder = new DeserializerBuilder(); var deserializer = deserializeBuilder.Build(); return(deserializer.Deserialize <K8SConfiguration>(kubeconfig)); }
public QuestionList CreateQuestionList(string _document) { var input = new StringReader(_document); var deserializerBuilder = new DeserializerBuilder(); var deserializer = deserializerBuilder.Build(); return(deserializer.Deserialize <QuestionList>(input));; }
/// <summary> /// Helper to deserialize the manifest. /// </summary> /// <returns>IDeserializer object.</returns> private static IDeserializer CreateDeserializer() { var deserializer = new DeserializerBuilder(). WithNamingConvention(PascalCaseNamingConvention.Instance). IgnoreUnmatchedProperties(); return(deserializer.Build()); }
static UpgradeGuides() { var builder = new DeserializerBuilder(); builder.IgnoreUnmatchedProperties(); builder.WithNamingConvention(CamelCaseNamingConvention.Instance); deserializer = builder.Build(); }
public YamlPluginFormat() { var builder = new DeserializerBuilder() .WithNamingConvention(LowerCaseNamingConvention.Instance) ; _deserializer = builder.Build(); }
private static IDeserializer BuildDeserialiser() { var builder = new DeserializerBuilder() .WithNamingConvention(new HyphenatedNamingConvention()) .WithTypeConverter(new WidthConverter()) .WithTypeConverter(new BrushConverter()); return(builder.Build()); }
private static IDeserializer GetDeserializer() { var serializerBuilder = new DeserializerBuilder() .IgnoreUnmatchedProperties() .WithTypeConverter(new YamlStringEnumConverter()); var serializer = serializerBuilder.Build(); return(serializer); }