Exemplo n.º 1
0
        public static void ApplyFieldDeclaration(FieldDeclaration declaration, object target)
        {
            var setterMethod = ReflectUtil.GetSetter(declaration.Name, target.GetType(), declaration.Value.GetType());

            if (setterMethod != null)
            {
                try
                {
                    setterMethod.Invoke(target, new[] { declaration.Value });
                }
                catch (System.Exception e)
                {
                    throw Log.ExceptionWhileApplyingFieldDeclatation(declaration.Name, target.GetType().FullName, e);
                }
            }
            else
            {
                var field = ReflectUtil.GetField(declaration.Name, target);
                EnsureUtil.EnsureNotNull("Field definition uses unexisting field '" + declaration.Name + "' on class " + target.GetType().FullName, "field", field);
                // Check if the delegate field's type is correct
                if (!FieldTypeCompatible(declaration, field))
                {
                    //throw Log.IncompatibleTypeForFieldDeclaration(declaration, target, field);
                }
                ReflectUtil.SetField(field, target, declaration.Value);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 ///     Creates a new <seealso cref="ExecutableScript" /> from a dynamic resource. Dynamic means that the source
 ///     is an expression which will be evaluated during execution.
 /// </summary>
 /// <param name="language"> the language of the script </param>
 /// <param name="resourceExpression"> the expression which evaluates to the resource path </param>
 /// <param name="scriptFactory"> the script factory used to create the script </param>
 /// <returns> the newly created script </returns>
 /// <exception cref="NotValidException"> if language is null or empty or resourceExpression is null </exception>
 public static ExecutableScript GetScriptFromResourceExpression(string language, IExpression resourceExpression,
                                                                ScriptFactory scriptFactory)
 {
     EnsureUtil.EnsureNotEmpty(typeof(NotValidException), "Script language", language);
     EnsureUtil.EnsureNotNull(typeof(NotValidException), "Script resource expression", resourceExpression);
     return(scriptFactory.CreateScriptFromResource(language, resourceExpression));
 }
Exemplo n.º 3
0
 /// <summary>
 ///     Creates a new <seealso cref="ExecutableScript" /> from a source. It excepts static and dynamic sources.
 ///     Dynamic means that the source is an expression which will be evaluated during execution.
 /// </summary>
 /// <param name="language"> the language of the script </param>
 /// <param name="source"> the source code of the script or an expression which evaluates to the source code </param>
 /// <param name="expressionManager"> the expression manager to use to generate the expressions of dynamic scripts </param>
 /// <param name="scriptFactory"> the script factory used to create the script </param>
 /// <returns> the newly created script </returns>
 /// <exception cref="NotValidException"> if language is null or empty or source is null </exception>
 public static ExecutableScript GetScriptFormSource(string language, string source,
                                                    ExpressionManager expressionManager, ScriptFactory scriptFactory)
 {
     EnsureUtil.EnsureNotEmpty(typeof(NotValidException), "Script language", language);
     EnsureUtil.EnsureNotNull(typeof(NotValidException), "Script source", source);
     if (IsDynamicScriptExpression(language, source))
     {
         IExpression sourceExpression = expressionManager.CreateExpression(source);
         return(GetScriptFromSourceExpression(language, sourceExpression, scriptFactory));
     }
     return(GetScriptFromSource(language, source, scriptFactory));
 }
Exemplo n.º 4
0
 /// <summary>
 ///     Creates a new <seealso cref="ExecutableScript" /> from a source or resource. It excepts static and
 ///     dynamic sources and resources. Dynamic means that the source or resource is an expression
 ///     which will be evaluated during execution.
 /// </summary>
 /// <param name="language"> the language of the script </param>
 /// <param name="source"> the source code of the script or an expression which evaluates to the source code </param>
 /// <param name="resource"> the resource path of the script code or an expression which evaluates to the resource path </param>
 /// <param name="expressionManager"> the expression manager to use to generate the expressions of dynamic scripts </param>
 /// <param name="scriptFactory"> the script factory used to create the script </param>
 /// <returns> the newly created script </returns>
 /// <exception cref="NotValidException"> if language is null or empty or both of source and resource are invalid </exception>
 public static ExecutableScript GetScript(string language, string source, string resource,
                                          ExpressionManager expressionManager, ScriptFactory scriptFactory)
 {
     EnsureUtil.EnsureNotEmpty(typeof(NotValidException), "Script language", language);
     EnsureUtil.EnsureAtLeastOneNotNull(typeof(NotValidException), "No script source or resource was given", source,
                                        resource);
     if (!ReferenceEquals(resource, null) && resource.Length > 0)
     {
         return(GetScriptFromResource(language, resource, expressionManager, scriptFactory));
     }
     return(GetScriptFormSource(language, source, expressionManager, scriptFactory));
 }
Exemplo n.º 5
0
        //public static ICmmnActivityBehavior GetActivityBehavior(CmmnExecution execution)
        //{
        //    string id = execution.Id;

        //    CmmnActivity activity = execution.Activity;
        //    EnsureUtil.EnsureNotNull(typeof(PvmException), "Case execution '" + id + "' has no current activity.", "activity", activity);

        //    ICmmnActivityBehavior behavior = (ICmmnActivityBehavior)activity.ActivityBehavior;
        //    EnsureUtil.EnsureNotNull(typeof(PvmException), "There is no behavior specified in " + activity + " for case execution '" + id + "'.", "behavior", behavior);

        //    return behavior;
        //}

        public static IActivityBehavior GetActivityBehavior(PvmExecutionImpl execution)
        {
            var id = execution.Id;

            IPvmActivity activity = execution.Activity;

            EnsureUtil.EnsureNotNull(typeof(PvmException), "Execution '" + id + "' has no current activity.",
                                     "activity", activity);

            var behavior = activity.ActivityBehavior;

            EnsureUtil.EnsureNotNull(typeof(PvmException),
                                     "There is no behavior specified in " + activity + " for execution '" + id + "'.", "behavior", behavior);

            return(behavior);
        }
Exemplo n.º 6
0
 /// <summary>
 ///     Creates a new <seealso cref="ExecutableScript" /> from a static source.
 /// </summary>
 /// <param name="language"> the language of the script </param>
 /// <param name="source"> the source code of the script </param>
 /// <param name="scriptFactory"> the script factory used to create the script </param>
 /// <returns> the newly created script </returns>
 /// <exception cref="NotValidException"> if language is null or empty or source is null </exception>
 public static ExecutableScript GetScriptFromSource(string language, string source, ScriptFactory scriptFactory)
 {
     EnsureUtil.EnsureNotEmpty(typeof(NotValidException), "Script language", language);
     EnsureUtil.EnsureNotNull(typeof(NotValidException), "Script source", source);
     return(scriptFactory.CreateScriptFromSource(language, source));
 }