Ejemplo n.º 1
0
        /// <summary>
        ///     Adds the in queue.
        /// </summary>
        /// <param name="balancedDraw">The balanced draw.</param>
        /// <param name="action">The action.</param>
        /// <param name="isEditor">if set to <c>true</c> [is editor].</param>
        /// <param name="extender">The extender.</param>
        /// <param name="storedPredicate">The stored predicate.</param>
        /// <exception cref="ArgumentNullException">action</exception>
        public static void AddInQueue(UIBalancedDraw balancedDraw, Expression <Action <object[]> > action, bool isEditor,
                                      ExpressionExtender extender = null, Func <bool> storedPredicate = null)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            // If Editor, add once the actions to list
            // Else, call them (draw it)

            if (storedPredicate != null)
            {
                AddStoredPredicate(balancedDraw, action, extender, storedPredicate);
            }

            if (isEditor)
            {
                Add(balancedDraw, action, extender);
            }
            else
            {
                ExecuteCompiledAction(action, extender);
            }
        }
Ejemplo n.º 2
0
        public static ExpressionExtender GetByID(Guid ID)
        {
            Init();
            ExpressionExtender expressionExtender = null;

            if (methodsByIds.TryGetValue(ID, out expressionExtender))
            {
                return(expressionExtender);
            }
            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Adds the stored predicate.
        /// </summary>
        /// <param name="balancedDraw">The balanced draw.</param>
        /// <param name="action">The action.</param>
        /// <param name="extender">The extender.</param>
        /// <param name="storedPredicate">The stored predicate.</param>
        /// <returns></returns>
        private static bool AddStoredPredicate(UIBalancedDraw balancedDraw, Expression <Action <object[]> > action,
                                               ExpressionExtender extender, Func <bool> storedPredicate)
        {
            var key = GetKey(action, extender);

            if (balancedDraw.m_predicates.ContainsKey(key))
            {
                return(false);
            }

            balancedDraw.m_predicates.Add(key, storedPredicate);

            return(true);
        }
Ejemplo n.º 4
0
        ////////////////////////////////////////////////////////////////////

        public static ExpressionExtenderInfo FindByName(String Name)
        {
            Init();
            ExpressionExtender expressionExtender = null;

            if (methodsByNames.TryGetValue(Name, out expressionExtender))
            {
                return new ExpressionExtenderInfo()
                       {
                           ID = expressionExtender.ID
                       }
            }
            ;
            return(null);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Adds the in queue.
        /// </summary>
        /// <param name="balancedDraw">The balanced draw.</param>
        /// <param name="action">The action.</param>
        /// <param name="isEditor">if set to <c>true</c> [is editor].</param>
        /// <param name="predicate">The predicate.</param>
        /// <param name="extender">The extender.</param>
        /// <param name="storedPredicate">The stored predicate.</param>
        /// <exception cref="ArgumentNullException">predicate</exception>
        public static void AddInQueue(UIBalancedDraw balancedDraw, Expression <Action <object[]> > action, bool isEditor,
                                      Func <bool> predicate, ExpressionExtender extender = null, Func <bool> storedPredicate = null)
        {
            if (predicate == null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }

            if (predicate())
            {
                AddInQueue(balancedDraw, action, isEditor, extender, storedPredicate);
            }
            else
            {
                ExecuteCompiledAction(action, extender);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Adds the specified balanced draw.
        /// </summary>
        /// <param name="balancedDraw">The balanced draw.</param>
        /// <param name="action">The action.</param>
        /// <param name="extender">The extender.</param>
        /// <returns></returns>
        /// <exception cref="NullReferenceException"></exception>
        private static bool Add(UIBalancedDraw balancedDraw, Expression <Action <object[]> > action,
                                ExpressionExtender extender)
        {
            var key = GetKey(action, extender);

            if (balancedDraw.m_actions.ContainsKey(key))
            {
                return(false);
            }

            var compiledAction = action.Compile();

            if (compiledAction == null)
            {
                throw new NullReferenceException(NullCompiledActionMessage);
            }

            balancedDraw.m_actions.Add(key, compiledAction);
            balancedDraw.m_extenders.Add(key, extender);

            return(true);
        }
Ejemplo n.º 7
0
 /// <summary>
 ///     Gets the key.
 /// </summary>
 /// <param name="action">The action.</param>
 /// <param name="extender">The extender.</param>
 /// <returns></returns>
 private static string GetKey(Expression <Action <object[]> > action, ExpressionExtender extender)
 {
     return(action + extender?.Salt);
 }
Ejemplo n.º 8
0
        /// <summary>
        ///     Executes the compiled action.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="extender">The extender.</param>
        /// <exception cref="ArgumentNullException"></exception>
        private static void ExecuteCompiledAction(Expression <Action <object[]> > action, ExpressionExtender extender)
        {
            var compiledAction = action.Compile();

            if (compiledAction == null)
            {
                throw new ArgumentNullException(NullCompiledActionMessage);
            }

            compiledAction(extender?.Objects);
        }
Ejemplo n.º 9
0
        private static ExpressionMethodResult EvaluateInlineMethod(
            Object Object,
            Object Method,
            IList <Object> MethodParameters,
            DynLanContext DynLanContext)
        {
            if (Method is OnpMethodInfo)
            {
                OnpMethodInfo methodInfo = Method as OnpMethodInfo;

                DynamicCallResult callResult = MyReflectionHelper.CallMethod(
                    methodInfo.Obj,
                    methodInfo.MethodName,
                    CorrectParameters(MethodParameters));

                if (callResult != null)
                {
                    return(new ExpressionMethodResult(callResult.Value));
                }
            }
            else if (Method is OnpActionMethodInfo)
            {
                OnpActionMethodInfo methodInfo = Method as OnpActionMethodInfo;

                if (methodInfo != null && methodInfo.Action != null)
                {
                    return(new ExpressionMethodResult(methodInfo.Action(CorrectParameters(MethodParameters))));
                }
            }
            else if (Method is ExpressionMethod)
            {
                ExpressionMethod       onpMethod = Method as ExpressionMethod;
                ExpressionMethodResult result    = null;

                if (Object is EmptyObject)
                {
                    result = onpMethod.
                             CalculateValueDelegate(
                        DynLanContext,
                        CorrectParameters(MethodParameters));
                }
                else
                {
#if !NET20
                    var tmp = new[] { Object }.Union(MethodParameters);
#else
                    var tmp = Linq2.From(new[] { Object }).Union(MethodParameters).ToArray();
#endif
                    result = onpMethod.
                             CalculateValueDelegate(
                        DynLanContext,
                        CorrectParameters(tmp));
                }

                return(result == null ?
                       new ExpressionMethodResult(null) :
                       result);
            }
            else if (Method is ExpressionMethodInfo)
            {
                ExpressionMethodInfo   onpMethodInfo = Method as ExpressionMethodInfo;
                ExpressionMethod       onpMethod     = BuildinMethods.GetByID(onpMethodInfo.ID);
                ExpressionMethodResult result        = null;

                if (onpMethod == null)
                {
                    return(new ExpressionMethodResult(result));
                }

                if (Object is EmptyObject)
                {
                    result = onpMethod.
                             CalculateValueDelegate(
                        DynLanContext,
                        CorrectParameters(MethodParameters));
                }
                else
                {
#if !NET20
                    var tmp = new[] { Object }.Union(MethodParameters);
#else
                    var tmp = Linq2.From(new[] { Object }).Union(MethodParameters).ToArray();
#endif
                    result = onpMethod.
                             CalculateValueDelegate(
                        DynLanContext,
                        CorrectParameters(tmp));
                }

                if (result != null)
                {
                    result.Value = InternalTypeConverter.ToInner(result.Value);
                }

                return(result == null ?
                       new ExpressionMethodResult(null) :
                       result);
            }
            else if (Method is ExpressionExtender)
            {
                ExpressionExtender onpExtender = Method as ExpressionExtender;

                return(new ExpressionMethodResult(
                           onpExtender.
                           CalculateValueDelegate(
                               DynLanContext,
                               Object,
                               MethodParameters)));
            }
            else if (Method is ExpressionExtenderInfo)
            {
                ExpressionExtenderInfo onpExtenderInfo = Method as ExpressionExtenderInfo;
                ExpressionExtender     onpExtender     = BuildinExtenders.GetByID(onpExtenderInfo.ID);

                if (onpExtender == null)
                {
                    return(new ExpressionMethodResult(null));
                }

                return(new ExpressionMethodResult(
                           onpExtender.
                           CalculateValueDelegate(
                               DynLanContext,
                               Object,
                               MethodParameters)));
            }
            else if (Method is Delegate)
            {
#if NETCE
                throw new NotSupportedException("Calling delegates is forbidden on wince2.0!");
#else
                Delegate m = Method as Delegate;

                DynamicCallResult callResult = MyReflectionHelper.CallMethod(
                    m.Target,
                    m.Method,
                    CorrectParameters(MethodParameters));

                if (callResult != null)
                {
                    return(new ExpressionMethodResult(callResult.Value));
                }
#endif
            }

            if (Method == null)
            {
                if (Object == null)
                {
                    throw new DynLanMethodNotFoundException("Cannot find a method to call");
                }
                else
                {
                    throw new DynLanMethodNotFoundException("Cannot find a method to call in object " + Object.GetType().Name + "");
                }
            }
            throw new DynLanUnsupportedMethodTypeException("Unsupported method type " + Method.GetType() + "!");
        }
Ejemplo n.º 10
0
        private static ExpressionMethodResult EvaluateInlineMethod(
            Object Object,
            Object Method,
            IList <Object> MethodParameters,
            PainContext PainContext)
        {
            if (Method is OnpMethodInfo)
            {
                OnpMethodInfo methodInfo = Method as OnpMethodInfo;

                DynamicCallResult callResult = MyReflectionHelper.CallMethod(
                    methodInfo.Obj,
                    methodInfo.Name,
                    MethodParameters);

                if (callResult != null)
                {
                    return(new ExpressionMethodResult(callResult.Value));
                }
            }
            else if (Method is ExpressionMethod)
            {
                ExpressionMethod       onpMethod = Method as ExpressionMethod;
                ExpressionMethodResult result    = null;

                if (Object is EmptyObject)
                {
                    result = onpMethod.
                             CalculateValueDelegate(
                        PainContext,
                        MethodParameters);
                }
                else
                {
                    result = onpMethod.
                             CalculateValueDelegate(
                        PainContext,
                        new[] { Object }.Union(MethodParameters).ToArray());
                }

                return(result == null ?
                       new ExpressionMethodResult(null) :
                       result);
            }
            else if (Method is ExpressionMethodInfo)
            {
                ExpressionMethodInfo   onpMethodInfo = Method as ExpressionMethodInfo;
                ExpressionMethod       onpMethod     = BuildinMethods.GetByID(onpMethodInfo.ID);
                ExpressionMethodResult result        = null;

                if (onpMethod == null)
                {
                    return(new ExpressionMethodResult(result));
                }

                if (Object is EmptyObject)
                {
                    result = onpMethod.
                             CalculateValueDelegate(
                        PainContext,
                        MethodParameters);
                }
                else
                {
                    result = onpMethod.
                             CalculateValueDelegate(
                        PainContext,
                        new[] { Object }.Union(MethodParameters).ToArray());
                }

                return(result == null ?
                       new ExpressionMethodResult(null) :
                       result);
            }
            else if (Method is ExpressionExtender)
            {
                ExpressionExtender onpExtender = Method as ExpressionExtender;

                return(new ExpressionMethodResult(
                           onpExtender.
                           CalculateValueDelegate(
                               PainContext,
                               Object,
                               MethodParameters)));
            }
            else if (Method is ExpressionExtenderInfo)
            {
                ExpressionExtenderInfo onpExtenderInfo = Method as ExpressionExtenderInfo;
                ExpressionExtender     onpExtender     = BuildinExtenders.GetByID(onpExtenderInfo.ID);

                if (onpExtender == null)
                {
                    return(new ExpressionMethodResult(null));
                }

                return(new ExpressionMethodResult(
                           onpExtender.
                           CalculateValueDelegate(
                               PainContext,
                               Object,
                               MethodParameters)));
            }

            if (Method == null)
            {
                if (Object == null)
                {
                    throw new PainMethodNotFoundException("Cannot find a method to call");
                }
                else
                {
                    throw new PainMethodNotFoundException("Cannot find a method to call in object " + Object.GetType().Name + "");
                }
            }
            throw new PainUnsupportedMethodTypeException("Unsupported method type " + Method.GetType() + "!");
        }