예제 #1
0
        public IEnumerable <IDataObject> GetList(IZetboxContext ctx, InterfaceType ifType, int maxListCount, bool eagerLoadLists, IEnumerable <Expression> filter, IEnumerable <OrderBy> orderBy, out List <IStreamable> auxObjects)
        {
            int resultCount = 0;
            List <IStreamable> tmpAuxObjects = null;
            var _ifType = ifType.ToSerializableType();
            var ticks   = _perfCounter.IncrementGetList(ifType);

            try
            {
                var _filter = filter != null?filter.Select(f => SerializableExpression.FromExpression(f, _iftFactory)).ToArray() : null;

                var _orderBy = orderBy != null?orderBy.Select(o => new OrderByContract()
                {
                    Type = o.Type, Expression = SerializableExpression.FromExpression(o.Expression, _iftFactory)
                }).ToArray() : null;

                byte[] bytes = null;

                MakeRequest(() =>
                {
                    bytes = _service.GetList(
                        ZetboxGeneratedVersionAttribute.Current,
                        _ifType,
                        maxListCount,
                        eagerLoadLists,
                        _filter,
                        _orderBy);
                });

                Logging.Facade.DebugFormat("GetList retrieved: {0:n0} bytes", bytes.Length);

                IEnumerable <IDataObject> result = null;
                using (var sr = _readerFactory(new BinaryReader(new MemoryStream(bytes))))
                {
                    result = ReceiveObjects(ctx, sr, out tmpAuxObjects).Cast <IDataObject>();
                }
                resultCount = result.Count();
                auxObjects  = tmpAuxObjects;
                return(result);
            }
            finally
            {
                _perfCounter.DecrementGetList(ifType, resultCount, ticks);
            }
        }
예제 #2
0
        /// <summary>
        /// Returns a list of objects from the datastore, matching the specified filters.
        /// </summary>
        /// <param name="version">Current version of generated Zetbox.Objects assembly</param>
        /// <param name="type">Type of Objects</param>
        /// <param name="maxListCount">Max. ammount of objects</param>
        /// <param name="eagerLoadLists">If true list properties will be eager loaded</param>
        /// <param name="filter">Serializable linq expression used a filter</param>
        /// <param name="orderBy">List of derializable linq expressions used as orderby</param>
        /// <returns>the found objects</returns>
        public byte[] GetList(Guid version, SerializableType type, int maxListCount, bool eagerLoadLists, SerializableExpression[] filter, OrderByContract[] orderBy)
        {
            using (Logging.Facade.DebugTraceMethodCallFormat("GetList", "type={0}", type))
            {
                DebugLogIdentity();
                try
                {
                    if (type == null)
                    {
                        throw new ArgumentNullException("type");
                    }
                    var ifType      = _iftFactory(type.GetSystemType());
                    int resultCount = 0;
                    var ticks       = _perfCounter.IncrementGetList(ifType);
                    try
                    {
                        using (IZetboxContext ctx = _ctxFactory())
                        {
                            var filterExpresstions = filter != null?filter.Select(f => SerializableExpression.ToExpression(f)).ToList() : null;

                            IEnumerable <IStreamable> lst = _sohFactory
                                                            .GetServerObjectHandler(ifType)
                                                            .GetList(version, ctx, maxListCount,
                                                                     filterExpresstions,
                                                                     orderBy != null ? orderBy.Select(o => new OrderBy(o.Type, SerializableExpression.ToExpression(o.Expression))).ToList() : null);
                            resultCount = lst.Count();
                            return(SendObjects(lst, eagerLoadLists).ToArray());
                        }
                    }
                    finally
                    {
                        _perfCounter.DecrementGetList(ifType, resultCount, ticks);
                    }
                }
                catch (Exception ex)
                {
                    Helper.ThrowFaultException(ex);
                    // Never called, Handle errors throws an Exception
                    return(null);
                }
            }
        }