コード例 #1
0
        private static void AttachNewInstance(Type compiledResultType, DynamicActivity dynamicActivity)
        {
            /*
             * https://docs.microsoft.com/en-us/dotnet/framework/windows-workflow-foundation/csharp-expressions
             */
            // Create an instance of the new compiled expression type.
            ICompiledExpressionRoot
                compiledExpressionRoot =
                Activator
                .CreateInstance
                (
                    compiledResultType
                    , new object[]
            {
                dynamicActivity
            }
                ) as ICompiledExpressionRoot;

            // Attach it to the activity.
            CompiledExpressionInvoker
            .SetCompiledExpressionRootForImplementation
            (
                dynamicActivity
                , compiledExpressionRoot
            );
        }
コード例 #2
0
        private bool CanExecuteExpression(ICompiledExpressionRoot compiledExpressionRoot, out int expressionId)
        {
            if (compiledExpressionRoot.CanExecuteExpression(this.textExpression.ExpressionText, this.isReference, locationReferences, out expressionId))
            {
                return(true);
            }

            return(false);
        }
コード例 #3
0
ファイル: RuntimeActivity.cs プロジェクト: alex-kukhtin/A2v10
        static void CreateCompiledActivity(DynamicActivity dynamicActivity, Type resultType)
        {
            ICompiledExpressionRoot compiledExpressionRoot =
                Activator.CreateInstance(resultType,
                                         new Object[] { dynamicActivity }) as ICompiledExpressionRoot;

            // Attach it to the activity.
            CompiledExpressionInvoker.SetCompiledExpressionRootForImplementation(
                dynamicActivity, compiledExpressionRoot);
        }
コード例 #4
0
        /// <summary>
        /// Compile the Expressions in workflow
        /// </summary>
        /// <param name="id">The workflow Id</param>
        /// <param name="activity">The workflow activity for build the expressions</param>
        static void CompileExpressions(string id, Activity activity)
        {
            Type t = GetType(id, activity);
            ICompiledExpressionRoot compiledExpressionRoot =
                Activator.CreateInstance(t,
                                         new object[] { activity }) as ICompiledExpressionRoot;

            CompiledExpressionInvoker.SetCompiledExpressionRootForImplementation(
                activity, compiledExpressionRoot);
        }
コード例 #5
0
 // Attached property setter for the compiled expression root for the implementation surface
 // area of an activity
 public static void SetCompiledExpressionRootForImplementation(object target, ICompiledExpressionRoot compiledExpressionRoot)
 {
     if (compiledExpressionRoot == null)
     {
         AttachablePropertyServices.RemoveProperty(target, compiledExpressionRootForImplementationProperty);
     }
     else
     {
         AttachablePropertyServices.SetProperty(target, compiledExpressionRootForImplementationProperty, compiledExpressionRoot);
     }
 }
コード例 #6
0
        private void RefreshAccessors()
        {
            //
            // If we've gotten here is means that we have a location that has roundtripped through persistence
            // CompiledDataContext & ICER don't round trip so we need to get them back from the current tree
            // and get new pointers to the get/set methods for this expression
            ICompiledExpressionRoot compiledRoot = GetCompiledExpressionRoot();
            CompiledLocation <T>    tempLocation = (CompiledLocation <T>)compiledRoot.InvokeExpression(this.expressionId, this.locations);

            this.getMethod = tempLocation.getMethod;
            this.setMethod = tempLocation.setMethod;
        }
コード例 #7
0
ファイル: RuntimeActivity.cs プロジェクト: alex-kukhtin/A2v10
        static Type CompileExpressions(DynamicActivity dynamicActivity)
        {
            // activityName is the Namespace.Type of the activity that contains the
            // C# expressions. For Dynamic Activities this can be retrieved using the
            // name property , which must be in the form Namespace.Type.
            String activityName = dynamicActivity.Name;
            // Split activityName into Namespace and Type.Append _CompiledExpressionRoot to the type name
            // to represent the new type that represents the compiled expressions.
            // Take everything after the last . for the type name.
            String activityType = activityName.Split('.').Last() + "_CompiledExpressionRoot";
            // Take everything before the last . for the namespace.
            String activityNamespace = String.Join(".", activityName.Split('.').Reverse().Skip(1).Reverse());

            // Create a TextExpressionCompilerSettings.
            TextExpressionCompilerSettings settings = new TextExpressionCompilerSettings
            {
                Activity               = dynamicActivity,
                Language               = "C#",
                ActivityName           = activityType,
                ActivityNamespace      = activityNamespace,
                RootNamespace          = null,
                GenerateAsPartialClass = false,
                AlwaysGenerateSource   = true,
                ForImplementation      = true
            };

            // Compile the C# expression.
            TextExpressionCompilerResults results =
                new TextExpressionCompiler(settings).Compile();

            // Any compilation errors are contained in the CompilerMessages.
            if (results.HasErrors)
            {
                throw new Exception("Compilation failed.");
            }

            // Create an instance of the new compiled expression type.
            ICompiledExpressionRoot compiledExpressionRoot =
                Activator.CreateInstance(results.ResultType,
                                         new Object[] { dynamicActivity }) as ICompiledExpressionRoot;

            // Attach it to the activity.
            CompiledExpressionInvoker.SetCompiledExpressionRootForImplementation(
                dynamicActivity, compiledExpressionRoot);
            return(results.ResultType);
        }
コード例 #8
0
        private static void Compile(IDynamicActivity dynamicActivity, LocationReferenceEnvironment environment)
        {
#if NET45
            string language = null;
            if (RequiresCompilation(dynamicActivity, environment, out language))
            {
                TextExpressionCompiler        compiler = new TextExpressionCompiler(GetCompilerSettings(dynamicActivity, language));
                TextExpressionCompilerResults results  = compiler.Compile();

                if (results.HasErrors)
                {
                    StringBuilder messages = new StringBuilder();
                    messages.Append("\r\n");
                    messages.Append("\r\n");

                    foreach (TextExpressionCompilerError message in results.CompilerMessages)
                    {
                        messages.Append("\t");
                        if (results.HasSourceInfo)
                        {
                            messages.Append(string.Concat(" ", SR.ActivityXamlServiceLineString, " ", message.SourceLineNumber, ": "));
                        }
                        messages.Append(message.Message);
                    }

                    messages.Append("\r\n");
                    messages.Append("\r\n");

                    InvalidOperationException exception = new InvalidOperationException(SR.ActivityXamlServicesCompilationFailed(messages.ToString()));

                    foreach (TextExpressionCompilerError message in results.CompilerMessages)
                    {
                        exception.Data.Add(message, message.Message);
                    }
                    throw FxTrace.Exception.AsError(exception);
                }

                Type compiledExpressionRootType = results.ResultType;

                ICompiledExpressionRoot compiledExpressionRoot = Activator.CreateInstance(compiledExpressionRootType, new object[] { dynamicActivity }) as ICompiledExpressionRoot;
                CompiledExpressionInvoker.SetCompiledExpressionRootForImplementation(dynamicActivity, compiledExpressionRoot);
            }
#endif
        }
コード例 #9
0
ファイル: ActivityXamlServices.cs プロジェクト: lvama/corewf
        private static void Compile(IDynamicActivity dynamicActivity, ActivityXamlServicesSettings settings)
        {
            string language = null;

            if (!RequiresCompilation(dynamicActivity, settings.LocationReferenceEnvironment, out language))
            {
                return;
            }
            var cSharpCompiler = settings.CSharpCompiler ?? new CSharpAheadOfTimeCompiler();
            var compiler       = new TextExpressionCompiler(GetCompilerSettings(dynamicActivity, language, cSharpCompiler));
            var results        = compiler.Compile();

            if (results.HasErrors())
            {
                var messages = new StringBuilder();
                messages.Append("\r\n");
                messages.Append("\r\n");

                foreach (TextExpressionCompilerError message in results.CompilerMessages)
                {
                    messages.Append("\t");
                    messages.Append(string.Concat(" ", SR.ActivityXamlServiceLineString, " ", message.SourceLineNumber, ": "));
                    messages.Append(message.Message);
                }

                messages.Append("\r\n");
                messages.Append("\r\n");

                InvalidOperationException exception = new InvalidOperationException(SR.ActivityXamlServicesCompilationFailed(messages.ToString()));

                foreach (TextExpressionCompilerError message in results.CompilerMessages)
                {
                    exception.Data.Add(message, message.Message);
                }
                throw FxTrace.Exception.AsError(exception);
            }

            Type compiledExpressionRootType = results.ResultType;

            ICompiledExpressionRoot compiledExpressionRoot = Activator.CreateInstance(compiledExpressionRootType, new object[] { dynamicActivity }) as ICompiledExpressionRoot;

            CompiledExpressionInvoker.SetCompiledExpressionRootForImplementation(dynamicActivity, compiledExpressionRoot);
        }
コード例 #10
0
        static WorkflowService CreatetWorkflowServiceAndSetCompiledExpressionRoot(string supportedVersionXamlxfilePath, Stream activityStream, XName defaultServiceName)
        {
            WorkflowService service = CreatetWorkflowService(activityStream, defaultServiceName);

            if (service != null)
            {
                // CompiledExpression is not supported on Configuration Based Activation (CBA) scenario.
                if (ServiceHostingEnvironment.IsHosted && !ServiceHostingEnvironment.IsConfigurationBased)
                {
                    // We use ServiceHostingEnvironment.FullVirtualPath (instead of the constructor string) because we’re passing this path to BuildManager,
                    // which may not understand the file type referenced by the constructor string (e.g. .xaml).
                    ICompiledExpressionRoot expressionRoot = XamlBuildProviderExtension.GetExpressionRoot(supportedVersionXamlxfilePath, service, ServiceHostingEnvironment.FullVirtualPath);
                    if (expressionRoot != null)
                    {
                        CompiledExpressionInvoker.SetCompiledExpressionRoot(service.Body, expressionRoot);
                    }
                }
            }

            return(service);
        }
コード例 #11
0
        private bool FindCompiledExpressionRoot(Activity activity, out ICompiledExpressionRoot compiledExpressionRoot)
        {
            if (CompiledExpressionInvoker.TryGetCompiledExpressionRoot(activity, this.forImplementation, out compiledExpressionRoot))
            {
                if (compiledExpressionRoot.CanExecuteExpression(this.expressionText, true /* this is always a reference */, this.locationReferences, out this.expressionId))
                {
                    return(true);
                }
            }

            foreach (Activity containedActivity in WorkflowInspectionServices.GetActivities(activity))
            {
                if (FindCompiledExpressionRoot(containedActivity, out compiledExpressionRoot))
                {
                    return(true);
                }
            }

            compiledExpressionRoot = null;
            return(false);
        }
コード例 #12
0
        private bool FindCompiledExpressionRoot(out int exprId, out ICompiledExpressionRoot compiledExpressionRoot)
        {
            var root = this.metadata.CurrentActivity.Parent;

            while (root != null)
            {
                if (CompiledExpressionInvoker.TryGetCompiledExpressionRoot(metadata.CurrentActivity, root, out var currentCompiledExpressionRoot))
                {
                    if (CanExecuteExpression(currentCompiledExpressionRoot, out exprId))
                    {
                        compiledExpressionRoot = currentCompiledExpressionRoot;
                        return(true);
                    }
                }
                root = root.Parent;
            }

            exprId = -1;
            compiledExpressionRoot = null;

            return(false);
        }
コード例 #13
0
        private static void AttachNewInstance(Type compiledResultType, DynamicActivity dynamicActivity)
        {
            // Create an instance of the new compiled expression type.
            ICompiledExpressionRoot
                compiledExpressionRoot =
                Activator
                .CreateInstance
                (
                    compiledResultType
                    , new object[]
            {
                dynamicActivity
            }
                ) as ICompiledExpressionRoot;

            // Attach it to the activity.
            CompiledExpressionInvoker
            .SetCompiledExpressionRootForImplementation
            (
                dynamicActivity
                , compiledExpressionRoot
            );
        }
コード例 #14
0
        bool TryGetCurrentCompiledExpressionRoot(ActivityContext activityContext, out ICompiledExpressionRoot compiledExpressionRoot, out int expressionId)
        {
            ActivityInstance current = activityContext.CurrentInstance;

            while (current != null && current.Activity != this.metadataRoot)
            {
                ICompiledExpressionRoot currentCompiledExpressionRoot = null;

                if (CompiledExpressionInvoker.TryGetCompiledExpressionRoot(current.Activity, true, out currentCompiledExpressionRoot))
                {
                    if (CanExecuteExpression(currentCompiledExpressionRoot, out expressionId))
                    {
                        compiledExpressionRoot = currentCompiledExpressionRoot;
                        return(true);
                    }
                }
                current = current.Parent;
            }

            compiledExpressionRoot = null;
            expressionId           = -1;

            return(false);
        }
コード例 #15
0
 //
 // Attached property setter for the compiled expression root for the public surface area of an activity
 public static void SetCompiledExpressionRoot(object target, ICompiledExpressionRoot compiledExpressionRoot)
 {
     if (compiledExpressionRoot == null)
     {
         AttachablePropertyServices.RemoveProperty(target, compiledExpressionRootProperty);
     }
     else
     {
         AttachablePropertyServices.SetProperty(target, compiledExpressionRootProperty, compiledExpressionRoot);
     }
 }
コード例 #16
0
        private bool TryGetCompiledExpressionRootAtDesignTime(Activity expression, Activity target, out ICompiledExpressionRoot compiledExpressionRoot, out int exprId)
        {
            exprId = -1;
            compiledExpressionRoot = null;
            if (!CompiledExpressionInvoker.TryGetCompiledExpressionRoot(expression, target, out compiledExpressionRoot) ||
                !CanExecuteExpression(compiledExpressionRoot, out exprId))
            {
                return(FindCompiledExpressionRoot(out exprId, out compiledExpressionRoot));
            }

            return(true);
        }
コード例 #17
0
        // Helper to find the correct ICER for a given expression. This is separate from the above
        // because within this class we switch forImplementation for the same target Activity to
        // matched the ICER model of using one ICER for all expressions in the implementation and
        // root argument defaults.
        internal static bool TryGetCompiledExpressionRoot(Activity target, bool forImplementation, out ICompiledExpressionRoot compiledExpressionRoot)
        {
            if (!forImplementation)
            {
                compiledExpressionRoot = GetCompiledExpressionRoot(target) as ICompiledExpressionRoot;
                if (compiledExpressionRoot != null)
                {
                    return(true);
                }
                // Default expressions for Arguments show up in the public surface area If we didn't
                // find an ICER for the public surface area continue and try to use the
                // implementation ICER
            }

            if (target is ICompiledExpressionRoot)
            {
                compiledExpressionRoot = (ICompiledExpressionRoot)target;
                return(true);
            }

            compiledExpressionRoot = GetCompiledExpressionRootForImplementation(target) as ICompiledExpressionRoot;
            if (compiledExpressionRoot != null)
            {
                return(true);
            }

            compiledExpressionRoot = null;
            return(false);
        }
コード例 #18
0
        // Internal helper to find the correct ICER for a given expression.
        internal static bool TryGetCompiledExpressionRoot(Activity expression, Activity target, out ICompiledExpressionRoot compiledExpressionRoot)
        {
            var forImplementation = expression.MemberOf != expression.RootActivity.MemberOf;

            return(TryGetCompiledExpressionRoot(target, forImplementation, out compiledExpressionRoot));
        }
コード例 #19
0
        //
        // Internal helper to find the correct ICER for a given expression.
        internal static bool TryGetCompiledExpressionRoot(Activity expression, Activity target, out ICompiledExpressionRoot compiledExpressionRoot)
        {
            bool forImplementation = expression.MemberOf != expression.RootActivity.MemberOf;

            return TryGetCompiledExpressionRoot(target, forImplementation, out compiledExpressionRoot);
        }
コード例 #20
0
        //
        // Helper to find the correct ICER for a given expression.
        // This is separate from the above because within this class we switch forImplementation for the same target Activity
        // to matched the ICER model of using one ICER for all expressions in the implementation and root argument defaults.
        internal static bool TryGetCompiledExpressionRoot(Activity target, bool forImplementation, out ICompiledExpressionRoot compiledExpressionRoot)
        {
            if (!forImplementation)
            {
                compiledExpressionRoot = GetCompiledExpressionRoot(target) as ICompiledExpressionRoot;
                if (compiledExpressionRoot != null)
                {
                    return true;
                }
                //
                // Default expressions for Arguments show up in the public surface area
                // If we didn't find an ICER for the public surface area continue
                // and try to use the implementation ICER
            }

            if (target is ICompiledExpressionRoot)
            {
                compiledExpressionRoot = (ICompiledExpressionRoot)target;
                return true;
            }

            compiledExpressionRoot = GetCompiledExpressionRootForImplementation(target) as ICompiledExpressionRoot;
            if (compiledExpressionRoot != null)
            {
                return true;
            }

            compiledExpressionRoot = null;
            return false;
        }
コード例 #21
0
        bool TryGetCurrentCompiledExpressionRoot(ActivityContext activityContext, out ICompiledExpressionRoot compiledExpressionRoot, out int expressionId)
        {
            ActivityInstance current = activityContext.CurrentInstance;

            while (current != null && current.Activity != this.metadataRoot)
            {
                ICompiledExpressionRoot currentCompiledExpressionRoot = null;

                if (CompiledExpressionInvoker.TryGetCompiledExpressionRoot(current.Activity, true, out currentCompiledExpressionRoot))
                {
                    if (CanExecuteExpression(currentCompiledExpressionRoot, out expressionId))
                    {
                        compiledExpressionRoot = currentCompiledExpressionRoot;
                        return true;
                    }
                }
                current = current.Parent;
            }

            compiledExpressionRoot = null;
            expressionId = -1;

            return false;
        }
コード例 #22
0
        bool FindCompiledExpressionRoot(out int exprId, out ICompiledExpressionRoot compiledExpressionRoot)
        {
            Activity root = this.metadata.CurrentActivity.Parent;

            while (root != null)
            {
                ICompiledExpressionRoot currentCompiledExpressionRoot = null;
                if (CompiledExpressionInvoker.TryGetCompiledExpressionRoot(metadata.CurrentActivity, root, out currentCompiledExpressionRoot))
                {
                    if (CanExecuteExpression(currentCompiledExpressionRoot, out exprId))
                    {
                        compiledExpressionRoot = currentCompiledExpressionRoot;
                        return true;
                    }
                }
                root = root.Parent;
            }

            exprId = -1;
            compiledExpressionRoot = null;

            return false;
        }
コード例 #23
0
        bool TryGetCompiledExpressionRootAtDesignTime(Activity expression, Activity target, out ICompiledExpressionRoot compiledExpressionRoot, out int exprId)
        {
            exprId = -1;
            compiledExpressionRoot = null;
            if (!CompiledExpressionInvoker.TryGetCompiledExpressionRoot(expression, target, out compiledExpressionRoot) ||
                !CanExecuteExpression(compiledExpressionRoot, out exprId))
            {
                return FindCompiledExpressionRoot(out exprId, out compiledExpressionRoot);
            }

            return true;
        }
コード例 #24
0
        bool CanExecuteExpression(ICompiledExpressionRoot compiledExpressionRoot, out int expressionId)
        {
            if (compiledExpressionRoot.CanExecuteExpression(this.textExpression.ExpressionText, this.isReference, locationReferences, out expressionId))
            {
                return true;
            }

            return false;
        }