コード例 #1
0
        Dictionary <object, SourceLocation> UpdateSourceLocationMappingInDebuggerService()
        {
            var debugView    = m_workflowDesigner.DebugManagerView;//不能保存m_workflowDesigner.DebugManagerView在以后使用,会是旧数据
            var modelService = m_workflowDesigner.Context.Services.GetService <ModelService>();

            var nonPublicInstance       = BindingFlags.Instance | BindingFlags.NonPublic;
            var debuggerServiceType     = typeof(DebuggerService);
            var ensureMappingMethodName = "EnsureSourceLocationUpdated";
            var mappingFieldName        = "instanceToSourceLocationMapping";
            var ensureMappingMethod     = debuggerServiceType.GetMethod(ensureMappingMethodName, nonPublicInstance);
            var mappingField            = debuggerServiceType.GetField(mappingFieldName, nonPublicInstance);

            if (ensureMappingMethod == null)
            {
                throw new MissingMethodException(debuggerServiceType.FullName, ensureMappingMethodName);
            }
            if (mappingField == null)
            {
                throw new MissingFieldException(debuggerServiceType.FullName, mappingFieldName);
            }

            var rootActivity = modelService.Root.GetCurrentValue() as Activity;

            if (rootActivity != null)
            {
                WorkflowInspectionServices.CacheMetadata(rootActivity);
            }

            ensureMappingMethod.Invoke(debugView, new object[0]);
            var mapping = (Dictionary <object, SourceLocation>)mappingField.GetValue(debugView);

            return(mapping);
        }
コード例 #2
0
        private static bool TryEvaluateExpression <T>(Activity <T> expression, LocationReferenceEnvironment locationReferenceEnvironment, ActivityContext context, out object result)
        {
            T local;

            if (!expression.TryGetValue(context, out local))
            {
                result = System.Activities.SR.DebugInfoTryGetValueFailed;
                return(false);
            }
            Activity rootActivity = local as Activity;

            context.Activity = rootActivity;
            if ((rootActivity != null) && !rootActivity.IsRuntimeReady)
            {
                WorkflowInspectionServices.CacheMetadata(rootActivity, locationReferenceEnvironment);
            }
            IExpressionContainer container = local as IExpressionContainer;

            if (container == null)
            {
                result = System.Activities.SR.DebugInfoNotAnIExpressionContainer;
                return(false);
            }
            Expression <Func <ActivityContext, object> > expression2 = container.Expression as Expression <Func <ActivityContext, object> >;

            if (expression2 == null)
            {
                result = System.Activities.SR.DebugInfoNoLambda;
                return(false);
            }
            result = expression2.Compile()(context);
            return(true);
        }
        /// <summary>
        /// The initialize template tables.
        /// </summary>
        /// <exception cref="ValidationException">
        /// The workflow is invalid
        /// </exception>
        private void InitializeTemplateTables()
        {
            try
            {
                // Cache definitions so we don't run CacheMetadata more than once.
                if (!UriTemplateTables.ContainsKey(this.Activity))
                {
                    WorkflowInspectionServices.CacheMetadata(this.Activity);
                    UriTemplateTables.Add(this.Activity, new List <UriTemplateTable>());
                    foreach (var uriTemplateTable in
                             this.BaseAddresses.Select(baseAddress => new UriTemplateTable(baseAddress)))
                    {
                        UriTemplateTables[this.Activity].Add(uriTemplateTable);
                        this.LocateHttpReceiveActivities(this.Activity, uriTemplateTable);

                        // No UriTemplates in this activity
                        if (uriTemplateTable.KeyValuePairs.Count == 0)
                        {
                            throw new ValidationException(
                                      "Activity must contain at least one HttpReceive activity with a valid Uri template");
                        }
                    }
                }
            }

#if DEBUG
            catch (Exception ex)
            {
                HttpExceptionHelper.WriteThread(ex.Message);
                throw;
            }
#endif
        }
コード例 #4
0
        protected override void LoadAndExecute()
        {
            MemoryStream    ms            = new MemoryStream(ASCIIEncoding.Default.GetBytes(this.workflowDesigner.Text));
            DynamicActivity workflowToRun = ActivityXamlServices.Load(ms) as DynamicActivity;

            WorkflowInspectionServices.CacheMetadata(workflowToRun);

            this.workflowApplication = new WorkflowApplication(workflowToRun);

            this.workflowApplication.Extensions.Add(this.output);

            this.workflowApplication.Completed            = this.WorkflowCompleted;
            this.workflowApplication.OnUnhandledException = this.WorkflowUnhandledException;
            this.workflowApplication.Aborted = this.WorkflowAborted;

            this.workflowApplication.Extensions.Add(this.InitialiseVisualTrackingParticipant(workflowToRun));

            try
            {
                this.running = true;
                this.workflowApplication.Run();
            }
            catch (Exception e)
            {
                this.output.WriteLine(ExceptionHelper.FormatStackTrace(e));
                StatusViewModel.SetStatusText(Resources.ExceptionInDebugStatus, this.workflowName);
            }
        }
コード例 #5
0
        public void GetChildrenModifyChildrenExecute()
        {
            TestSequence sequence = new TestSequence("Test Sequence")
            {
                Activities =
                {
                    new TestWriteLine("WriteLine A")
                    {
                        Message = "message a",
                    },
                },
            };

            WorkflowInspectionServices.GetActivities(sequence.ProductActivity);

            sequence.Activities.Add(
                new TestWriteLine("WriteLine B")
            {
                Message = "message b",
            }
                );

            // Now that we've changed the tree we explicitly recache
            WorkflowInspectionServices.CacheMetadata(sequence.ProductActivity);
            TestRuntime.RunAndValidateWorkflow(sequence);
        }
コード例 #6
0
        private static Dictionary <object, SourceLocation> UpdateSourceLocationMappingInDebuggerService(WorkflowDesigner workflowDesigner)
        {
            var debugView    = workflowDesigner.DebugManagerView;//不能保存m_workflowDesigner.DebugManagerView在以后使用,会是旧数据
            var modelService = workflowDesigner.Context.Services.GetService <ModelService>();

            var nonPublicInstance       = BindingFlags.Instance | BindingFlags.NonPublic;
            var debuggerServiceType     = typeof(DebuggerService);
            var ensureMappingMethodName = "EnsureSourceLocationUpdated";
            var mappingFieldName        = "instanceToSourceLocationMapping";
            var ensureMappingMethod     = debuggerServiceType.GetMethod(ensureMappingMethodName, nonPublicInstance);
            var mappingField            = debuggerServiceType.GetField(mappingFieldName, nonPublicInstance);

            if (ensureMappingMethod == null)
            {
                return(new Dictionary <object, SourceLocation>());
            }
            if (mappingField == null)
            {
                return(new Dictionary <object, SourceLocation>());
            }

            var rootActivity = (modelService.Root.GetCurrentValue() as ActivityBuilder).Implementation as Activity;

            if (rootActivity != null)
            {
                WorkflowInspectionServices.CacheMetadata(rootActivity);
            }

            ensureMappingMethod.Invoke(debugView, new object[0]);
            var mapping = (Dictionary <object, SourceLocation>)mappingField.GetValue(debugView);

            //TODO WJF 在空白项目中拖动一个组件时,断点设置失败,mapping为空
            return(mapping);
        }
コード例 #7
0
        protected override void StartInternal()
        {
            DynamicActivity activity;

            using (var stream = new MemoryStream(Encoding.Default.GetBytes(WorkflowDesigner.Text)))
            {
                activity = ActivityXamlServices.Load(stream) as DynamicActivity;
            }

            if (activity == null)
            {
                return;
            }

            WorkflowInspectionServices.CacheMetadata(activity);

            workflowApplication = new WorkflowApplication(activity);

            workflowApplication.Extensions.Add(OutputWriter);
            workflowApplication.Extensions.Add(InitialiseVisualTrackingParticipant(activity));

            workflowApplication.Completed            += Completed;
            workflowApplication.OnUnhandledException += OnUnhandledException;
            workflowApplication.Aborted += Aborted;

            try
            {
                workflowApplication.Run();
                OnRunningStateChanged(new WorkflowExecutingStateEventArgs(true));
            }
            catch (Exception e)
            {
                OutputWriter.WriteLine(e.StackTrace);
            }
        }
コード例 #8
0
        protected override Activity GetDebuggableActivity(Activity root)
        {
            WorkflowInspectionServices.CacheMetadata(root);

            var enumerator = WorkflowInspectionServices.GetActivities(root).GetEnumerator();

            enumerator.MoveNext();
            return(enumerator.Current);
        }
コード例 #9
0
        private DynamicActivity GetRuntimeExecutionRoot(string xaml)
        {
            Activity root = ActivityXamlServices.Load(new StringReader(xaml));


            WorkflowInspectionServices.CacheMetadata(root);

            return(root as DynamicActivity);
        }
コード例 #10
0
        public static Activity getActivityByString(string xaml)
        {
            System.IO.StringReader stringReader = new System.IO.StringReader(xaml);

            Activity activity = System.Activities.XamlIntegration.ActivityXamlServices.Load(stringReader);

            WorkflowInspectionServices.CacheMetadata(activity);

            return(activity);
        }//end
コード例 #11
0
        protected override Activity GetRootRuntimeWorkflowElement(Activity root)
        {
            WorkflowInspectionServices.CacheMetadata(root);

            IEnumerator <Activity> enumerator1 = WorkflowInspectionServices.GetActivities(root).GetEnumerator();

            // Get the first child
            enumerator1.MoveNext();
            root = enumerator1.Current;
            return(root);
        }
コード例 #12
0
        public void GetChildrenModifyChildrenExecute()
        {
            Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0);
            TestDoWhile    doWhile = new TestDoWhile("dowhile act")
            {
                ConditionExpression = ((env) => ((int)counter.Get(env)) < 10),
                Body = new TestSequence("test sequence act")
                {
                    Activities =
                    {
                        new TestWriteLine("wrong activity", "Its a big world after all"),
                        new TestAssign <int>("Increment Counter")
                        {
                            ToVariable      = counter,
                            ValueExpression = ((env) => (((int)counter.Get(env))) + 1),
                        },
                    },
                },
                HintIterationCount = 5,
            };
            TestSequence outerSequence = new TestSequence("sequence1")
            {
                Variables =
                {
                    counter
                },
                Activities =
                {
                    doWhile,
                }
            };

            WorkflowInspectionServices.GetActivities(doWhile.ProductActivity);

            doWhile.ConditionExpression = (env) => ((int)counter.Get(env)) < 5;
            doWhile.Body = new TestSequence("test sequence act")
            {
                Activities =
                {
                    new TestWriteLine("write hello", "Its a small world after all"),
                    new TestAssign <int>("Increment Counter")
                    {
                        ToVariable      = counter,
                        ValueExpression = ((env) => (((int)counter.Get(env))) + 1),
                    },
                },
            };

            // We need to recache the metadata now that we've changed the tree
            WorkflowInspectionServices.CacheMetadata(outerSequence.ProductActivity);

            TestRuntime.RunAndValidateWorkflow(outerSequence);
        }
コード例 #13
0
 Activity GetRuntimeExecutionRoot(Activity root)
 {
     try
     {
         // Activity root = ActivityXamlServices.Load(_currentWorkflowFile);
         WorkflowInspectionServices.CacheMetadata(root);
     }
     catch (Exception ex)
     {
         Log.Logger.LogData(ex.Message, LogLevel.Error);
     }
     return(root);
 }
コード例 #14
0
        //从[xaml]字串得到[Activity]对象
        public static Activity activityByXaml(string xaml, bool isCheck = true)
        {
            System.IO.StringReader stringReader = new System.IO.StringReader(xaml);

            Activity activity = System.Activities.XamlIntegration.ActivityXamlServices.Load(stringReader);

            if (isCheck)
            {
                WorkflowInspectionServices.CacheMetadata(activity);
            }

            return(activity);
        }//end
コード例 #15
0
        Activity GetRootRuntimeWorkflowElement()
        {
            Activity root = XamlHelper.GetActivity(_designer.Text);

            WorkflowInspectionServices.CacheMetadata(root);

            IEnumerator <Activity> enumerator1 = WorkflowInspectionServices.GetActivities(root).GetEnumerator();

            //Get the first child of the x:class
            enumerator1.MoveNext();
            root = enumerator1.Current;
            return(root);
        }
コード例 #16
0
        public static Activity GetRootRuntimeWorkflowElement(Activity workflowInstance)
        {
            Activity root = workflowInstance;

            WorkflowInspectionServices.CacheMetadata(root);

            IEnumerator <Activity> enumerator1 = WorkflowInspectionServices.GetActivities(root).GetEnumerator();

            //Get the first child of the x:class
            enumerator1.MoveNext();
            root = enumerator1.Current;
            return(root);
        }
コード例 #17
0
        private Activity GetRuntimeActivity()
        {
            _workflowDesigner.Flush();
            var stringReader = new StringReader(_workflowDesigner.Text);
            var root         = ActivityXamlServices.Load(stringReader);

            WorkflowInspectionServices.CacheMetadata(root);
            var list = WorkflowInspectionServices.GetActivities(root).GetEnumerator();

            list.MoveNext();
            var runtimeActivity = list.Current;

            return(runtimeActivity);
        }
コード例 #18
0
        Activity GetRootRuntimeWorkflowElement(Activity root)
        {
            try
            {
                //Activity root = ActivityXamlServices.Load(_currentWorkflowFile);
                WorkflowInspectionServices.CacheMetadata(root);

                IEnumerator <Activity> enumerator1 = WorkflowInspectionServices.GetActivities(root).GetEnumerator();
                //Get the first child of the x:class
                enumerator1.MoveNext();
                root = enumerator1.Current;
            }
            catch (Exception ex)
            {
                Log.Logger.LogData(ex.Message, LogLevel.Error);
            }
            return(root);
        }
コード例 #19
0
ファイル: WhileActivity.cs プロジェクト: sunxiaotianmg/CoreWF
        public void GetChildrenModifyChildrenExecute()
        {
            Variable <int> counter  = VariableHelper.CreateInitialized <int>("counter", 0);
            TestWhile      whileAct = new TestWhile("while act")
            {
                ConditionExpression = ((env) => false),
                Body = new TestSequence("Seq"),
            };
            TestSequence outerSequence = new TestSequence("sequence1")
            {
                Variables  = { counter },
                Activities =
                {
                    whileAct,
                },
            };

            WorkflowInspectionServices.GetActivities(whileAct.ProductActivity);

            whileAct.ConditionExpression = (env) => ((int)counter.Get(env)) < 1;
            whileAct.Body = new TestSequence("Inner Seq")
            {
                Activities =
                {
                    new TestWriteLine("write hello")
                    {
                        Message = "Its a small world after all",
                    },
                    new TestAssign <int>("Increment Counter")
                    {
                        ValueExpression = ((env) => (((int)counter.Get(env))) + 1),
                        ToVariable      = counter,
                    },
                },
            };
            whileAct.HintIterationCount = 1;

            // Now that we've changed the tree we need to recache
            WorkflowInspectionServices.CacheMetadata(outerSequence.ProductActivity);

            TestRuntime.RunAndValidateWorkflow(outerSequence);
        }
コード例 #20
0
        public void GetChildrenModifyChildrenExecute()
        {
            TestFlowchart flowchart  = new TestFlowchart("Flow1");
            TestWriteLine writeLine1 = new TestWriteLine("hello1", "Hello1");
            TestWriteLine writeLine2 = new TestWriteLine("hello2", "Hello2");
            TestWriteLine writeLine3 = new TestWriteLine("hello3", "Hello3");
            TestWriteLine writeLine4 = new TestWriteLine("hello4", "Hello4");

            flowchart.AddLink(writeLine1, writeLine2);
            flowchart.AddLink(writeLine2, writeLine3);

            WorkflowInspectionServices.GetActivities(flowchart.ProductActivity);

            flowchart.AddLink(writeLine3, writeLine4);

            // Now that we've change the tree we need to explicitly recache
            WorkflowInspectionServices.CacheMetadata(flowchart.ProductActivity);

            TestRuntime.RunAndValidateWorkflow(flowchart);
        }
コード例 #21
0
ファイル: DebugInfo.cs プロジェクト: dox0/DotNet471RS3
        static bool TryEvaluateExpression(
            ActivityWithResult element,
            LocationReferenceEnvironment locationReferenceEnvironment,
            CodeActivityContext context,
            out object result)
        {
            // value is some expression type and needs to be opened
            context.Reinitialize(context.CurrentInstance, context.CurrentExecutor, element, context.CurrentInstance.InternalId);
            if (element != null && !element.IsRuntimeReady)
            {
                WorkflowInspectionServices.CacheMetadata(element, locationReferenceEnvironment);
            }

            if (element == null || !element.IsFastPath)
            {
                result = SR.DebugInfoNotSkipArgumentResolution;
                return(false);
            }

            result = element.InternalExecuteInResolutionContextUntyped(context);
            return(true);
        }
コード例 #22
0
 private void WalkActivityTree()
 {
     if (this.knownServiceActivities == null)
     {
         if (this.Body == null)
         {
             throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new ValidationException(System.ServiceModel.Activities.SR.MissingBodyInWorkflowService));
         }
         WorkflowInspectionServices.CacheMetadata(this.Body);
         this.knownServiceActivities = new List <Receive>();
         this.receiveAndReplyPairs   = new HashSet <ReceiveAndReplyTuple>();
         Queue <QueueItem> queue = new Queue <QueueItem>();
         queue.Enqueue(new QueueItem(this.Body, null, null));
         while (queue.Count > 0)
         {
             QueueItem item     = queue.Dequeue();
             Activity  activity = item.Activity;
             TransactedReceiveScope parentTransactedReceiveScope = item.ParentTransactedReceiveScope;
             TransactedReceiveScope rootTransactedReceiveScope   = item.RootTransactedReceiveScope;
             if (activity is Receive)
             {
                 Receive receive = (Receive)activity;
                 if (rootTransactedReceiveScope != null)
                 {
                     receive.InternalReceive.AdditionalData.IsInsideTransactedReceiveScope = true;
                     if ((receive == parentTransactedReceiveScope.Request) && (parentTransactedReceiveScope == rootTransactedReceiveScope))
                     {
                         receive.InternalReceive.AdditionalData.IsFirstReceiveOfTransactedReceiveScopeTree = true;
                     }
                 }
                 this.knownServiceActivities.Add(receive);
             }
             else if (activity is SendReply)
             {
                 SendReply reply   = (SendReply)activity;
                 Receive   request = reply.Request;
                 if (reply.InternalContent.IsFault)
                 {
                     request.FollowingFaults.Add(reply);
                 }
                 else
                 {
                     if (request.HasReply)
                     {
                         SendReply reply2 = request.FollowingReplies[0];
                         ContractValidationHelper.ValidateSendReplyWithSendReply(reply2, reply);
                     }
                     request.FollowingReplies.Add(reply);
                 }
                 ReceiveAndReplyTuple tuple = new ReceiveAndReplyTuple(request, reply);
                 this.receiveAndReplyPairs.Add(tuple);
             }
             if (activity is TransactedReceiveScope)
             {
                 parentTransactedReceiveScope = activity as TransactedReceiveScope;
                 if (rootTransactedReceiveScope == null)
                 {
                     rootTransactedReceiveScope = parentTransactedReceiveScope;
                 }
             }
             foreach (Activity activity2 in WorkflowInspectionServices.GetActivities(activity))
             {
                 QueueItem item2 = new QueueItem(activity2, parentTransactedReceiveScope, rootTransactedReceiveScope);
                 queue.Enqueue(item2);
             }
         }
     }
 }
コード例 #23
0
 protected override Activity GetRootRuntimeWorkflowElement(Activity root)
 {
     WorkflowInspectionServices.CacheMetadata(root);
     return(root);
 }
コード例 #24
0
 protected override Activity GetDebuggableActivity(Activity root)
 {
     WorkflowInspectionServices.CacheMetadata(root);
     return(root);
 }