/// <summary>Parse a JSON structure which can contain tokens, and validate that it's valid.</summary> /// <param name="rawJson">The raw JSON structure which may contain tokens.</param> /// <param name="assumeModIds">Mod IDs to assume are installed for purposes of token validation.</param> /// <param name="error">An error phrase indicating why parsing failed (if applicable).</param> /// <param name="parsed">The parsed value, which may be legitimately <c>null</c> even if successful.</param> public bool TryParseJsonTokens(JToken rawJson, InvariantHashSet assumeModIds, out string error, out TokenizableJToken parsed) { if (rawJson == null || rawJson.Type == JTokenType.Null) { error = null; parsed = null; return(true); } // parse parsed = new TokenizableJToken(rawJson, this.Context); if (!this.Migrator.TryMigrate(parsed, out error)) { return(false); } // validate tokens foreach (LexTokenToken lexToken in parsed.GetTokenStrings().SelectMany(p => p.GetTokenPlaceholders(recursive: false))) { if (!this.TryValidateToken(lexToken, assumeModIds, out error)) { return(false); } } // looks OK if (parsed.Value.Type == JTokenType.Null) { parsed = null; } error = null; return(true); }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="key">The unique key for the entry in the data file.</param> /// <param name="value">The entry value to set.</param> public EditDataPatchRecord(IManagedTokenString key, TokenizableJToken value) { this.Key = key; this.Value = value; this.Contextuals = new AggregateContextual() .Add(key) .Add(value); }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="entryKey">The unique key for the entry in the data file.</param> /// <param name="fieldKey">The field number to change.</param> /// <param name="value">The entry value to set.</param> public EditDataPatchField(IManagedTokenString entryKey, IManagedTokenString fieldKey, TokenizableJToken value) { this.EntryKey = entryKey; this.FieldKey = fieldKey; this.Value = value; this.Contextuals = new AggregateContextual() .Add(entryKey) .Add(fieldKey) .Add(value); }
/// <summary>Migrate a tokenized JSON structure.</summary> /// <param name="tokenStructure">The tokenized JSON structure to migrate.</param> /// <param name="error">An error message which indicates why migration failed (if any).</param> /// <returns>Returns whether migration succeeded.</returns> public bool TryMigrate(TokenizableJToken tokenStructure, out string error) { foreach (IManagedTokenString str in tokenStructure.GetTokenStrings()) { if (!this.TryMigrate(str, out error)) { return(false); } } error = null; return(true); }
/// <summary>Migrate a tokenized JSON structure.</summary> /// <param name="tokenStructure">The tokenized JSON structure to migrate.</param> /// <param name="error">An error message which indicates why migration failed (if any).</param> /// <returns>Returns whether migration succeeded.</returns> public bool TryMigrate(TokenizableJToken tokenStructure, out string error) { // apply migrations foreach (IMigration migration in this.Migrations) { if (!migration.TryMigrate(tokenStructure, out error)) { return(false); } } // no issues found error = null; return(true); }
/// <summary>Parse a JSON structure which can contain tokens, and validate that it's valid.</summary> /// <param name="rawJson">The raw JSON structure which may contain tokens.</param> /// <param name="assumeModIds">Mod IDs to assume are installed for purposes of token validation.</param> /// <param name="path">The path to the value from the root content file.</param> /// <param name="error">An error phrase indicating why parsing failed (if applicable).</param> /// <param name="parsed">The parsed value, which may be legitimately <c>null</c> even if successful.</param> public bool TryParseJson(JToken rawJson, InvariantHashSet assumeModIds, LogPathBuilder path, out string error, out TokenizableJToken parsed) { if (rawJson == null || rawJson.Type == JTokenType.Null) { error = null; parsed = null; return(true); } // extract mutable fields if (!this.TryInjectJsonProxyFields(rawJson, assumeModIds, path, out error, out TokenizableProxy[] proxyFields))