Exemplo n.º 1
0
        /// <summary>Migrate a tokenised string.</summary>
        /// <param name="tokenStr">The tokenised string to migrate.</param>
        /// <param name="error">An error message which indicates why migration failed (if any).</param>
        /// <returns>Returns whether migration succeeded.</returns>
        public virtual bool TryMigrate(IParsedTokenString tokenStr, out string error)
        {
            // tokens which need a higher version
            for (int i = 0; i < tokenStr.LexTokens.Length; i++)
            {
                if (!this.TryMigrate(ref tokenStr.LexTokens[i], out error))
                {
                    return(false);
                }
            }

            // no issue found
            error = null;
            return(true);
        }
        /// <summary>Migrate a tokenised string.</summary>
        /// <param name="tokenStr">The tokenised string 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(IParsedTokenString tokenStr, out string error)
        {
            // apply migrations
            foreach (IMigration migration in this.Migrations)
            {
                if (!migration.TryMigrate(tokenStr, out error))
                {
                    return(false);
                }
            }

            // no issues found
            error = null;
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>Migrate a tokenized string.</summary>
        /// <param name="tokenStr">The tokenized string to migrate.</param>
        /// <param name="error">An error message which indicates why migration failed (if any).</param>
        /// <returns>Returns whether migration succeeded.</returns>
        public virtual bool TryMigrate(IParsedTokenString tokenStr, out string error)
        {
            // tokens which need a higher version
            foreach (ILexToken token in tokenStr.LexTokens)
            {
                if (!this.TryMigrate(token, out error))
                {
                    return(false);
                }
            }

            // no issue found
            error = null;
            return(true);
        }
Exemplo n.º 4
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="logName">A unique name for this patch shown in log messages.</param>
        /// <param name="contentPack">The content pack which requested the patch.</param>
        /// <param name="assetName">The normalised asset name to intercept.</param>
        /// <param name="conditions">The conditions which determine whether this patch should be applied.</param>
        /// <param name="fromFile">The normalised asset key from which to load entries (if applicable), including tokens.</param>
        /// <param name="records">The data records to edit.</param>
        /// <param name="fields">The data fields to edit.</param>
        /// <param name="moveRecords">The records to reorder, if the target is a list asset.</param>
        /// <param name="monitor">Encapsulates monitoring and logging.</param>
        /// <param name="normaliseAssetName">Normalise an asset name.</param>
        /// <param name="tryParseFields">Parse the data change fields for an <see cref="PatchType.EditData"/> patch.</param>
        public EditDataPatch(string logName, ManagedContentPack contentPack, ITokenString assetName, IEnumerable <Condition> conditions, IParsedTokenString fromFile, IEnumerable <EditDataPatchRecord> records, IEnumerable <EditDataPatchField> fields, IEnumerable <EditDataPatchMoveRecord> moveRecords, IMonitor monitor, Func <string, string> normaliseAssetName, TryParseFieldsDelegate tryParseFields)
            : base(logName, PatchType.EditData, contentPack, assetName, conditions, normaliseAssetName, fromAsset: fromFile)
        {
            // set fields
            this.Records        = records?.ToArray();
            this.Fields         = fields?.ToArray();
            this.MoveRecords    = moveRecords?.ToArray();
            this.Monitor        = monitor;
            this.TryParseFields = tryParseFields;

            // track contextuals
            this.Contextuals
            .Add(this.Records)
            .Add(this.Fields)
            .Add(this.MoveRecords)
            .Add(this.Conditions);
        }
Exemplo n.º 5
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="tokenString">The token string which provides the field value.</param>
 /// <param name="setValue">Set the instance value.</param>
 public TokenizableProxy(IParsedTokenString tokenString, Action <string> setValue)
 {
     this.TokenString = tokenString;
     this.SetValue    = setValue;
 }
Exemplo n.º 6
0
        /// <summary>Parse a string which can contain tokens, and validate that it's valid.</summary>
        /// <param name="rawValue">The raw string 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.</param>
        public bool TryParseStringTokens(string rawValue, InvariantHashSet assumeModIds, out string error, out IParsedTokenString parsed)
        {
            // parse
            parsed = new TokenString(rawValue, this.Context);
            if (!this.Migrator.TryMigrate(parsed, out error))
            {
                return(false);
            }

            // validate tokens
            foreach (LexTokenToken lexToken in parsed.GetTokenPlaceholders(recursive: false))
            {
                if (!this.TryValidateToken(lexToken, assumeModIds, out error))
                {
                    return(false);
                }
            }

            // looks OK
            error = null;
            return(true);
        }