private void ShowDebug(SourceLocation srcLoc)
 {
     DispatcherService.Dispatch(() =>
     {
         this.workflowDesigner.DebugManagerView.CurrentLocation = srcLoc;
     });
 }
예제 #2
0
        public async Task Dispatch_Command_ReplyReturned()
        {
            var serverCallContext = TestServerCallContextFactory.Create();

            serverCallContext.UserState["__HttpContext"] = httpContextFactory();
            var dispatcher = new DispatcherService();

            var cmd = new TestCommand
            {
                Value = Guid.NewGuid().ToString()
            };

            var request = new RequestEnvelope()
            {
                Type = cmd.GetType().AssemblyQualifiedName,
                Data = UnsafeByteOperations.UnsafeWrap(JsonSerializer.SerializeToUtf8Bytes(cmd))
            };

            var response = await dispatcher.Dispatch(request, serverCallContext);

            response.ShouldNotBeNull().Data.ShouldNotBeNull().ShouldNotBeEmpty();
            var responseType = System.Type.GetType(response.Type, an => Assembly.Load(an.Name ?? null !), null, true, true).ShouldNotBeNull();

            using var ms = new MemoryStream(response.Data.ToByteArray());
            JsonSerializer.Deserialize(ms, responseType).ShouldBeOfType <string>().ShouldBe(cmd.Value);
        }
예제 #3
0
        public WorkflowViewModel(bool disableDebugViewOutput)
        {
            this.workflowDesigner = new WorkflowDesigner();
            this.id = ++designerCount;
            this.validationErrors       = new List <ValidationErrorInfo>();
            this.validationErrorService = new ValidationErrorService(this.validationErrors);
            this.workflowDesigner.Context.Services.Publish <IValidationErrorService>(this.validationErrorService);

            this.workflowDesigner.ModelChanged += delegate(object sender, EventArgs args)
            {
                this.modelChanged = true;
                this.OnPropertyChanged("DisplayNameWithModifiedIndicator");
            };

            this.validationErrorsView = new ValidationErrorsUserControl();

            this.outputTextBox          = new TextBox();
            this.output                 = new TextBoxStreamWriter(this.outputTextBox, this.DisplayName);
            this.disableDebugViewOutput = disableDebugViewOutput;

            this.workflowDesigner.Context.Services.GetService <DesignerConfigurationService>().TargetFrameworkName = new System.Runtime.Versioning.FrameworkName(".NETFramework", new Version(4, 5));
            this.workflowDesigner.Context.Services.GetService <DesignerConfigurationService>().LoadingFromUntrustedSourceEnabled = bool.Parse(ConfigurationManager.AppSettings["LoadingFromUntrustedSourceEnabled"]);

            this.validationErrorService.ErrorsChangedEvent += delegate(object sender, EventArgs args)
            {
                DispatcherService.Dispatch(() =>
                {
                    this.validationErrorsView.ErrorsDataGrid.ItemsSource = this.validationErrors;
                    this.validationErrorsView.ErrorsDataGrid.Items.Refresh();
                });
            };
        }
예제 #4
0
        public async Task Dispatch_Command_ReplyReturned()
        {
            var serverCallContext = TestServerCallContextFactory.Create();

            serverCallContext.UserState["__HttpContext"] = httpContextFactory();
            var dispatcher = new DispatcherService();

            var cmd = new TestCommand
            {
                Value = Guid.NewGuid().ToString()
            };

            var request = new RequestEnvelope()
            {
                Type    = cmd.GetType().AssemblyQualifiedName,
                Content = Value.Parser.ParseJson(JsonSerializer.Serialize(cmd))
            };

            var response = await dispatcher.Dispatch(request, serverCallContext);

            response.ShouldNotBeNull().Content.ShouldNotBeNull();
            var responseType = System.Type.GetType(response.Type, an => Assembly.Load(an.Name ?? null !), null, true, true).ShouldNotBeNull();

            JsonSerializer.Deserialize(JsonFormatter.Default.Format(response.Content), responseType).ShouldBeOfType <string>().ShouldBe(cmd.Value);
        }
예제 #5
0
        public async Task CanSerializeErrors()
        {
            var serverCallContext = TestServerCallContextFactory.Create();

            serverCallContext.UserState["__HttpContext"] = httpContextFactory();
            var dispatcher = new DispatcherService();
            var request    = new RequestEnvelope()
            {
                Type = typeof(TestThrowErrorCommand).AssemblyQualifiedName,
                Data = UnsafeByteOperations.UnsafeWrap(JsonSerializer.SerializeToUtf8Bytes(new TestThrowErrorCommand()))
            };
            var response = await dispatcher.Dispatch(request, serverCallContext);

            response.ShouldNotBeNull();
        }
예제 #6
0
 public void HighlightActivity(int selectedRowNumber)
 {
     DispatcherService.Dispatch(() =>
     {
         try
         {
             if (selectedRowNumber >= 0 && selectedRowNumber < stepSourceLocationMapping.Count)
             {
                 WorkflowDesigner.DebugManagerView.CurrentLocation = stepSourceLocationMapping[selectedRowNumber];
             }
         }
         catch (Exception)
         {
             // If the user clicks other than on the tracking records themselves.
             WorkflowDesigner.DebugManagerView.CurrentLocation = new SourceLocation("Workflow.xaml", 1, 1, 1, 10);
         }
     });
 }
예제 #7
0
        public async Task Dispatch_CommandWithNoReply_EmptyResponseType()
        {
            var serverCallContext = TestServerCallContextFactory.Create();

            serverCallContext.UserState["__HttpContext"] = httpContextFactory();
            var dispatcher = new DispatcherService();
            var cmd        = new TestCommandNoReturnValue();

            RequestEnvelope request = new RequestEnvelope()
            {
                Type    = cmd.GetType().AssemblyQualifiedName,
                Content = Value.Parser.ParseJson(JsonSerializer.Serialize(cmd))
            };
            var response = await dispatcher.Dispatch(request, serverCallContext);

            response.Type.ShouldBeNullOrEmpty();
            response.Content.ShouldBe(Value.ForNull());
        }
예제 #8
0
        public async Task Dispatch_CommandWithNoReply_EmptyResponseType()
        {
            var serverCallContext = TestServerCallContextFactory.Create();

            serverCallContext.UserState["__HttpContext"] = httpContextFactory();
            var dispatcher = new DispatcherService();
            var cmd        = new TestCommandNoReturnValue();

            RequestEnvelope request = new RequestEnvelope()
            {
                Type = cmd.GetType().AssemblyQualifiedName,
                Data = UnsafeByteOperations.UnsafeWrap(JsonSerializer.SerializeToUtf8Bytes(cmd))
            };
            var response = await dispatcher.Dispatch(request, serverCallContext);

            response.Error.ShouldBeFalse();
            response.Type.ShouldBeNullOrEmpty();
            response.Data.IsEmpty.ShouldBeTrue();
        }
예제 #9
0
        protected VisualTrackingParticipant InitialiseVisualTrackingParticipant(Activity activityToRun)
        {
            // Mapping between the object and Line No.
            var elementToSourceLocationMap = UpdateSourceLocationMappingInDebuggerService(activityToRun);

            // Mapping between the object and the Instance Id
            var activityIdToElementMap = elementToSourceLocationMap
                                         .Keys
                                         .OfType <Activity>()
                                         .ToDictionary(workflowElement => workflowElement.Id);

            // Setup custom tracking
            var participant = new VisualTrackingParticipant
            {
                ActivityIdToWorkflowElementMap = activityIdToElementMap,
                TrackingProfile = new TrackingProfile
                {
                    Name    = "VisualTrackingProfile",
                    Queries =
                    {
                        new CustomTrackingQuery
                        {
                            Name         = "*",
                            ActivityName = "*"
                        },
                        new WorkflowInstanceQuery
                        {
                            // Limit workflow instance tracking records for started and completed workflow states
                            States ={ WorkflowInstanceStates.Started,              WorkflowInstanceStates.Completed },
                        },
                        new ActivityStateQuery
                        {
                            // Subscribe for track records from all activities for all states
                            ActivityName = "*",
                            States       = { "*" },

                            // Extract workflow variables and arguments as a part of the activity tracking record
                            // VariableName = "*" allows for extraction of all variables in the scope
                            // of the activity
                            Variables ={ "*" }
                        }
                    }
                }
            };

            var debugInterval = Settings.Default.MillisecondsBetweenDebugSteps > 0
                                    ? Settings.Default.MillisecondsBetweenDebugSteps
                                    : 1000;

            // As the tracking events are received
            participant.TrackingRecordReceived += (trackingParticipant, trackingEventArgs) =>
            {
                if (trackingEventArgs.Activity != null)
                {
                    DispatcherService.Dispatch(() =>
                    {
                        WorkflowDesigner.DebugManagerView.CurrentLocation =
                            elementToSourceLocationMap[trackingEventArgs.Activity];
                    });

                    Thread.Sleep(debugInterval);

                    var debugItem = new DebugStep(
                        stepCount++,
                        trackingEventArgs.Record.EventTime,
                        trackingEventArgs.Activity.DisplayName,
                        trackingEventArgs.Activity.Id,
                        trackingEventArgs.Record.InstanceId,
                        ((ActivityStateRecord)trackingEventArgs.Record).State);

                    stepSourceLocationMapping.Add((int)stepCount - 1, elementToSourceLocationMap[trackingEventArgs.Activity]);
                    OnDebugStepAdded(debugItem);
                }
            };

            return(participant);
        }
        protected VisualTrackingParticipant InitialiseVisualTrackingParticipant(Activity workflowToRun)
        {
            // Mapping between the object and Line No.
            Dictionary <object, SourceLocation> elementToSourceLocationMap = this.UpdateSourceLocationMappingInDebuggerService(workflowToRun);

            // Mapping between the object and the Instance Id
            Dictionary <string, Activity> activityIdToElementMap = this.BuildactivityIdToElementMap(elementToSourceLocationMap);

            // Setup custom tracking
            const string All = "*";
            VisualTrackingParticipant simTracker = new VisualTrackingParticipant()
            {
                TrackingProfile = new TrackingProfile()
                {
                    Name    = "CustomTrackingProfile",
                    Queries =
                    {
                        new CustomTrackingQuery()
                        {
                            Name         = All,
                            ActivityName = All
                        },
                        new WorkflowInstanceQuery()
                        {
                            // Limit workflow instance tracking records for started and completed workflow states
                            States ={ WorkflowInstanceStates.Started,              WorkflowInstanceStates.Completed },
                        },
                        new ActivityStateQuery()
                        {
                            // Subscribe for track records from all activities for all states
                            ActivityName = All,
                            States       = { All },

                            // Extract workflow variables and arguments as a part of the activity tracking record
                            // VariableName = "*" allows for extraction of all variables in the scope
                            // of the activity
                            Variables =
                            {
                                { All }
                            }
                        }
                    }
                }
            };

            simTracker.ActivityIdToWorkflowElementMap = activityIdToElementMap;

            // As the tracking events are received
            simTracker.TrackingRecordReceived += (trackingParticpant, trackingEventArgs) =>
            {
                if (trackingEventArgs.Activity != null)
                {
                    ShowDebug(elementToSourceLocationMap[trackingEventArgs.Activity]);

                    Thread.Sleep(this.pauseBetweenDebugStepsInMilliseconds);

                    SourceLocationDebugItem debugItem = new SourceLocationDebugItem()
                    {
                        ActivityName = trackingEventArgs.Activity.DisplayName,
                        Id           = trackingEventArgs.Activity.Id,
                        State        = ((ActivityStateRecord)trackingEventArgs.Record).State,
                        StepCount    = sourceLocationSteppedCount,
                        InstanceId   = ((ActivityStateRecord)trackingEventArgs.Record).InstanceId
                    };

                    this.debugTraceSource.TraceData(
                        TraceEventType.Information,
                        0,
                        trackingEventArgs.Activity.DisplayName,
                        trackingEventArgs.Activity.Id,
                        ((ActivityStateRecord)trackingEventArgs.Record).State,
                        sourceLocationSteppedCount,
                        ((ActivityStateRecord)trackingEventArgs.Record).InstanceId);

                    this.allDebugTraceSource.TraceData(
                        TraceEventType.Information,
                        0,
                        Path.GetFileNameWithoutExtension(this.workflowName),
                        trackingEventArgs.Activity.DisplayName,
                        trackingEventArgs.Activity.Id,
                        ((ActivityStateRecord)trackingEventArgs.Record).State,
                        sourceLocationSteppedCount,
                        ((ActivityStateRecord)trackingEventArgs.Record).InstanceId);

                    sourceLocationSteppedCount++;

                    if (!this.disableDebugViewOutput)
                    {
                        this.textLineToSourceLocationMap.Add(this.sourceLocations.Count, elementToSourceLocationMap[trackingEventArgs.Activity]);
                        this.sourceLocations.Add(debugItem);

                        DispatcherService.Dispatch(() =>
                        {
                            debugView.ItemsSource = this.SourceLocations;
                            debugView.Items.Refresh();
                        });
                    }
                }
            };

            return(simTracker);
        }