コード例 #1
0
 public bool push(PhpValue value)
 {
     if (!this.exists(value))
     {
         this.ticktock++;
         return(this.CSRedis.ZAdd(this.key, (this.ticktock, value.ToString(this.ctx))) == 1);
     }
     return(false);
 }
コード例 #2
0
ファイル: Locale.cs プロジェクト: zhangwenquan/peachpie
        /// <summary>
        /// Searches in given objects for a locale string describing an existing culture.
        /// </summary>
        /// <param name="ctx">Current runtime context.</param>
        /// <param name="locale">Contains either an instance of <see cref="PhpArray"/> containing locales or a locale.</param>
        /// <param name="moreLocales">If <paramref name="locale"/> is not of type <see cref="PhpArray"/> contains locales, ignored otherwise.</param>
        /// <param name="culture">The resulting culture. A <B>null</B> reference means no culture has been found.</param>
        /// <returns>Whether a culture settings should be changed.</returns>
        static bool GetFirstExistingCulture(Context ctx, PhpValue locale, PhpValue[] moreLocales, out CultureInfo culture)
        {
            PhpArray array;
            IEnumerator <PhpValue> locales;

            culture = null;

            if ((array = locale.ArrayOrNull()) != null)
            {
                // locales are stored in the "locale" array:
                locales = array.Values.GetEnumerator();
                locales.MoveNext();
                locale = locales.Current;
            }
            else if (moreLocales != null)
            {
                // locales are stored in the "locale" and "moreLocales":
                locales = moreLocales.AsEnumerable().GetEnumerator();
            }
            else
            {
                throw new ArgumentNullException(nameof(moreLocales));
            }

            // enumerates locales and finds out the first which is valid:
            for (;;)
            {
                var name = locale.IsNull ? null : locale.ToString(ctx);

                culture = GetCultureByName(name);

                // name is "empty" then the current culture is not changed:
                if (name == null || name == "0")
                {
                    return(false);
                }

                // if culture exists and is specific then finish searching:
                if (culture != null)
                {
                    return(true);
                }

                // the next locale:
                if (!locales.MoveNext())
                {
                    return(false);
                }

                locale = locales.Current;
            }
        }
コード例 #3
0
        protected virtual void NextImpl()
        {
            var innerIterator = getInnerIterator();

            _valid      = innerIterator.valid();
            _currentVal = innerIterator.current();
            _currentKey = innerIterator.key();

            if ((_flags & CALL_TOSTRING) != 0)
            {
                _currentString = _currentVal.ToString(_ctx);
            }
            else if ((_flags & TOSTRING_USE_INNER) != 0)
            {
                _currentString = _iterator.ToString();
            }

            if (_valid && IsFullCacheEnabled)
            {
                bool isKeyConverted = _currentKey.TryToIntStringKey(out var key);
                Debug.Assert(isKeyConverted);                                       // It was already used as a key in the previous iterator

                _cache.Add(key, _currentVal);
            }

            try
            {
                innerIterator.next();
            }
            catch (System.Exception)
            {
                if ((_flags & CATCH_GET_CHILD) == 0)
                {
                    throw;
                }
            }
        }
コード例 #4
0
ファイル: RedisQueue.cs プロジェクト: jingmian/NULASpider
        public bool exists(PhpValue value)
        {
            // TODO: 性能问题
            var count = this.count();

            if (count == 0)
            {
                return(false);
            }
            for (int i = 0; i < Math.Ceiling(count / 500d); i++)
            {
                var start    = i * 500;
                var contains = this.CSRedis.LRange(this.key, start, start + 500 - 1).Contains(value.ToString(this.ctx));
                if (contains)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #5
0
ファイル: RedisQueue.cs プロジェクト: jingmian/NULASpider
 public void push(PhpValue value)
 {
     this.CSRedis.RPush(this.key, value.ToString(this.ctx));
 }
コード例 #6
0
        public void __construct(Context ctx, PhpValue @class, string name)
        {
            if (name != null)
            {
                _tinfo   = ReflectionUtils.ResolvePhpTypeInfo(ctx, @class);
                _routine = _tinfo.RuntimeMethods[name] ?? throw new ReflectionException(string.Format(Resources.Resources.method_does_not_exist, _tinfo.Name, name));
            }
            else if (@class.IsString(out var class_method))
            {
                __construct(ctx, class_method);
            }
            else
            {
                throw new ReflectionException(string.Format("Invalid method name '{0}'", @class.ToString(ctx)));
            }

            // get the real declaring type from routine:
            _tinfo = _routine.DeclaringType ?? _tinfo;
        }
コード例 #7
0
 public bool push(PhpValue value)
 {
     return(this.count() == this.CSRedis.RPush(this.key, value.ToString(this.ctx)) - 1);
 }