コード例 #1
0
        /// <summary>
        /// Returns the return value of the method call in <paramref name="ex"/>.
        /// </summary>
        /// <param name="ex"><see cref="SerializableMethodCallExpression"/> to invoke.</param>
        /// <returns>Returns the return value of the method call in <paramref name="ex"/>.</returns>
        protected object InvokeMethodCall(SerializableMethodCallExpression ex)
        {
            if (ex.Method.DeclaringType.GetClrVersion() == typeof(Queryable))
            {
                List <object> args           = new List <object>();
                Type[]        parameterTypes = ex.Method.ParameterTypes.Select(p => (Type)p.GetClrVersion()).ToArray();
                for (int i = 0; i < ex.Arguments.Count && i < parameterTypes.Length; i++)
                {
                    SerializableExpression currentArg = ex.Arguments[i];
                    Type currentParameterType         = parameterTypes[i];
                    if (typeof(Expression).IsAssignableFrom(currentParameterType))
                    {
                        args.Add(((UnaryExpression)Visit(currentArg)).Operand);
                    }
                    else
                    {
                        args.Add(VisitResult(currentArg));
                    }
                }
                return(((MethodInfo)ex.Method.GetClrVersion()).Invoke(ex.Object, args.ToArray()));
            }

            // If the method is not of DeclaringType "Queryable", it mustn't be invoked.
            // Without this check, we were able to delete files from the server disk
            // using System.IO.File.Delete( ... )!
            throw new SecurityException(string.Format("Could not call method '{0}' of type '{1}'. Type must be Queryable.", ex.Method.Name, ex.Method.DeclaringType.Name));
        }
コード例 #2
0
        /// <summary>
        /// Returns the value of the <see cref="Expression"/>.
        /// </summary>
        /// <param name="expression"><see cref="Expression"/> to visit.</param>
        /// <returns>Returns the value of the <see cref="Expression"/>.</returns>
        public object VisitResult(SerializableExpression expression)
        {
            if (expression == null)
            {
                return(null);
            }
            if (convertedObjects.ContainsKey(expression.HashCode))
            {
                return(convertedObjects[expression.HashCode]);
            }

            object foundObject;

            if (expression is SerializableConstantExpression)
            {
                foundObject = GetResultConstantExpression((SerializableConstantExpression)expression);
            }
            else if (expression is SerializableMethodCallExpression)
            {
                foundObject = GetResultMethodCallExpression((SerializableMethodCallExpression)expression);
            }
            else
            {
                throw new NotImplementedException();
            }
            convertedObjects[expression.HashCode] = foundObject;
            return(foundObject);
        }
コード例 #3
0
        public void roundtrip_Constant_string()
        {
            ConstantExpression expr = Expression.Constant("a");
            var result = (ConstantExpression)SerializableExpression.ToExpression(SerializableExpression.FromExpression(expr, iftFactory));

            AssertExpressions.AreEqual(result, expr);
        }
コード例 #4
0
        /// <summary>
        /// Retrieves data from the server by an <see cref="SerializableExpression">Expression</see> tree.
        /// </summary>
        /// <typeparam name="T">Type of the <see cref="IQueryable"/>.</typeparam>
        /// <param name="serializableExpression">
        ///     <see cref="SerializableExpression">Expression</see> tree
        ///     containing selection and projection.
        /// </param>
        /// <returns>Returns requested data.</returns>
        /// <seealso cref="IQueryRemoteHandler.Retrieve"/>
        /// <remarks>
        /// This method's return type depends on the submitted
        /// <see cref="SerializableExpression">Expression</see> tree.
        /// Here some examples ('T' is the requested type):
        /// <list type="list">
        ///     <listheader>
        ///         <term>Method</term>
        ///         <description>Return Type</description>
        ///     </listheader>
        ///     <item>
        ///         <term>Select(...)</term>
        ///         <description>T[;</description>
        ///     </item>
        ///     <item>
        ///         <term>First(...), Last(...)</term>
        ///         <description>T</description>
        ///     </item>
        ///     <item>
        ///         <term>Count(...)</term>
        ///         <description><see langword="int"/></description>
        ///     </item>
        ///     <item>
        ///         <term>Contains(...)</term>
        ///         <description><see langword="bool"/></description>
        ///     </item>
        /// </list>
        /// </remarks>
        public object RetrieveGeneric <T>(SerializableExpression serializableExpression)
        {
            object session = null;

            try
            {
                session = QueryHandler.StartSession();
                IQueryable <T> query = serializableExpression.Convert(QueryHandler, session) as IQueryable <T>;
                if (query != null)
                {
                    var    returnValue          = query.ToArray();
                    object convertedReturnValue = TypeConverter.ConvertToSerializable(returnValue);
                    return(convertedReturnValue);
                }
                return(null);
            }
            catch
            {
                throw;
            }
            finally
            {
                QueryHandler.CloseSession(session);
            }
        }
コード例 #5
0
        /// <summary>
        /// Executes the query and returns the requested data.
        /// </summary>
        /// <param name="expression"><see cref="Expression"/> tree to execute.</param>
        /// <returns>Returns the requested data of Type <see langword="object"/>.</returns>
        /// <seealso cref="InterLinqQueryProvider.Execute"/>
        public override object Execute(Expression expression)
        {
            SerializableExpression serExp = expression.MakeSerializable();

#if !SILVERLIGHT
            object receivedObject = Handler.Retrieve(serExp);
#else
            IAsyncResult asyncResult    = Handler.BeginRetrieve(serExp, null, null);
            object       receivedObject = null;

            if (!asyncResult.CompletedSynchronously)
            {
                asyncResult.AsyncWaitHandle.WaitOne();
            }

            try
            {
                receivedObject = Handler.EndRetrieve(asyncResult);
            }
            catch
            {
                throw;
            }
            finally
            {
#if !NETFX_CORE
                asyncResult.AsyncWaitHandle.Close();
#else
                asyncResult.AsyncWaitHandle.Dispose();
#endif
            }
#endif
            return(receivedObject);
        }
コード例 #6
0
        /// <summary>
        /// Executes the query and returns the requested data.
        /// </summary>
        /// <param name="expression"><see cref="Expression"/> tree to execute.</param>
        /// <returns>Returns the requested data of Type <see langword="object"/>.</returns>
        /// <seealso cref="InterLinqQueryProvider.Execute"/>
        public override object Execute(Expression expression)
        {
            SerializableExpression serExp = expression.MakeSerializable();
            object receivedObject         = Handler.Retrieve(serExp);

            return(receivedObject);
        }
コード例 #7
0
        public void roundtrip_Constant_object()
        {
            ISomething         value = new Something();
            ConstantExpression expr  = Expression.Constant(value);
            var result = (ConstantExpression)SerializableExpression.ToExpression(SerializableExpression.FromExpression(expr, iftFactory));

            AssertExpressions.AreEqual(result, expr);
        }
コード例 #8
0
 /// <summary>
 /// Initializes this class.
 /// </summary>
 /// <param name="expression"><see cref="SerializableExpression"/> to convert.</param>
 protected SerializableExpressionVisitor(SerializableExpression expression)
 {
     if (expression == null)
     {
         throw new ArgumentNullException("expression");
     }
     ExpressionToConvert = expression;
 }
コード例 #9
0
        public void roundtrip_Constant_interface()
        {
            ISomething         value = new Something();
            ConstantExpression expr  = Expression.Constant(value, typeof(ISomething));
            var result = (ConstantExpression)SerializableExpression.ToExpression(SerializableExpression.FromExpression(expr, iftFactory));

            AssertExpressions.AreEqual(result, expr);
            Assert.That(result.Type, Is.EqualTo(typeof(ISomething)));
        }
コード例 #10
0
 /// <summary>
 /// Initializes this class.
 /// </summary>
 /// <param name="expression"><see cref="SerializableExpression"/> to convert.</param>
 /// <param name="queryHandler"><see cref="IQueryHandler"/>.</param>
 public SerializableExpressionConverter(SerializableExpression expression, IQueryHandler queryHandler)
     : base(expression)
 {
     if (queryHandler == null)
     {
         throw new ArgumentNullException("queryHandler");
     }
     QueryHandler = queryHandler;
 }
コード例 #11
0
        public void roundtrip_MemberAccess_to_string_Length_property_should_optimize_constness()
        {
            string           testString = "farglbl";
            var              objExpr    = Expression.Constant(testString);
            MemberExpression expr       = Expression.MakeMemberAccess(objExpr, typeof(string).GetMember("Length").First());

            var result = SerializableExpression.ToExpression(SerializableExpression.FromExpression(expr, scope.Resolve <InterfaceType.Factory>()));

            AssertExpressions.AreEqual(result, Expression.Constant(testString.Length));
        }
コード例 #12
0
        /// <summary>
        /// Deserializes the specified xml to an <see cref="Expression"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static Expression <T> DeserializeExpression <T>(string xml)
        {
            if (string.IsNullOrEmpty(xml))
            {
                throw new ArgumentNullException("xml");
            }

            SerializableExpression          expression = Deserialize <SerializableExpression>(xml);
            SerializableExpressionConverter converter  = new SerializableExpressionConverter(expression, new DummyQueryHandler());

            return(converter.Visit(expression) as Expression <T>);
        }
コード例 #13
0
        /// <summary>
        /// Retrieves data from the server by an <see cref="SerializableExpression">Expression</see> tree.
        /// </summary>
        /// <remarks>
        /// This method's return type depends on the submitted
        /// <see cref="SerializableExpression">Expression</see> tree.
        /// Here some examples ('T' is the requested type):
        /// <list type="list">
        ///     <listheader>
        ///         <term>Method</term>
        ///         <description>Return Type</description>
        ///     </listheader>
        ///     <item>
        ///         <term>Select(...)</term>
        ///         <description>T[;</description>
        ///     </item>
        ///     <item>
        ///         <term>First(...), Last(...)</term>
        ///         <description>T</description>
        ///     </item>
        ///     <item>
        ///         <term>Count(...)</term>
        ///         <description><see langword="int"/></description>
        ///     </item>
        ///     <item>
        ///         <term>Contains(...)</term>
        ///         <description><see langword="bool"/></description>
        ///     </item>
        /// </list>
        /// </remarks>
        /// <param name="expression">
        ///     <see cref="SerializableExpression">Expression</see> tree
        ///     containing selection and projection.
        /// </param>
        /// <returns>Returns requested data.</returns>
        /// <seealso cref="IQueryRemoteHandler.Retrieve"/>
        public object Retrieve(SerializableExpression expression)
        {
            try
            {
//#if DEBUG
//                Console.WriteLine(expression);
//                Console.WriteLine();
//#endif

                MethodInfo mInfo;
                Type       realType = (Type)expression.Type.GetClrVersion();
                if (typeof(IQueryable).IsAssignableFrom(realType) &&
                    realType.GetGenericArguments().Length == 1)
                {
                    // Find Generic Retrieve Method
                    mInfo = typeof(ServerQueryHandler).GetMethod("RetrieveGeneric");
                    mInfo = mInfo.MakeGenericMethod(realType.GetGenericArguments()[0]);
                }
                else
                {
                    // Find Non-Generic Retrieve Method
                    mInfo = typeof(ServerQueryHandler).GetMethod("RetrieveNonGenericObject");
                }

                object returnValue = mInfo.Invoke(this, new object[] { expression });

//#if !SILVERLIGHT && DEBUG
//                try
//                {
//                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
//                    new System.Runtime.Serialization.NetDataContractSerializer().Serialize(ms, returnValue);
//                }
//                catch (Exception)
//                {
//                    throw;
//                }
//#endif

                return(returnValue);
            }
            catch (Exception ex)
            {
                if (!HandleExceptionInRetrieve(ex))
                {
                    throw;
                }
                else
                {
                    return(null);
                }
            }
        }
コード例 #14
0
 /// <summary>
 /// Retrieves data from the server by an <see cref="SerializableExpression">Expression</see> tree.
 /// </summary>
 /// <param name="serializableExpression">
 ///     <see cref="SerializableExpression">Expression</see> tree
 ///     containing selection and projection.
 /// </param>
 /// <returns>Returns requested data.</returns>
 /// <remarks>
 /// This method's return type depends on the submitted
 /// <see cref="SerializableExpression">Expression</see> tree.
 /// Here some examples ('T' is the requested type):
 /// <list type="list">
 ///     <listheader>
 ///         <term>Method</term>
 ///         <description>Return Type</description>
 ///     </listheader>
 ///     <item>
 ///         <term>Select(...)</term>
 ///         <description>T[]</description>
 ///     </item>
 ///     <item>
 ///         <term>First(...), Last(...)</term>
 ///         <description>T</description>
 ///     </item>
 ///     <item>
 ///         <term>Count(...)</term>
 ///         <description><see langword="int"/></description>
 ///     </item>
 ///     <item>
 ///         <term>Contains(...)</term>
 ///         <description><see langword="bool"/></description>
 ///     </item>
 /// </list>
 /// </remarks>
 /// <seealso cref="IQueryRemoteHandler.Retrieve"/>
 public object RetrieveNonGenericObject(SerializableExpression serializableExpression)
 {
     try
     {
         QueryHandler.StartSession();
         object returnValue          = serializableExpression.Convert(QueryHandler);
         object convertedReturnValue = TypeConverter.ConvertToSerializable(returnValue);
         return(convertedReturnValue);
     }
     finally
     {
         QueryHandler.CloseSession();
     }
 }
コード例 #15
0
        /// <summary>
        /// Retrieves data from the server by an <see cref="SerializableExpression">Expression</see> tree.
        /// </summary>
        /// <remarks>
        /// This method's return type depends on the submitted
        /// <see cref="SerializableExpression">Expression</see> tree.
        /// Here some examples ('T' is the requested type):
        /// <list type="list">
        ///     <listheader>
        ///         <term>Method</term>
        ///         <description>Return Type</description>
        ///     </listheader>
        ///     <item>
        ///         <term>Select(...)</term>
        ///         <description>T[]</description>
        ///     </item>
        ///     <item>
        ///         <term>First(...), Last(...)</term>
        ///         <description>T</description>
        ///     </item>
        ///     <item>
        ///         <term>Count(...)</term>
        ///         <description><see langword="int"/></description>
        ///     </item>
        ///     <item>
        ///         <term>Contains(...)</term>
        ///         <description><see langword="bool"/></description>
        ///     </item>
        /// </list>
        /// </remarks>
        /// <param name="expression">
        ///     <see cref="SerializableExpression">Expression</see> tree
        ///     containing selection and projection.
        /// </param>
        /// <returns>Returns requested data.</returns>
        /// <seealso cref="IQueryRemoteHandler.Retrieve"/>
        public object Retrieve(SerializableExpression expression)
        {
            try
            {
#if DEBUG
                Trace.WriteLine(expression);
#endif

                MethodInfo mInfo;
                Type       realType = (Type)expression.Type.GetClrVersion();
                if (typeof(IQueryable).IsAssignableFrom(realType) &&
                    realType.GetGenericArguments().Length == 1)
                {
                    // Find Generic Retrieve Method
                    mInfo = GetType().GetMethod("RetrieveGeneric");
                    mInfo = mInfo.MakeGenericMethod(realType.GetGenericArguments()[0]);
                }
                else
                {
                    // Find Non-Generic Retrieve Method
                    mInfo = GetType().GetMethod("RetrieveNonGenericObject");
                }

                object returnValue = mInfo.Invoke(this, new object[] { expression });

#if DEBUG
                // NetDataContractSerializer is not supported by Mono Framework
                //try
                //{
                //	System.IO.MemoryStream ms = new System.IO.MemoryStream();
                //	new System.Runtime.Serialization.NetDataContractSerializer().Serialize(ms, returnValue);
                //}
                //catch (Exception)
                //{
                //	throw;
                //}
#endif

                return(returnValue);
            }
            catch (Exception ex)
            {
                HandleExceptionInRetrieve(ex);
                throw;
            }
        }
コード例 #16
0
 /// <summary>
 /// Retrieves data from the server by an <see cref="SerializableExpression">Expression</see> tree.
 /// </summary>
 /// <typeparam name="T">Type of the <see cref="IQueryable"/>.</typeparam>
 /// <param name="serializableExpression">
 ///     <see cref="SerializableExpression">Expression</see> tree
 ///     containing selection and projection.
 /// </param>
 /// <returns>Returns requested data.</returns>
 /// <seealso cref="IQueryRemoteHandler.Retrieve"/>
 /// <remarks>
 /// This method's return type depends on the submitted
 /// <see cref="SerializableExpression">Expression</see> tree.
 /// Here some examples ('T' is the requested type):
 /// <list type="list">
 ///     <listheader>
 ///         <term>Method</term>
 ///         <description>Return Type</description>
 ///     </listheader>
 ///     <item>
 ///         <term>Select(...)</term>
 ///         <description>T[]</description>
 ///     </item>
 ///     <item>
 ///         <term>First(...), Last(...)</term>
 ///         <description>T</description>
 ///     </item>
 ///     <item>
 ///         <term>Count(...)</term>
 ///         <description><see langword="int"/></description>
 ///     </item>
 ///     <item>
 ///         <term>Contains(...)</term>
 ///         <description><see langword="bool"/></description>
 ///     </item>
 /// </list>
 /// </remarks>
 public object RetrieveGeneric <T>(SerializableExpression serializableExpression)
 {
     try
     {
         QueryHandler.StartSession();
         IQueryable <T> query = serializableExpression.Convert(QueryHandler) as IQueryable <T>;
         // ReSharper disable AssignNullToNotNullAttribute
         var returnValue = query.ToArray();
         // ReSharper restore AssignNullToNotNullAttribute
         object convertedReturnValue = TypeConverter.ConvertToSerializable(returnValue);
         return(convertedReturnValue);
     }
     finally
     {
         QueryHandler.CloseSession();
     }
 }
コード例 #17
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);
            }
        }
コード例 #18
0
 /// <summary>
 /// Retrieves data from the server by an <see cref="SerializableExpression">Expression</see> tree.
 /// </summary>
 /// <remarks>
 /// This method's return type depends on the submitted
 /// <see cref="SerializableExpression">Expression</see> tree.
 /// Here some examples ('T' is the requested type):
 /// <list type="list">
 ///     <listheader>
 ///         <term>Method</term>
 ///         <description>Return Type</description>
 ///     </listheader>
 ///     <item>
 ///         <term>Select(...)</term>
 ///         <description>T[]</description>
 ///     </item>
 ///     <item>
 ///         <term>First(...), Last(...)</term>
 ///         <description>T</description>
 ///     </item>
 ///     <item>
 ///         <term>Count(...)</term>
 ///         <description><see langword="int"/></description>
 ///     </item>
 ///     <item>
 ///         <term>Contains(...)</term>
 ///         <description><see langword="bool"/></description>
 ///     </item>
 /// </list>
 /// </remarks>
 /// <param name="expression">
 ///     <see cref="SerializableExpression">Expression</see> tree
 ///     containing selection and projection.
 /// </param>
 /// <returns>Returns requested data.</returns>
 /// <seealso cref="IQueryRemoteHandler.Retrieve"/>
 public object Retrieve(SerializableExpression expression)
 {
     try
     {
         return(Handler.Retrieve(expression));
     }
     catch (FaultException ex)
     {
         Console.WriteLine("Test Failed on server.");
         handler = null;
         throw new Exception("The execution of the query failed on the server. See inner exception for more details.", ex);
     }
     catch (Exception)
     {
         Console.WriteLine("Test Failed.");
         handler = null;
         throw;
     }
 }
コード例 #19
0
        /// <summary>
        /// Retrieves data from the server by an <see cref="SerializableExpression">Expression</see> tree.
        /// </summary>
        /// <param name="serializableExpression">
        ///     <see cref="SerializableExpression">Expression</see> tree
        ///     containing selection and projection.
        /// </param>
        /// <returns>Returns requested data.</returns>
        /// <remarks>
        /// This method's return type depends on the submitted
        /// <see cref="SerializableExpression">Expression</see> tree.
        /// Here some examples ('T' is the requested type):
        /// <list type="list">
        ///     <listheader>
        ///         <term>Method</term>
        ///         <description>Return Type</description>
        ///     </listheader>
        ///     <item>
        ///         <term>Select(...)</term>
        ///         <description>T[;</description>
        ///     </item>
        ///     <item>
        ///         <term>First(...), Last(...)</term>
        ///         <description>T</description>
        ///     </item>
        ///     <item>
        ///         <term>Count(...)</term>
        ///         <description><see langword="int"/></description>
        ///     </item>
        ///     <item>
        ///         <term>Contains(...)</term>
        ///         <description><see langword="bool"/></description>
        ///     </item>
        /// </list>
        /// </remarks>
        /// <seealso cref="IQueryRemoteHandler.Retrieve"/>
        public object RetrieveNonGenericObject(SerializableExpression serializableExpression)
        {
            object session = null;

            try
            {
                session = QueryHandler.StartSession();
                object returnValue          = serializableExpression.Convert(QueryHandler, session);
                object convertedReturnValue = TypeConverter.ConvertToSerializable(returnValue);
                return(convertedReturnValue);
            }
            catch
            {
                throw;
            }
            finally
            {
                QueryHandler.CloseSession(session);
            }
        }
コード例 #20
0
            public void should_roundtrip_nulls()
            {
                SerializableExpression value = null;

                int preGuardValue  = 0x0eadbeef;
                int postGuardValue = 0x00c0ffee;

                sw.Write(preGuardValue);
                sw.Write(value);
                sw.Write(postGuardValue);
                sw.Flush();

                ms.Seek(0, SeekOrigin.Begin);

                Assert.That(sr.ReadInt32(), Is.EqualTo(preGuardValue), "inital guard wrong");

                SerializableExpression fromval;

                sr.Read(out fromval, null);
                Assert.That(sr.ReadInt32(), Is.EqualTo(postGuardValue), "final guard wrong");

                Assert.That(fromval, Is.Null);
                Assert.That(ms.Position, Is.EqualTo(ms.Length), "stream not read completely");
            }
コード例 #21
0
 /// <summary>
 /// Visits a <see cref="SerializableExpression"/>.
 /// </summary>
 /// <param name="expression"><see cref="SerializableExpression"/> to visit.</param>
 /// <returns>Returns the converted <see cref="Expression"/>.</returns>
 protected override Expression VisitUnknownSerializableExpression(SerializableExpression expression)
 {
     throw new Exception(string.Format("Expression \"{0}\" could not be handled.", expression));
 }
コード例 #22
0
 /// <summary>
 /// Retrieves data from the server by an <see cref="SerializableExpression">Expression</see> tree.
 /// </summary>
 /// <remarks>
 /// This method's return type depends on the submitted
 /// <see cref="SerializableExpression">Expression</see> tree.
 /// Here some examples ('T' is the requested type):
 /// <list type="list">
 ///     <listheader>
 ///         <term>Method</term>
 ///         <description>Return Type</description>
 ///     </listheader>
 ///     <item>
 ///         <term>Select(...)</term>
 ///         <description>T[]</description>
 ///     </item>
 ///     <item>
 ///         <term>First(...), Last(...)</term>
 ///         <description>T</description>
 ///     </item>
 ///     <item>
 ///         <term>Count(...)</term>
 ///         <description><see langword="int"/></description>
 ///     </item>
 ///     <item>
 ///         <term>Contains(...)</term>
 ///         <description><see langword="bool"/></description>
 ///     </item>
 /// </list>
 /// </remarks>
 /// <param name="expression">
 ///     <see cref="SerializableExpression">Expression</see> tree
 ///     containing selection and projection.
 /// </param>
 /// <returns>Returns requested data.</returns>
 /// <seealso cref="IQueryRemoteHandler.Retrieve"/>
 public object Retrieve(SerializableExpression expression)
 {
     return(InnerHandler.Retrieve(expression));
 }
コード例 #23
0
ファイル: HttpServiceClient.cs プロジェクト: daszat/zetbox
 public byte[] GetObjects(Guid version, SerializableExpression query)
 {
     return MakeRequest(GetObjectsUri,
       reqStream =>
       {
           reqStream.Write(version);
           reqStream.Write(query);
           reqStream.WriteRaw(Encoding.ASCII.GetBytes("\n"));// required for basic.authenticated POST to apache
       });
 }
コード例 #24
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);
                }
            }
        }
コード例 #25
0
        public void GivenNonNullExpressionWhenConstructorCalledThenShouldSetType()
        {
            var target = new SerializableExpression(Expression.Constant(5));

            Assert.Equal(ExpressionType.Constant, (ExpressionType)target.Type);
        }
コード例 #26
0
 public void FromExpression_null_fails()
 {
     Assert.That(() => SerializableExpression.FromExpression(null, iftFactory), Throws.InstanceOf <ArgumentNullException>());
 }
コード例 #27
0
 /// <summary>
 /// Converts specified <see cref="SerializableExpression"/> to <see cref="Expression"/>.
 /// </summary>
 /// <param name="expression">The expression to convert.</param>
 /// <returns></returns>
 public static Expression ToExpression(this SerializableExpression expression)
 {
     return(new SerializableExpressionToExpressionConverter(expression).Convert());
 }
コード例 #28
0
        /// <summary>
        /// Returns an <see cref="Expression"/> by visiting and converting <paramref name="expression"/>.
        /// </summary>
        /// <param name="expression"><see cref="SerializableExpression"/> to visit.</param>
        /// <returns>Returns an <see cref="Expression"/> by visiting and converting <paramref name="expression"/>.</returns>
        public Expression Visit(SerializableExpression expression)
        {
            if (expression == null)
            {
                return(null);
            }
            if (convertedObjects.ContainsKey(expression.HashCode))
            {
                return((Expression)convertedObjects[expression.HashCode]);
            }

            Expression returnValue;

            if (expression is SerializableBinaryExpression)
            {
                returnValue = VisitSerializableBinaryExpression(expression as SerializableBinaryExpression);
            }
            else if (expression is SerializableConditionalExpression)
            {
                returnValue = VisitSerializableConditionalExpression(expression as SerializableConditionalExpression);
            }
            else if (expression is SerializableConstantExpression)
            {
                returnValue = VisitSerializableConstantExpression(expression as SerializableConstantExpression);
            }
            else if (expression is SerializableInvocationExpression)
            {
                returnValue = VisitSerializableInvocationExpression(expression as SerializableInvocationExpression);
            }
            else if (expression is SerializableLambdaExpression)
            {
                if (expression is SerializableExpressionTyped)
                {
                    MethodInfo executeMethod        = GetType().GetMethod("VisitSerializableExpressionTyped", BindingFlags.NonPublic | BindingFlags.Instance);
                    MethodInfo genericExecuteMethod = executeMethod.MakeGenericMethod(new[] { (Type)expression.Type.GetClrVersion() });
                    returnValue = (Expression)genericExecuteMethod.Invoke(this, new object[] { expression });
                }
                else
                {
                    returnValue = VisitSerializableLambdaExpression(expression as SerializableLambdaExpression);
                }
            }
            else if (expression is SerializableListInitExpression)
            {
                returnValue = VisitSerializableListInitExpression(expression as SerializableListInitExpression);
            }
            else if (expression is SerializableMemberExpression)
            {
                returnValue = VisitSerializableMemberExpression(expression as SerializableMemberExpression);
            }
            else if (expression is SerializableMemberInitExpression)
            {
                returnValue = VisitSerializableMemberInitExpression(expression as SerializableMemberInitExpression);
            }
            else if (expression is SerializableMethodCallExpression)
            {
                returnValue = VisitSerializableMethodCallExpression(expression as SerializableMethodCallExpression);
            }
            else if (expression is SerializableNewArrayExpression)
            {
                returnValue = VisitSerializableNewArrayExpression(expression as SerializableNewArrayExpression);
            }
            else if (expression is SerializableNewExpression)
            {
                returnValue = VisitSerializableNewExpression(expression as SerializableNewExpression);
            }
            else if (expression is SerializableParameterExpression)
            {
                returnValue = VisitSerializableParameterExpression(expression as SerializableParameterExpression);
            }
            else if (expression is SerializableTypeBinaryExpression)
            {
                returnValue = VisitSerializableTypeBinaryExpression(expression as SerializableTypeBinaryExpression);
            }
            else if (expression is SerializableUnaryExpression)
            {
                returnValue = VisitSerializableUnaryExpression(expression as SerializableUnaryExpression);
            }
            else
            {
                returnValue = VisitUnknownSerializableExpression(expression);
            }

            convertedObjects.Add(expression.HashCode, returnValue);
            return(returnValue);
        }
コード例 #29
0
 /// <summary>
 /// Visits a <see cref="SerializableExpression"/>.
 /// </summary>
 /// <param name="expression"><see cref="SerializableExpression"/> to visit.</param>
 /// <returns>Returns the converted <see cref="Expression"/>.</returns>
 protected abstract Expression VisitUnknownSerializableExpression(SerializableExpression expression);
コード例 #30
0
 public void ToExpression_null_fails()
 {
     Assert.That(() => SerializableExpression.ToExpression(null), Throws.InstanceOf <ArgumentNullException>());
 }
コード例 #31
0
ファイル: ZetboxService.cs プロジェクト: jrgcubano/zetbox
 /// <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;
         }
     }
 }
コード例 #32
0
ファイル: HttpServiceClient.cs プロジェクト: jrgcubano/zetbox
        public byte[] GetList(Guid version, SerializableType type, int maxListCount, bool eagerLoadLists, SerializableExpression[] filter, OrderByContract[] orderBy)
        {
            if (type == null) throw new ArgumentNullException("type");

            return MakeRequest(GetListUri,
                reqStream =>
                {
                    reqStream.Write(version);
                    reqStream.Write(type);
                    reqStream.Write(maxListCount);
                    reqStream.Write(eagerLoadLists);
                    reqStream.Write(filter);
                    reqStream.Write(orderBy);
                    reqStream.WriteRaw(Encoding.ASCII.GetBytes("\n"));// required for basic.authenticated POST to apache
                });
        }
コード例 #33
0
ファイル: ZetboxService.cs プロジェクト: daszat/zetbox
        /// <summary>
        /// Returns a list of objects from the datastore, as requested by the query.
        /// </summary>
        /// <param name="version">Current version of generated Zetbox.Objects assembly</param>
        /// <param name="query">A full LINQ query returning zero, one or more objects (FirstOrDefault, Single, Where, Skip, Take, etc.)</param>
        /// <returns>the found objects</returns>
        public byte[] GetObjects(Guid version, SerializableExpression query)
        {
            if (query == null) { throw new ArgumentNullException("query"); }
            using (Logging.Facade.DebugTraceMethodCallFormat("GetObjects", "query={0}", query))
            {
                DebugLogIdentity();
                try
                {
                    ZetboxGeneratedVersionAttribute.Check(version);

                    var type = query.SerializableType.GetSystemType();
                    var ifType = _iftFactory(type.IsGenericType && typeof(IQueryable).IsAssignableFrom(type)
                        ? type.GetGenericArguments()[0]
                        : type);
                    int resultCount = 0;
                    var ticks = _perfCounter.IncrementGetObjects(ifType);
                    try
                    {
                        using (IZetboxContext ctx = _ctxFactory())
                        {
                            IEnumerable<IStreamable> lst = _sohFactory
                                .GetServerObjectHandler(ifType)
                                .GetObjects(version, ctx, SerializableExpression.ToExpression(ctx, query, _iftFactory));
                            resultCount = lst.Count();
                            return SendObjects(lst, resultCount <= 1).ToArray();
                        }
                    }
                    finally
                    {
                        _perfCounter.DecrementGetObjects(ifType, resultCount, ticks);
                    }
                }
                catch (Exception ex)
                {
                    Helper.ThrowFaultException(ex);
                    // Never called, Handle errors throws an Exception
                    return null;
                }
            }
        }
 public SerializableExpressionToExpressionConverter(SerializableExpression source)
 {
     this.source = source;
     cache       = new Dictionary <SerializableExpression, Expression>();
 }