private static dynamic ResolveToken(IToken token)
        {
            dynamic ret = new ExpandoObject();

            ret.Label = token.Token;
            ret.Icon  = "";
            ID tokenBackingItemId = token.GetBackingItemId();

            if (tokenBackingItemId != (ID)null)
            {
                var tokenItem = TokenKeeper.CurrentKeeper.GetDatabase().GetItem(token.GetBackingItemId());
                ret.Icon = "";
                if (tokenItem != null)
                {
                    ret.Icon = GetIcon(tokenItem[FieldIDs.Icon]);
                    if (string.IsNullOrWhiteSpace(ret.Icon))
                    {
                        ret.Icon = GetIcon(tokenItem.Template.InnerItem[FieldIDs.Icon]);
                    }
                }
            }
            AutoToken autoToken = token as AutoToken;

            if (autoToken != null)
            {
                ret.Icon = GetIcon(autoToken.TokenIcon);
            }
            if (string.IsNullOrWhiteSpace(ret.Icon))
            {
                ret.Icon = TokenKeeper.IsSc8 ? GetIcon("Office/32x32/package.png") : GetIcon("People/32x32/cube_green.png");
            }
            return(ret);
        }
Esempio n. 2
0
 /// <summary>
 /// returns the token based on the text
 /// </summary>
 /// <param name="token"></param>
 /// <returns>token object</returns>
 public virtual T GetToken(string token)
 {
     if ((object)_itemId == null)
     {
         if (_tokens.ContainsKey(token))
         {
             return(_tokens[token]);
         }
         return(default(T));
     }
     else if (_tokens.ContainsKey(token))
     {
         var item = TokenKeeper.CurrentKeeper.GetDatabase().GetItem(_itemId);
         if (item == null)
         {
             ResetTokenCache();
         }
         else if (item.Statistics.Updated > _itemUpdated)
         {
             InitializeCollection(item);
             ResetTokenCache();
         }
         if (_tokens.ContainsKey(token))
         {
             IToken t = _tokens[token];
             if (t != null)
             {
                 if (t.GetBackingItemId() != (ID)null)
                 {
                     var tokenItem = TokenKeeper.CurrentKeeper.GetDatabase().GetItem(t.GetBackingItemId());
                     if (tokenItem != null)
                     {
                         if (!_cacheTime.ContainsKey(t.GetBackingItemId()) ||
                             tokenItem.Statistics.Updated > _cacheTime[t.GetBackingItemId()])
                         {
                             _tokens[token] = InitiateToken(token);
                             _cacheTime[t.GetBackingItemId()] = tokenItem.Statistics.Updated;
                             return(_tokens[token]);
                         }
                     }
                 }
                 else
                 {
                     return(_tokens[token]);
                 }
             }
         }
     }
     _tokens[token] = InitiateToken(token);
     return(_tokens[token]);
 }
 private static dynamic ResolveToken(IToken token)
 {
     dynamic ret = new ExpandoObject();
     ret.Label = token.Token;
     ret.Icon = "";
     ID tokenBackingItemId = token.GetBackingItemId();
     if (tokenBackingItemId != (ID)null)
     {
         var tokenItem = TokenKeeper.CurrentKeeper.GetDatabase().GetItem(token.GetBackingItemId());
         ret.Icon = "";
         if (tokenItem != null)
         {
             ret.Icon = tokenItem[FieldIDs.Icon];
             if (string.IsNullOrWhiteSpace(ret.Icon))
                 ret.Icon = tokenItem.Template.InnerItem[FieldIDs.Icon];
         }
     }
     if (string.IsNullOrWhiteSpace(ret.Icon))
         ret.Icon = "Office/32x32/package.png";
     return ret;
 }