Example #1
0
        /// <summary>
        /// Fetches an object starting at the local scope and then moving up
        /// the hierarchy
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private object FindVariable(string key)
        {
            Hash   scope    = Scopes.FirstOrDefault(s => s.ContainsKey(key));
            object variable = null;

            if (scope == null)
            {
                foreach (Hash e in Environments)
                {
                    if ((variable = LookupAndEvaluate(e, key)) != null)
                    {
                        scope = e;
                        break;
                    }
                }
            }
            scope    = scope ?? Environments.LastOrDefault() ?? Scopes.Last();
            variable = variable ?? LookupAndEvaluate(scope, key);

            variable = Liquidize(variable);
            if (variable is IContextAware)
            {
                ((IContextAware)variable).Context = this;
            }
            return(variable);
        }
Example #2
0
        public void RemoveScope(int scopeId)
        {
            var scopeToRemove = Scopes.FirstOrDefault(s => s.ScopeId == scopeId);

            if (scopeToRemove != null)
            {
                Scopes.Remove(scopeToRemove);
            }
        }
Example #3
0
 public void AddScope(int scopeId)
 {
     if (Scopes.FirstOrDefault(s => s.ScopeId == scopeId) == null)
     {
         Scope s = new Scope(scopeId);
         if (s.ScopeId > 0)
         {
             Scopes.Add(s);
         }
         else
         {
             throw new ArgumentException("Scope not found.", "scopeId");
         }
     }
 }
Example #4
0
        // Get existing scope or add new one from symbol
        public Scope GetScope(string symbol)
        {
            var existing = Scopes.FirstOrDefault(x => x.Name
                                                 == Scope.ExtractScope(symbol));

            if (existing != null)
            {
                return(existing);
            }
            else
            {
                var newScope = Scope.ParseSymbol(this, symbol);
                Scopes.Add(newScope);
                return(newScope);
            }
        }
Example #5
0
        /// <summary>
        /// Fetches an object starting at the local scope and then moving up
        /// the hierarchy
        /// </summary>
        /// <param name="key"></param>
        /// <param name="variable"></param>
        /// <returns></returns>
        private bool TryFindVariable(string key, out object variable)
        {
            bool   foundVariable = false;
            object foundValue    = null;
            Hash   scope         = Scopes.FirstOrDefault(s => s.ContainsKey(key));

            if (scope == null)
            {
                foreach (Hash environment in Environments)
                {
                    foundVariable = TryEvaluateHashOrArrayLikeObject(environment, key, out foundValue);
                    if (foundVariable)
                    {
                        scope = environment;
                        break;
                    }
                }

                if (scope == null)
                {
                    scope         = Environments.LastOrDefault() ?? Scopes.Last();
                    foundVariable = TryEvaluateHashOrArrayLikeObject(scope, key, out foundValue);
                }
            }
            else
            {
                foundVariable = TryEvaluateHashOrArrayLikeObject(scope, key, out foundValue);
            }

            variable = Liquidize(foundValue);
            if (variable is IContextAware contextAwareVariable)
            {
                contextAwareVariable.Context = this;
            }
            return(foundVariable);
        }
 public virtual ApiScopeDto FindScope(string name)
 {
     return(Scopes.FirstOrDefault(r => r.Name == name));
 }
Example #7
0
 /// <summary>
 /// Searches <see cref="Scopes"/> list for the given scope name.
 /// </summary>
 /// <param name="scopeName">The scope name to look for. Must be fully qualified (e.x. facade:customers).</param>
 public Scope GetScope(string scopeName) => Scopes?.FirstOrDefault(x => x.Name == scopeName);
Example #8
0
 public virtual ApiResourceScope FindScope(string scope)
 {
     return(Scopes.FirstOrDefault(r => r.Scope == scope));
 }