Example #1
0
        public static ExchangeList GetListExchangePaginated(int offset, int limit)
        {
            if (offset < 0 || limit < 0)
            {
                throw new ArgumentException("offset and limit value must be >= 0");
            }

            long latest_num = Manager.Instance.DBManager.DynamicProperties.GetLatestExchangeNum();

            if (latest_num <= offset)
            {
                throw new ArgumentException("latest num is " + latest_num + ". offset num  must be smaller than latest.");
            }

            limit = limit > Parameter.DatabaseParameters.EXCHANGE_COUNT_LIMIT_MAX ? Parameter.DatabaseParameters.EXCHANGE_COUNT_LIMIT_MAX : limit;
            long end = offset + limit;

            end = end > latest_num ? latest_num : end;

            ExchangeList result = new ExchangeList();

            for (int i = offset; i < end; i++)
            {
                ExchangeCapsule exchange = Manager.Instance.DBManager.ExchangeFinal.Get(ExchangeCapsule.CalculateDatabaseKey(i));
                if (exchange != null)
                {
                    result.Exchanges.Add(exchange.Instance);
                }
            }

            return(result);
        }