Esempio n. 1
0
        private void BuildTokenCache()
        {
            foreach (TokenDefinition tokenDefinition in _tokens)
            {
                foreach (string token in tokenDefinition.GetTokens())
                {
                    var tokenKey = Regex.Unescape(token);
                    if (TokenDictionary.ContainsKey(tokenKey))
                    {
                        continue;
                    }

                    int    before = _web.Context.PendingRequestCount();
                    string value  = tokenDefinition.GetReplaceValue();
                    int    after  = _web.Context.PendingRequestCount();

                    if (before != after)
                    {
                        throw new Exception($"Token {token} triggered an ExecuteQuery on the 'current' context. Please refactor this token to use the TokenContext class.");
                    }

                    TokenDictionary[tokenKey] = value;
                    if (tokenDefinition is ListIdToken)
                    {
                        ListTokenDictionary[tokenKey] = tokenDefinition;
                    }
                }
            }
        }
Esempio n. 2
0
 private bool CreateListFromString(string operation)
 {
     tokens.Clear();
     for (int i = 0; i < operation.Length; i++)
     {
         string character = operation[i].ToString(CultureInfo.CurrentCulture);
         if (TokenDictionary.ContainsKey(character))
         {
             Token n = new Token(TokenDictionary[character]);
             if (tokens.Count > 0)
             {
                 Token previousToken = tokens[tokens.Count - 1];
                 if (previousToken.TypeToken == TypeToken.Number && n.TypeToken == TypeToken.Number)
                 {
                     previousToken.ExpressionToken += n.ExpressionToken;
                     previousToken.ValToken         = double.Parse(previousToken.ExpressionToken,
                                                                   CultureInfo.CurrentCulture);
                 }
                 else
                 {
                     tokens.Add(n);
                 }
             }
             else
             {
                 tokens.Add(n);
             }
         }
         else
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 3
0
 public Token(string str, string encode_type = "MD5")
 {
     Data     = Security.Encode(str, encode_type);
     TimeLife = DEFAULT_TIME_LIFE;
     new Timer((s) =>
     {
         TimeLife -= 1;
         if (TimeLife <= 0 && TokenDictionary.ContainsKey(this))
         {
             TokenDictionary.Remove(this);
         }
     }, null, 0, DEFAULT_PERIOD_DECREASE_TIME_LIFE);
 }
Esempio n. 4
0
        private void BuildTokenCache()
        {
            foreach (var tokenDefinition in _tokens)
            {
                foreach (string token in tokenDefinition.GetTokens())
                {
                    var tokenKey = Regex.Unescape(token);
                    if (TokenDictionary.ContainsKey(tokenKey))
                    {
                        continue;
                    }

                    string value = tokenDefinition.GetReplaceValue();

                    TokenDictionary[tokenKey] = value;
                }
            }
        }