Example #1
0
        /// <summary>
        /// Adds the request values to the cache by walking the entity hierarchy
        /// and updating the cache with all the retrieved values.
        /// </summary>
        private void RequestToCache(string parentName, Entity entity, Cache cache)
        {
            string fullName;

            if (parentName != null)
            {
                fullName = parentName + "." + entity.Name;
            }
            else
            {
                fullName = entity.Name;
            }

            if (entity.Type == Entity.Types.PARENT | entity.Type == Entity.Types.ARRAY)
            {
                if (entity.Name[0] == '~')
                {
                    // Need to store array parent so that repeat count can be determined
                    cache.AddResolved(fullName, "repeat");
                }

                foreach (var entityName in entity.ChildOrder)
                {
                    Entity child = entity.ChildEntities[entityName];
                    RequestToCache(fullName, child, cache);
                }
            }
            else
            {
                cache.AddResolved(fullName, entity.Value);
            }
        }
Example #2
0
        /// <summary>
        /// Resolve all mods and add to cache (ignore special cases)
        /// </summary>
        private void addResponseMods(Cache cache, Dictionary <string, string> mods)
        {
            foreach (var mod in mods)
            {
                ResolvedValue resolving;

                if (!mod.Key.Equals("*") && mod.Value != null)
                {
                    if (mod.Value[0] == '~')
                    {
                        // Try to retrieve modded value from cache
                        string findName = mod.Value.Substring(1);

                        var refEntity = this.resolver.FindEntity(findName);
                        resolving = new ResolvedValue(findName, refEntity.Type, refEntity.Value);
                        this.resolver.Resolve(resolving, cache, this.formatter);

                        // Also add to cache using mod key name
                        cache.AddResolved(mod.Key, resolving.Value);
                    }
                    else
                    {
                        // Mod value is a literal
                        string value;
                        if (mod.Value[0] == '"' && mod.Value[mod.Value.Length - 1] == '"')
                        {
                            value = mod.Value.Substring(1, mod.Value.Length - 2);
                        }
                        else
                        {
                            value = mod.Value;

                            // Still needs resolving if it contains funcs
                            //if (value.Contains("func."))
                            //{
                            //    resolving = new ResolvedValue(mod.Key, Entity.Types.STR, value);
                            //    this.resolver.Resolve(resolving, cache, this.formatter);
                            //    return;
                            //}
                        }

                        cache.AddResolved(mod.Key, value);
                    }
                }
            }
        }