//构造函数
        public designerDebugTracking(WorkflowDesigner designer)
        {
            //(1)
            this.designer = designer;
            this.debugService = designer.DebugManagerView as DebuggerService; ;

            //(2) TrackingProfile
            TrackingProfile trackingProfile = new TrackingProfile();
            ActivityStateQuery activityStateQuery = new ActivityStateQuery()
            {
                ActivityName = "*",
                States = { System.Activities.Tracking.ActivityStates.Executing },
                Variables = { "*" },
                Arguments = { "*" }
            };
            trackingProfile.Queries.Add(activityStateQuery);

            this.TrackingProfile = trackingProfile;

            //(3)
            clearTrackInfo();

            //(4)
            sourceLocationList = getSourceLocationMap();
            activityMapList = getActivityMapList(sourceLocationList);

        } //end
            public RuntimeTrackingProfile GetRuntimeTrackingProfile(TrackingProfile profile, Activity rootElement)
            {
                RuntimeTrackingProfile item = null;
                HybridCollection <RuntimeTrackingProfile> hybrids = null;

                lock (this.cache)
                {
                    if (!this.cache.TryGetValue(rootElement, out hybrids))
                    {
                        item    = new RuntimeTrackingProfile(profile, rootElement);
                        hybrids = new HybridCollection <RuntimeTrackingProfile>();
                        hybrids.Add(item);
                        this.cache.Add(rootElement, hybrids);
                        return(item);
                    }
                    foreach (RuntimeTrackingProfile profile3 in hybrids.AsReadOnly())
                    {
                        if ((string.CompareOrdinal(profile.Name, profile3.associatedProfile.Name) == 0) && (string.CompareOrdinal(profile.ActivityDefinitionId, profile3.associatedProfile.ActivityDefinitionId) == 0))
                        {
                            item = profile3;
                            break;
                        }
                    }
                    if (item == null)
                    {
                        item = new RuntimeTrackingProfile(profile, rootElement);
                        hybrids.Add(item);
                    }
                }
                return(item);
            }
        private RuntimeTrackingProfile GetRuntimeTrackingProfile(TrackingParticipant participant)
        {
            RuntimeTrackingProfile runtimeTrackingProfile;

            if (!this.profileSubscriptions.TryGetValue(participant, out runtimeTrackingProfile))
            {
                TrackingProfile trackingProfile = participant.TrackingProfile;
                if (trackingProfile != null)
                {
                    runtimeTrackingProfile = RuntimeTrackingProfile.GetRuntimeTrackingProfile(trackingProfile, this.definition);
                    this.Merge(runtimeTrackingProfile.Filter);
                    IEnumerable <string> subscribedActivityNames = runtimeTrackingProfile.GetSubscribedActivityNames();
                    if (subscribedActivityNames != null)
                    {
                        if (this.activitySubscriptions == null)
                        {
                            this.activitySubscriptions = new Hashtable();
                        }
                        foreach (string str in subscribedActivityNames)
                        {
                            if (this.activitySubscriptions[str] == null)
                            {
                                this.activitySubscriptions[str] = str;
                            }
                        }
                    }
                }
                else
                {
                    this.Merge(new TrackingRecordPreFilter(true));
                }
                this.profileSubscriptions.Add(participant, runtimeTrackingProfile);
            }
            return(runtimeTrackingProfile);
        }
        public GrainTrackingParticipant(Logger logger)
        {
            this.logger = logger;

            TrackingProfile = new TrackingProfile();
            TrackingProfile.Queries.Add(new WorkflowInstanceQuery()
            {
                States = { "*" },
            });
            //TrackingProfile.Queries.Add(new ActivityScheduledQuery()
            //{
            //    ActivityName = "*",
            //});
            //TrackingProfile.Queries.Add(new ActivityStateQuery()
            //{
            //    States = { "*" }
            //});
            TrackingProfile.Queries.Add(new BookmarkResumptionQuery()
            {
                Name = "*",
            });
            TrackingProfile.Queries.Add(new CancelRequestedQuery()
            {
                ActivityName = "*",
            });
            TrackingProfile.Queries.Add(new CustomTrackingQuery()
            {
                ActivityName = "*",
                Name = "*"
            });
            TrackingProfile.Queries.Add(new FaultPropagationQuery()
            {
                FaultSourceActivityName = "*",
            });
        }
Exemple #5
0
        /*
         * Enable Analytic and Debug Logs:
         * Event Viewer -> Applications and Services Logs ->
         * Microsoft -> Windows -> Application Server-Applications
         * Right-click "Application Server-Applications" -> select View ->
         * Show Analytic and Debug Logs -> Refresh
         * */
        static void Main(string[] args)
        {
            //Tracking Configuration
            TrackingProfile trackingProfile = new TrackingProfile();
            trackingProfile.Queries.Add(new WorkflowInstanceQuery
            {
                States = { "*" }
            });
            trackingProfile.Queries.Add(new ActivityStateQuery
            {
                States = { "*" }
            });
            trackingProfile.Queries.Add(new CustomTrackingQuery
            {
                ActivityName = "*",
                Name = "*"
            });
            EtwTrackingParticipant etwTrackingParticipant =
                new EtwTrackingParticipant();
            etwTrackingParticipant.TrackingProfile = trackingProfile;

            // Run workflow app "Workflow1.xaml"
            AutoResetEvent waitHandler = new AutoResetEvent(false);
            WorkflowApplication wfApp =
                new WorkflowApplication(new Workflow1());
            wfApp.Completed = (arg) => { waitHandler.Set(); };
            wfApp.Extensions.Add(etwTrackingParticipant);
            wfApp.Run();
            waitHandler.WaitOne();
        }
Exemple #6
0
        static void Main(string[] args)
        {
            TrackingProfile fileTrackingProfile = new TrackingProfile();
            fileTrackingProfile.Queries.Add(new WorkflowInstanceQuery
            {
                States = { "*" }
            });

            fileTrackingProfile.Queries.Add(new ActivityStateQuery()
            {
                States = {
                    ActivityStates.Executing,
                    ActivityStates.Closed
                }
            });

            FileTrackingParticipant fileTrackingParticipant = new FileTrackingParticipant();
            fileTrackingParticipant.TrackingProfile = fileTrackingProfile;

            AutoResetEvent waitHandler = new AutoResetEvent(false);
            WorkflowApplication wfapp = new WorkflowApplication(new Workflow1());
            wfapp.Unloaded = (wfAppEventArg) => { waitHandler.Set(); };
            wfapp.Extensions.Add(fileTrackingParticipant);
            wfapp.Run();

            waitHandler.WaitOne();
        }
Exemple #7
0
        private static TrackingProfile CreateTrace(List<string> argumentNames, List<string> variableNames)
        {
            var trackingProfile = new TrackingProfile()
            {
                ImplementationVisibility = ImplementationVisibility.All,
                Name = "CustomTrackingProfile",
                Queries =
                {
                    new CustomTrackingQuery()
                    {
                     Name = "*",
                     ActivityName = "*"
                    },
                    new WorkflowInstanceQuery()
                    {

                         // Limit workflow instance tracking records for started and completed workflow states
                        States = {WorkflowInstanceStates.Started, WorkflowInstanceStates.Completed },
                   }
                }
            };

            trackingProfile.Queries.Add(GetActivityQueryState(argumentNames, variableNames));

            return trackingProfile;
        }
        TrackingProfile GetProfile(string profileName)
        {
            TrackingProfile profile = new TrackingProfile();
            TrackingSection trackingSection = (TrackingSection)ConfigurationManager.GetSection("system.serviceModel/tracking");
            if (trackingSection == null) return null;

            var match = from p in new List<TrackingProfile>(trackingSection.TrackingProfiles)
                        where p.Name == profileName
                        select p;

            if (match.Count() == 0) throw new ConfigurationErrorsException(string.Format("Could not find a profile with name '{0}'", profileName));
            else return match.First();
        }
        public void ShouldHostService()
        {
            var trackingProfile = new TrackingProfile { Queries = { new ActivityStateQuery { ActivityName = "ReceiveRequest", States = { "Executing" }, }, new ActivityStateQuery { ActivityName = "SendResponse", States = { "Executing" }, }, } };

            var xamlInjector = new XamlInjector("TestSumService.xamlx");

            // The first TestActivity1 will not be replaced - will add 1 to sum

            // Replace the second TestActivity1 with TestActivity2 - will add 2 to sum
            xamlInjector.ReplaceAt(1, typeof(TestActivity1), typeof(TestActivity2));

            // Replace third TestActivity1 with TestActivity3 - will add 3 to sum
            xamlInjector.ReplaceAt(2, typeof(TestActivity1), typeof(TestActivity3));

            // Replace all (2) TestActivity4 with TestActivity5 - will add 10 to sum
            xamlInjector.ReplaceAll(typeof(TestActivity4), typeof(TestActivity5));

            // Response will be (data=1)+1+2+3+10 = 17
            var serviceAddress = ServiceTest.GetUniqueEndpointAddress();
            using (var testHost = new WorkflowServiceTestHost(xamlInjector.GetWorkflowService(), serviceAddress))
            {
                testHost.Tracking.TrackingProfile = trackingProfile;
                testHost.Open();

                var client = ChannelFactory<ITestService>.CreateChannel(ServiceTest.Pipe, serviceAddress);
                var response = client.GetData(1);
                Assert.AreEqual("17", response);

                testHost.Close();

                // Find the tracking records for the ReceiveRequest and SendResponse

                // Activity <ReceiveRequest> state is Executing
                AssertTracking.ExistsAt(testHost.Tracking.Records, 0, "ReceiveRequest", ActivityInstanceState.Executing);

                // Activity <SendResponse> state is Executing
                AssertTracking.ExistsAt(testHost.Tracking.Records, 1, "SendResponse", ActivityInstanceState.Executing);
            }
        }
Exemple #10
0
            public RuntimeTrackingProfile GetRuntimeTrackingProfile(TrackingProfile profile, Activity rootElement)
            {
                Fx.Assert(rootElement != null, "Root element must be valid");

                RuntimeTrackingProfile foundRuntimeProfile = null;
                HybridCollection <RuntimeTrackingProfile> runtimeProfileList = null;

                lock (this.cache)
                {
                    if (!this.cache.TryGetValue(rootElement, out runtimeProfileList))
                    {
                        foundRuntimeProfile = new RuntimeTrackingProfile(profile, rootElement);
                        runtimeProfileList  = new HybridCollection <RuntimeTrackingProfile>();
                        runtimeProfileList.Add(foundRuntimeProfile);

                        this.cache.Add(rootElement, runtimeProfileList);
                    }
                    else
                    {
                        var runtimeProfileCollection = runtimeProfileList.AsReadOnly();
                        foreach (var runtimeProfile in runtimeProfileCollection)
                        {
                            if (string.CompareOrdinal(profile.Name, runtimeProfile.associatedProfile.Name) == 0 &&
                                string.CompareOrdinal(profile.ActivityDefinitionId, runtimeProfile.associatedProfile.ActivityDefinitionId) == 0)
                            {
                                foundRuntimeProfile = runtimeProfile;
                                break;
                            }
                        }

                        if (foundRuntimeProfile == null)
                        {
                            foundRuntimeProfile = new RuntimeTrackingProfile(profile, rootElement);
                            runtimeProfileList.Add(foundRuntimeProfile);
                        }
                    }
                }
                return(foundRuntimeProfile);
            }
        internal RuntimeTrackingProfile(TrackingProfile profile, Activity rootElement)
        {
            this.associatedProfile = profile;
            this.isRootNativeActivity = rootElement is NativeActivity;
            this.trackingRecordPreFilter = new TrackingRecordPreFilter();

            foreach (TrackingQuery query in this.associatedProfile.Queries)
            {
                if (query is ActivityStateQuery)
                {
                    AddActivitySubscription((ActivityStateQuery)query);
                }
                else if (query is WorkflowInstanceQuery)
                {
                    AddWorkflowSubscription((WorkflowInstanceQuery)query);
                }
                else if (query is BookmarkResumptionQuery)
                {
                    AddBookmarkSubscription((BookmarkResumptionQuery)query);
                }
                else if (query is CustomTrackingQuery)
                {
                    AddCustomTrackingSubscription((CustomTrackingQuery)query);
                }
                else if (query is ActivityScheduledQuery)
                {
                    AddActivityScheduledSubscription((ActivityScheduledQuery)query);
                }
                else if (query is CancelRequestedQuery)
                {
                    AddCancelRequestedSubscription((CancelRequestedQuery)query);
                }
                else if (query is FaultPropagationQuery)
                {
                    AddFaultPropagationSubscription((FaultPropagationQuery)query);
                }
            }
        }
Exemple #12
0
        internal RuntimeTrackingProfile(TrackingProfile profile, Activity rootElement)
        {
            this.associatedProfile       = profile;
            this.isRootNativeActivity    = rootElement is NativeActivity;
            this.trackingRecordPreFilter = new TrackingRecordPreFilter();

            foreach (var query in this.associatedProfile.Queries)
            {
                if (query is ActivityStateQuery)
                {
                    AddActivitySubscription((ActivityStateQuery)query);
                }
                else if (query is WorkflowInstanceQuery)
                {
                    AddWorkflowSubscription((WorkflowInstanceQuery)query);
                }
                else if (query is BookmarkResumptionQuery)
                {
                    AddBookmarkSubscription((BookmarkResumptionQuery)query);
                }
                else if (query is CustomTrackingQuery)
                {
                    AddCustomTrackingSubscription((CustomTrackingQuery)query);
                }
                else if (query is ActivityScheduledQuery)
                {
                    AddActivityScheduledSubscription((ActivityScheduledQuery)query);
                }
                else if (query is CancelRequestedQuery)
                {
                    AddCancelRequestedSubscription((CancelRequestedQuery)query);
                }
                else if (query is FaultPropagationQuery)
                {
                    AddFaultPropagationSubscription((FaultPropagationQuery)query);
                }
            }
        }
 public RuntimeTrackingProfile GetRuntimeTrackingProfile(TrackingProfile profile, Activity rootElement)
 {
     RuntimeTrackingProfile item = null;
     HybridCollection<RuntimeTrackingProfile> hybrids = null;
     lock (this.cache)
     {
         if (!this.cache.TryGetValue(rootElement, out hybrids))
         {
             item = new RuntimeTrackingProfile(profile, rootElement);
             hybrids = new HybridCollection<RuntimeTrackingProfile>();
             hybrids.Add(item);
             this.cache.Add(rootElement, hybrids);
             return item;
         }
         foreach (RuntimeTrackingProfile profile3 in hybrids.AsReadOnly())
         {
             if ((string.CompareOrdinal(profile.Name, profile3.associatedProfile.Name) == 0) && (string.CompareOrdinal(profile.ActivityDefinitionId, profile3.associatedProfile.ActivityDefinitionId) == 0))
             {
                 item = profile3;
                 break;
             }
         }
         if (item == null)
         {
             item = new RuntimeTrackingProfile(profile, rootElement);
             hybrids.Add(item);
         }
     }
     return item;
 }
 internal static RuntimeTrackingProfile GetRuntimeTrackingProfile(TrackingProfile profile, Activity rootElement)
 {
     return Cache.GetRuntimeTrackingProfile(profile, rootElement);
 }
 public Collection<TrackingProfile> ReadProfiles()
 {
     if (this.trackingProfiles == null)
     {
         TrackingSection section = null;
         try
         {
             section = (TrackingSection) ConfigurationHelpers.GetSection(ConfigurationHelpers.GetSectionPath("tracking"));
         }
         catch (ConfigurationErrorsException exception)
         {
             if (!Fx.IsFatal(exception))
             {
                 FxTrace.Exception.TraceUnhandledException(exception);
             }
             throw;
         }
         if (section == null)
         {
             return null;
         }
         this.trackingProfiles = new Collection<TrackingProfile>();
         foreach (ProfileElement element in section.Profiles)
         {
             if (element.Workflows != null)
             {
                 foreach (ProfileWorkflowElement element2 in element.Workflows)
                 {
                     TrackingProfile item = new TrackingProfile {
                         Name = element.Name,
                         ImplementationVisibility = element.ImplementationVisibility,
                         ActivityDefinitionId = element2.ActivityDefinitionId
                     };
                     element2.AddQueries(item.Queries);
                     this.trackingProfiles.Add(item);
                 }
             }
         }
     }
     return this.trackingProfiles;
 }
Exemple #16
0
 internal static RuntimeTrackingProfile GetRuntimeTrackingProfile(TrackingProfile profile, Activity rootElement)
 {
     return(RuntimeTrackingProfile.Cache.GetRuntimeTrackingProfile(profile, rootElement));
 }
        TrackingProfile GetProfile(string trackingProfileName, string displayName)
        {
            TrackingProfile trackingProfile;
            TrackingSection trackingSection = (TrackingSection)WebConfigurationManager.GetSection("system.serviceModel/tracking");
            if (trackingSection == null) {
                return null;
            }

            if (trackingProfileName == null) {
                trackingProfileName = "";
            }

            //Find the profile with the specified profile name in the list of profile found in config
            var match = from p in new List<TrackingProfile>(trackingSection.TrackingProfiles)
                        where (p.Name == trackingProfileName) && ((p.ActivityDefinitionId == displayName) || (p.ActivityDefinitionId == "*"))
                        select p;

            if (match.Count() == 0) {
                //return an empty profile
                trackingProfile = new TrackingProfile {
                    ActivityDefinitionId = displayName
                };

            }
            else {
                trackingProfile = match.First();
            }

            return trackingProfile;
        }
Exemple #18
0
        public void ShouldOutputVerboseTrace()
        {
            // Arrange
            string testCategory = "Test";
            string expectedData = "From SayHello";
            string expectedTrace = string.Format("{0}: {1}", testCategory, expectedData);
            var listener = new TestTraceListener();
            var tracker = new TestTrackingParticipant();
            var profile = new TrackingProfile()
            {
                Name = "TestTrackingProfile",
                Queries = 
                {
                    new CustomTrackingQuery()
                    {
                        Name="Test",
                        ActivityName = "*"
                    }
                }
            };

            tracker.TrackingProfile = profile;

            Trace.Listeners.Add(listener);

            var target = new SayHello()
            {
                UserName = "******"
            };

            var workflow = new WorkflowInvoker(target);
            workflow.Extensions.Add(tracker);

            // Act
            workflow.Invoke();

            // Assert System.Diagnostics.Trace
            Assert.AreEqual(1, listener.Traces.Count);
            Assert.AreEqual(expectedTrace, listener.Traces[0]);

            // Assert Tracking Records
            Assert.AreEqual(1, tracker.Records.Count);
            var customRecord = tracker.Records[0] as CustomTrackingRecord;
            Assert.AreEqual(expectedData, customRecord.Data["Text"]);
            Assert.AreEqual(testCategory, customRecord.Data["Category"]);
        }
            public Collection<TrackingProfile> ReadProfiles()
            {
                if (this.trackingProfiles != null)
                {
                    return this.trackingProfiles;
                }

                TrackingSection trackingSection = null;

                try
                {
                    trackingSection =
                        (TrackingSection)ConfigurationHelpers.GetSection(ConfigurationHelpers.GetSectionPath(TrackingConfigurationStrings.Tracking));
                }
                catch (ConfigurationErrorsException e)
                {
                    if (!Fx.IsFatal(e))
                    {
                        FxTrace.Exception.TraceUnhandledException(e);
                    }

                    throw;
                }

                if (trackingSection == null)
                {
                    return null;
                }

                // Configuration elements are never null, collections are empty
                // and single elements are constructed with the property IsPresent=false
                this.trackingProfiles = new Collection<TrackingProfile>();

                foreach (ProfileElement profileElement in trackingSection.Profiles)
                {
                    if (profileElement.Workflows != null)
                    {
                        foreach (ProfileWorkflowElement workflowElement in profileElement.Workflows)
                        {
                            TrackingProfile profile = new TrackingProfile()
                            {
                                Name = profileElement.Name,
                                ImplementationVisibility = profileElement.ImplementationVisibility,
                                ActivityDefinitionId = workflowElement.ActivityDefinitionId
                            };

                            workflowElement.AddQueries(profile.Queries);

                            this.trackingProfiles.Add(profile);
                        }
                    }
                }

                return this.trackingProfiles;
            }
        internal TrackingProfile GetProfile(string profileName, string activityDefinitionId)
        {
            // Get all profiles from the store
            Collection<TrackingProfile> profiles = this.ProfileStore.ReadProfiles();

            TrackingProfile bestMatch = null;
            if (profiles != null)
            {
                // Go through all the profiles in the data store and find a match to the requested profile
                foreach (TrackingProfile profile in profiles)
                {
                    // Check the profile matches the requested name, and scope type
                    if (string.Compare(profileName, profile.Name, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        // If we find a global scope profile, use it as the default profile
                        if (string.Compare("*", profile.ActivityDefinitionId, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            if (bestMatch == null)
                            {
                                bestMatch = profile;
                            }
                        }
                        else if (string.Compare(activityDefinitionId, profile.ActivityDefinitionId, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            //specific profile for scopetarget found. 
                            bestMatch = profile;
                            break;
                        }
                    }
                }
            }
            if (bestMatch == null)
            {
                //Add a trace message indicating tracking profile with activity definiton id is not found
                if (TD.TrackingProfileNotFoundIsEnabled())
                {
                    TD.TrackingProfileNotFound(profileName, activityDefinitionId);
                }

                //If the profile is not found in config, return an empty profile to suppress
                //events. If .config does not have profiles, return null.
                bestMatch = new TrackingProfile()
                {
                    ActivityDefinitionId = activityDefinitionId
                };
            }
            
            return bestMatch;
        }
Exemple #21
0
        public void ShouldOutputVerboseTrace()
        {
            var targetWorkflow = GetVerboseTraceWorkflow();
            var listener = new TestTraceListener();
            var tracker = new TestTrackingParticipant();
            var profile = new TrackingProfile()
            {
                Name = "TestTrackingProfile",
                Queries = 
                {
                    new CustomTrackingQuery()
                    {
                        Name=TestCategory,
                        ActivityName = "*"
                    }
                }
            };

            tracker.TrackingProfile = profile;

            Trace.Listeners.Add(listener);

            var workflow = new WorkflowInvoker(targetWorkflow);
            workflow.Extensions.Add(tracker);

            workflow.Invoke();

            // Assert System.Diagnostics.Trace
            Assert.AreEqual(1, listener.Traces.Count);
            Assert.AreEqual(TestOutput, listener.Traces[0]);

            // Assert Tracking Records
            Assert.AreEqual(1, tracker.Records.Count);
            var customRecord = tracker.Records[0] as CustomTrackingRecord;
            Assert.AreEqual(TestTrace, customRecord.Data["Text"]);
            Assert.AreEqual(TestCategory, customRecord.Data["Category"]);
        }
            public RuntimeTrackingProfile GetRuntimeTrackingProfile(TrackingProfile profile, Activity rootElement)
            {
                Fx.Assert(rootElement != null, "Root element must be valid");

                RuntimeTrackingProfile foundRuntimeProfile = null;
                HybridCollection<RuntimeTrackingProfile> runtimeProfileList = null;

                lock (this.cache)
                {
                    if (!this.cache.TryGetValue(rootElement, out runtimeProfileList))
                    {
                        foundRuntimeProfile = new RuntimeTrackingProfile(profile, rootElement);
                        runtimeProfileList = new HybridCollection<RuntimeTrackingProfile>();
                        runtimeProfileList.Add(foundRuntimeProfile);

                        this.cache.Add(rootElement, runtimeProfileList);
                    }
                    else
                    {
                        ReadOnlyCollection<RuntimeTrackingProfile> runtimeProfileCollection = runtimeProfileList.AsReadOnly();
                        foreach (RuntimeTrackingProfile runtimeProfile in runtimeProfileCollection)
                        {
                            if (string.CompareOrdinal(profile.Name, runtimeProfile.associatedProfile.Name) == 0 &&
                                string.CompareOrdinal(profile.ActivityDefinitionId, runtimeProfile.associatedProfile.ActivityDefinitionId) == 0)
                            {
                                foundRuntimeProfile = runtimeProfile;
                                break;
                            }
                        }

                        if (foundRuntimeProfile == null)
                        {
                            foundRuntimeProfile = new RuntimeTrackingProfile(profile, rootElement);
                            runtimeProfileList.Add(foundRuntimeProfile);
                        }
                    }
                }
                return foundRuntimeProfile;
            }
Exemple #23
0
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            var projectInfo = new ProjectInformation
            {
                ProjectName = txtProjectName.Text,
                ApplicationInfo = _applicationData.ToList()
            };
            var workflowArgs =
                new Dictionary<string, object> {{"ProjectInfo", projectInfo}};

            _workflow = new WorkflowApplication(new TheWorkflow(),workflowArgs)
            {
                Completed = WorkflowCompletedCallback,
                Idle = WorkflowIdleCallback
            };

            _workflow.Extensions.Add(new List<string>());

            _workflow.Extensions.Add(_wce);

            var trackingParticipant = new EtwTrackingParticipant();

            var trackingProfile = new TrackingProfile
            {
                Name = "SampleTrackingProfile",
                ActivityDefinitionId = "FIB-->FIS"
            };

            trackingProfile.Queries.Add(new WorkflowInstanceQuery {States = {"*"}});

            _workflow.Extensions.Add(trackingParticipant);

            txbOutput.Text += "Starting planning phase...\r\n";

            _workflow.Run();
        }
        TrackingProfile GetProfile(string profileName, string profileTarget)
        {
            TrackingSection trackingSection =
                    (TrackingSection)ConfigurationManager.GetSection("system.serviceModel/tracking");

            TrackingProfile bestMatch = null;

            foreach (TrackingProfile profile in trackingSection.TrackingProfiles)
            {
                // Check the profile matches the requested name, and scope type
                if (string.Compare(profileName, profile.Name, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    // If we find a global scope profile, use it as the default profile
                    if (string.Compare("*", profile.ActivityDefinitionId, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        if (bestMatch == null)
                        {
                            bestMatch = profile;
                        }
                    }
                    else if (string.Compare(profileTarget, profile.ActivityDefinitionId, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        //specific profile for scopetarget found.
                        bestMatch = profile;
                        break;
                    }
                }
            }
            if (bestMatch == null)
            {
                //If the profile is not found in config, return an empty profile to suppress
                //events. If .config does not have profiles, return null.
                bestMatch = new TrackingProfile()
                {
                    ActivityDefinitionId = profileTarget,
                };

            }

            return bestMatch;
        }
        TrackingProfile GetProfile(string profileName, string displayName)
        {
            TrackingProfile trackingProfile = null;
            TrackingSection trackingSection = (TrackingSection)WebConfigurationManager.GetSection("system.serviceModel/tracking");
            if (trackingSection == null)
            {
                return null;
            }

            //Find the profile with the specified profile name in the list of profile found in config
            var match = from p in new List<TrackingProfile>(trackingSection.TrackingProfiles)
                        where p.Name == profileName
                        select p;

            if (match.Count() == 0)
            {
                throw new ConfigurationErrorsException(string.Format("Could not find a profile with name '{0}'", profileName));
            }
            else
            {
                trackingProfile = match.First();
            }

            //No matching profile with the specified name was found
            if (trackingProfile == null)
            {
                //return an empty profile
                trackingProfile = new TrackingProfile()
                {
                    ActivityDefinitionId = displayName
                };
            }

            return trackingProfile;
        }
        public void ShouldHostService()
        {
            var trackingProfile = new TrackingProfile { Queries = { new ActivityStateQuery { ActivityName = "ReceiveRequest", States = { "Executing" }, }, new ActivityStateQuery { ActivityName = "SendResponse", States = { "Executing" }, }, } };

            var serviceAddress = ServiceTest.GetUniqueEndpointAddress();
            using (var testHost = WorkflowServiceTestHost.Open("TestService.xamlx", serviceAddress))
            {
                testHost.TrackingProfile = trackingProfile;
                var client = ChannelFactory<ITestService>.CreateChannel(ServiceTest.Pipe, serviceAddress);
                var response = client.GetData(1);
                Assert.AreEqual("1", response);

                testHost.Close();

                // Find the tracking records for the ReceiveRequest and SendResponse

                // Activity <ReceiveRequest> state is Executing
                testHost.Tracking.Assert.ExistsAt(0, "ReceiveRequest", ActivityInstanceState.Executing);

                // Activity <SendResponse> state is Executing
                testHost.Tracking.Assert.ExistsAt(1, "SendResponse", ActivityInstanceState.Executing);
            }
        }
        TrackingProfile CreateTrackingProfile()
        {
            TrackingProfile trackingProfile = new TrackingProfile()
                {
                    Name = "CustomTrackingProfile",
                    Queries =
                    {
                        new CustomTrackingQuery()
                        {
                         Name = "*",
                         ActivityName = "*"
                        },
                        new WorkflowInstanceQuery()
                        {
                            States = { "*" }
                        }
                    }
                };

            if (this.hostView.UseActivityTracking)
            {
                trackingProfile.Queries.Add(
                    new ActivityStateQuery()
                        {

                            ActivityName = "*",
                            States = { "*" },
                            Variables = { "*" }
                        });
                trackingProfile.Queries.Add(
                    new ActivityScheduledQuery() { ChildActivityName = "*" });
            }

            return trackingProfile;
        }
		private PSWorkflowTrackingParticipant GetTrackingParticipant()
		{
			PSWorkflowTrackingParticipant pSWorkflowTrackingParticipant = new PSWorkflowTrackingParticipant();
			TrackingProfile trackingProfile = new TrackingProfile();
			trackingProfile.Name = "WorkflowTrackingProfile";
			CustomTrackingQuery customTrackingQuery = new CustomTrackingQuery();
			customTrackingQuery.Name = "*";
			customTrackingQuery.ActivityName = "*";
			trackingProfile.Queries.Add(customTrackingQuery);
			WorkflowInstanceQuery workflowInstanceQuery = new WorkflowInstanceQuery();
			workflowInstanceQuery.States.Add("Started");
			workflowInstanceQuery.States.Add("Completed");
			workflowInstanceQuery.States.Add("Persisted");
			workflowInstanceQuery.States.Add("UnhandledException");
			trackingProfile.Queries.Add(workflowInstanceQuery);
			ActivityStateQuery activityStateQuery = new ActivityStateQuery();
			activityStateQuery.ActivityName = "*";
			activityStateQuery.States.Add("*");
			activityStateQuery.Variables.Add("*");
			trackingProfile.Queries.Add(activityStateQuery);
			pSWorkflowTrackingParticipant.TrackingProfile = trackingProfile;
			PSWorkflowTrackingParticipant pSWorkflowTrackingParticipant1 = pSWorkflowTrackingParticipant;
			return pSWorkflowTrackingParticipant1;
		}