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); }
public List <Array> printActivityTree(Activity activity, string _parallel = "") { string[] myIntArray = new string[3]; List <Array> allSteps = new List <Array>(); if ((activity is CodeActivity) && (activity.DisplayName.IndexOf(keyForStep) > 0)) { myIntArray.SetValue(activity.DisplayName.Replace(keyForStep, ""), 0); myIntArray.SetValue(activity.Id, 1); myIntArray.SetValue(_parallel, 2); allSteps.Add(myIntArray); } if ((activity is Parallel)) { _parallel = activity.Id; } IEnumerator <Activity> list = WorkflowInspectionServices.GetActivities(activity).GetEnumerator(); while (list.MoveNext()) { var allStepsBuf = allSteps.Concat(printActivityTree(list.Current, _parallel)); allSteps = allStepsBuf.ToList(); } if ((activity is Parallel) && (activity.Id == _parallel)) { _parallel = ""; } return(allSteps); }
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); } }
internal static List <Activity> GetChildren(ActivityUtilities.ChildActivity root, ActivityUtilities.ActivityCallStack parentChain, ProcessActivityTreeOptions options) { ActivityUtilities.FinishCachingSubtree(root, parentChain, options); List <Activity> listOfChildren = new List <Activity>(); foreach (Activity activity in WorkflowInspectionServices.GetActivities(root.Activity)) { listOfChildren.Add(activity); } int toProcessIndex = 0; while (toProcessIndex < listOfChildren.Count) { foreach (Activity activity in WorkflowInspectionServices.GetActivities(listOfChildren[toProcessIndex])) { listOfChildren.Add(activity); } toProcessIndex++; } return(listOfChildren); }
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); }
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); }
public static void printActivityTreeA(Activity activity) { if (tag == null) { tag = new activityStruct(); tag.parent = null; tag.currentActivity = activity; tag.displayName = activity.DisplayName; } System.Collections.Generic.IEnumerator<Activity> list = WorkflowInspectionServices.GetActivities(activity).GetEnumerator(); while (list.MoveNext()) { activityStruct temp = new activityStruct(); temp.parent = tag; temp.currentActivity = list.Current; temp.displayName = list.Current.DisplayName; printActivityTreeA(list.Current); } }
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); }
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); } }
private void InspectActivity(Activity root) { IEnumerator <Activity> activities = WorkflowInspectionServices.GetActivities(root).GetEnumerator(); while (activities.MoveNext()) { PropertyInfo propVars = activities.Current.GetType().GetProperties().FirstOrDefault(p => p.Name == "Variables" && p.PropertyType == typeof(Collection <Variable>)); if (propVars != null) { try { Collection <Variable> variables = (Collection <Variable>)propVars.GetValue(activities.Current, null); variables.ToList().ForEach(v => { Variables.Add(v.Name); }); } catch { } } InspectActivity(activities.Current); } }
/// <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 }
public IDev2Activity Parse(DynamicActivity dynamicActivity, List <IDev2Activity> seenActivities) { try { var chart = WorkflowInspectionServices.GetActivities(dynamicActivity).FirstOrDefault() as Flowchart; if (chart != null) { if (chart.StartNode == null) { return(null); } var start = chart.StartNode as FlowStep; if (start != null) { var tool = ParseTools(start, seenActivities); return(tool.FirstOrDefault()); } var flowstart = chart.StartNode as FlowSwitch <string>; if (flowstart != null) { return(ParseSwitch(flowstart, seenActivities).FirstOrDefault()); } var flowdec = chart.StartNode as FlowDecision; return(ParseDecision(flowdec, seenActivities).FirstOrDefault()); } return(null); } catch (InvalidWorkflowException e) { Dev2Logger.Log.Error(e); throw; } }
protected override Activity GetDebuggableActivity(Activity root) { WorkflowInspectionServices.CacheMetadata(root); var enumerator = WorkflowInspectionServices.GetActivities(root).GetEnumerator(); enumerator.MoveNext(); return(enumerator.Current); }
private DynamicActivity GetRuntimeExecutionRoot(string xaml) { Activity root = ActivityXamlServices.Load(new StringReader(xaml)); WorkflowInspectionServices.CacheMetadata(root); return(root as DynamicActivity); }
Dictionary <object, SourceLocation> GetErrorInformation(Activity activity) { Dictionary <object, SourceLocation> sourceLocations = null; Activity implementationRoot = null; IEnumerable <Activity> children = WorkflowInspectionServices.GetActivities(activity); foreach (Activity child in children) { // Check if the child is the root of the activity's implementation // When an activity is an implementation child of another activity, the IDSpace for // the implementation child is different than it's parent activity and parent's public // children. The IDs for activities in the root activity's IDSpace are 1, 2 // etc and for the root implementation child it is 1.1 and for its implementation // child it is 1.1.1 and so on. // As the activity can have just one implementation root, we just check // for '.' to identify the root of the implementation. if (child.Id.Contains(".")) { implementationRoot = child; break; } } if (implementationRoot == null) { return(sourceLocations); } // We use the workflow debug symbol to get the line and column number information for a // erroneous activity. // We do not rely on the workflow debug symbol to get the file name. This is to enable cases // where the xaml was hand written outside of the workflow designer. The hand written xaml // file will not have the workflow debug symbol unless it was saved in the workflow designer. string symbolString = DebugSymbol.GetSymbol(implementationRoot) as String; if (!string.IsNullOrEmpty(symbolString)) { try { WorkflowSymbol wfSymbol = WorkflowSymbol.Decode(symbolString); if (wfSymbol != null) { sourceLocations = SourceLocationProvider.GetSourceLocations(activity, wfSymbol); } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } // Ignore invalid symbol. } } return(sourceLocations); }
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
}//end public static Activity getRuntimeActivityByDynamicActivity(DynamicActivity dynamicActivity) { IEnumerator <Activity> list = WorkflowInspectionServices.GetActivities(dynamicActivity).GetEnumerator(); list.MoveNext(); Activity runtimeActivity = list.Current; return(runtimeActivity); }
public void GetChildrenModifyChildrenExecute() { Variable <int> counter = VariableHelper.CreateInitialized <int>("counter", 0); TestIf testIf = new TestIf("If", HintThenOrElse.Then, HintThenOrElse.Else) { ConditionExpression = ((env) => ((int)counter.Get(env)) < 1), ThenActivity = new TestWriteLine("WriteLine Then") { Message = "Executing activity in Then branch", }, ElseActivity = new TestWriteLine("WriteLine Else") { Message = "Executing activity in Else branch", }, }; TestSequence outerSequence = new TestSequence("Outer sequence") { Variables = { counter }, Activities = { new TestDoWhile("DoWhile") { ConditionExpression = ((env) => counter.Get(env) < 2), Body = new TestSequence("Inner sequence") { Activities = { testIf, new TestAssign <int>("Increment Counter") { ValueExpression = (env) => counter.Get(env) + 1, ToVariable = counter, }, } }, HintIterationCount = 2, } }, }; WorkflowInspectionServices.GetActivities(testIf.ProductActivity); testIf.ThenActivity = new TestWriteLine("Then") { Message = "In Then branch", }; testIf.ElseActivity = new TestWriteLine("Else") { Message = "In Else branch", }; TestRuntime.RunAndValidateWorkflow(outerSequence); }
static void printActivityTree(Activity activity, string tag) { Console.WriteLine("{0} DisplayName:{1},type:{2}", tag, activity.DisplayName, activity.GetType()); IEnumerator <Activity> list = WorkflowInspectionServices.GetActivities(activity).GetEnumerator(); while (list.MoveNext()) { printActivityTree(list.Current, " " + tag); } }
private static ActivityInfo[] GetActivityChildren(Activity activity) { var children = new List <ActivityInfo>(); foreach (var child in WorkflowInspectionServices.GetActivities(activity).Where(a => a != null)) { children.Add(new ActivityInfo(child, activity, string.Empty)); } return(children.ToArray()); }
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); }
public static void InspectActivity(Activity root, int indent) { // Inspect the activity tree using WorkflowInspectionServices. IEnumerator <Activity> activities = WorkflowInspectionServices.GetActivities(root).GetEnumerator(); Debug.WriteLine("{0}{1}", new string(' ', indent), root.DisplayName); while (activities.MoveNext()) { InspectActivity(activities.Current, indent + 2); } }
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); }
public void Instrument(Activity rootActivity, Dictionary <object, SourceLocation> sourceLocations, string typeNamePrefix) { Queue <KeyValuePair <Activity, string> > queue = new Queue <KeyValuePair <Activity, string> >(); Activity key = rootActivity; KeyValuePair <Activity, string> item = new KeyValuePair <Activity, string>(key, string.Empty); queue.Enqueue(item); HashSet <string> set = new HashSet <string>(); HashSet <Activity> set2 = new HashSet <Activity>(); while (queue.Count > 0) { string str; SourceLocation location; item = queue.Dequeue(); key = item.Key; string str2 = item.Value; string displayName = key.DisplayName; if (string.IsNullOrEmpty(displayName)) { displayName = key.GetType().Name; } if (str2 == string.Empty) { str = displayName; } else { str = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", new object[] { str2, displayName }); } int num = 0; while (set.Contains(str)) { num++; str = string.Format(CultureInfo.InvariantCulture, "{0}.{1}{2}", new object[] { str2, displayName, num.ToString(CultureInfo.InvariantCulture) }); } set.Add(str); set2.Add(key); if (sourceLocations.TryGetValue(key, out location)) { this.Instrument(key, location, str); } foreach (Activity activity2 in WorkflowInspectionServices.GetActivities(key)) { if (!set2.Contains(activity2)) { queue.Enqueue(new KeyValuePair <Activity, string>(activity2, str)); } } } this.stateManager.Bake(typeNamePrefix); }
void FixAndCompileExpressions(Activity dynamicActivity, Guid resourceID) { // NOTE: DO NOT set properties or variables! SetNamespaces(dynamicActivity); // MS Memory Leak ;( var chart = WorkflowInspectionServices.GetActivities(dynamicActivity).FirstOrDefault() as Flowchart; if (chart != null) { FixExpressions(chart, true); } Dev2Logger.Log.Info("Fix Expressions"); CompileExpressionsImpl(dynamicActivity,resourceID); }
//从[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
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); }
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); }
protected override void Execute(NativeActivityContext context) { var activities = WorkflowInspectionServices.GetActivities(this); string name = MessageName; if (string.IsNullOrWhiteSpace(name)) { Debug.WriteLine("Bookmark name is empty"); return; } context.CreateBookmark(name, OnResumeBookmark); }
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); }