Esempio n. 1
0
        static void Main()
        {
            try
            {
                waitHandle = new AutoResetEvent(false);
                CreateAndInsertTrackingProfile();
                using (WorkflowRuntime runtime = new WorkflowRuntime())
                {
                    SqlTrackingService trackingService = new SqlTrackingService(connectionString);
                    runtime.AddService(trackingService);
                    runtime.StartRuntime();
                    runtime.WorkflowCompleted  += OnWorkflowCompleted;
                    runtime.WorkflowTerminated += OnWorkflowTerminated;
                    runtime.WorkflowAborted    += OnWorkflowAborted;

                    WorkflowInstance instance = runtime.CreateWorkflow(typeof(BankMachineWorkflow));
                    instance.Start();
                    waitHandle.WaitOne();

                    runtime.StopRuntime();
                    OutputTrackedData(instance.InstanceId);
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);
                }
                else
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Esempio n. 2
0
        static void Main()
        {
            try
            {
                waitHandle = new AutoResetEvent(false);
                CreateAndInsertTrackingProfile();
                using (WorkflowRuntime runtime = new WorkflowRuntime())
                {
                    SqlTrackingService trackingService = new SqlTrackingService(connectionString);
                    runtime.AddService(trackingService);
                    runtime.StartRuntime();
                    runtime.WorkflowCompleted += OnWorkflowCompleted;
                    runtime.WorkflowTerminated += OnWorkflowTerminated;
                    runtime.WorkflowAborted += OnWorkflowAborted;

                    WorkflowInstance instance = runtime.CreateWorkflow(typeof(BankMachineWorkflow));
                    instance.Start();
                    waitHandle.WaitOne();

                    runtime.StopRuntime();
                    OutputTrackedData(instance.InstanceId);
                    
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                    Console.WriteLine(ex.InnerException.Message);
                else
                    Console.WriteLine(ex.Message);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Add any services needed by the runtime engine
        /// </summary>
        /// <param name="instance"></param>
        private static void AddServices(WorkflowRuntime instance)
        {
#if CUSTOM_SERVICE
            //use the custom Console tracking service
            ConsoleTrackingService tracking
                = new ConsoleTrackingService();
#else
            //use the standard SQL Server tracking service
            SqlTrackingService tracking
                = new SqlTrackingService(_connStringTracking);
#endif

//#if RULES_TRACKING || USER_DATA_TRACKING || CUSTOM_SERVICE
            //when tracking rules or custom user track points,
            //the PartitionOnCompletion causes
            //a problem with the SqlTrackingQuery class. The class
            //is unable to retrieve user tracking entries as
            //UserEvents.  Turning PartitionOnCompletion off
            //solves the problem.
//#else
            //use automatic database partitioning.  this will create
            //a new set of tables for each time period.  the default
            //time period is monthly ('m') but can be changed using
            //the SetPartitionInterval stored procedure.
            //tracking.PartitionOnCompletion = true;
//#endif
            //add the service to the runtime
            instance.AddService(tracking);
        }
Esempio n. 4
0
        static void Main()
        {
            try
            {
                waitHandle = new AutoResetEvent(false);
                
                DataAccess.CreateAndInsertTrackingProfile();
                using (WorkflowRuntime runtime = new WorkflowRuntime())
                {
                    SqlTrackingService trackingService = new SqlTrackingService(DataAccess.connectionString);

                    /*
                     *  Set partitioning settings on Sql Tracking Service and database
                     */

                    //Turn on PartitionOnCompletion setting-- Default is false
                    trackingService.PartitionOnCompletion = true;

                    //Set partition interval-- Default is 'm' (monthly)
                    DataAccess.SetPartitionInterval('d');

                    runtime.AddService(trackingService);
                    runtime.StartRuntime();

                    runtime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
                    {
                       waitHandle.Set();
                    };
                    
                    runtime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                    {
                        Console.WriteLine(e.Exception.Message);
                        waitHandle.Set();
                    };

                    WorkflowInstance instance = runtime.CreateWorkflow(typeof(SimpleWorkflow));
                    instance.Start();
                    waitHandle.WaitOne();

                    runtime.StopRuntime();
                    DataAccess.GetWorkflowTrackingEvents(instance.InstanceId);
                    Console.WriteLine("\nDone running the workflow.");

                    /*
                     *  Show tracking partition information and tables
                     */

                    DataAccess.ShowTrackingPartitionInformation();
                    DataAccess.ShowPartitionTableInformation();
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                    Console.WriteLine(ex.InnerException.Message);
                else
                    Console.WriteLine(ex.Message);
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting CRySTAL...");
            Console.WriteLine("Linking Workflow Runtime Services...");
            CRySTAL.WorkflowInterface.WorkflowInterface.CustomerWF = new CRySTAL.WorkflowInterface.CustomerWorkflowInterface();
            WorkflowRuntime workflowRuntime = new WorkflowRuntime();
            AppDomain.CurrentDomain.SetData("WorkflowRuntime", workflowRuntime);
            ManualWorkflowSchedulerService manualScheduler =
                new ManualWorkflowSchedulerService(true);
            AppDomain.CurrentDomain.SetData("ManualScheduler", manualScheduler);
            workflowRuntime.AddService(manualScheduler);
            ExternalDataExchangeService des = new ExternalDataExchangeService();
            workflowRuntime.AddService(des);
            des.AddService(CRySTAL.WorkflowInterface.WorkflowInterface.CustomerWF);

            TimeSpan reloadIntevral = new TimeSpan(0, 0, 0, 20, 0);
            TimeSpan ownershipDuration = new TimeSpan(0, 0, 30, 0);
            string connectionString = @"Data Source=ETHIELE-LENOVO\SQLEXPRESS;Initial Catalog=WFTrackingAndPersistence;Integrated Security=True";
            SqlWorkflowPersistenceService sqlPersistenceService =
                new SqlWorkflowPersistenceService(connectionString, true, ownershipDuration, reloadIntevral);
            workflowRuntime.AddService(sqlPersistenceService);

            SqlTrackingService sts = new SqlTrackingService(connectionString);
            workflowRuntime.AddService(sts);

            Console.WriteLine("Starting Workflow Runtime...");
            workflowRuntime.StartRuntime();

            //AppDomain.CurrentDomain.SetData("firstNamestr", "thisisatest");
            List<ServiceHost> hosts = new List<ServiceHost>();
            hosts.Add(new ServiceHost(typeof(CRySTAL.CookService)));
            hosts.Add(new ServiceHost(typeof(CRySTAL.BusBoyService)));
            hosts.Add(new ServiceHost(typeof(CRySTAL.HostService)));
            hosts.Add(new ServiceHost(typeof(CRySTAL.LoginService)));
            hosts.Add(new ServiceHost(typeof(CRySTAL.MenuService)));
            hosts.Add(new ServiceHost(typeof(CRySTAL.WaiterService)));
            foreach (ServiceHost host in hosts)
            {
                host.Open();
                Console.WriteLine("CRySTAL: Service Running: " + host.BaseAddresses[0].ToString());
            }
            Console.WriteLine("CRySTAL Ready");

            Console.ReadLine();

            Console.WriteLine("Shutting down CRySTAL...");
            foreach (ServiceHost host in hosts)
            {
                host.Close();
                Console.WriteLine("CRySTAL: Shutingdown Service :" + host.BaseAddresses[0].ToString());
            }
            Console.WriteLine("Shutting down runtime...");
            workflowRuntime.StopRuntime();
            Console.WriteLine("CRySTAL shutdown complete");
            Console.ReadLine();
        }
Esempio n. 6
0
        private ReadOnlyCollection <string> GetStateHistory()
        {
            StateMachineWorkflowActivity stateMachineWorkflow;

            if (this._sqlTrackingService == null)
            {
                this._sqlTrackingService = this._runtime.GetService <SqlTrackingService>();
                if (this._sqlTrackingService == null)
                {
                    throw new InvalidOperationException(SR.GetSqlTrackingServiceRequired());
                }
            }
            if (this._sqlTrackingQuery == null)
            {
                this._sqlTrackingQuery = new SqlTrackingQuery(this._sqlTrackingService.ConnectionString);
            }
            Stack <string> stack = new Stack <string>();

            try
            {
                stateMachineWorkflow = this.StateMachineWorkflow;
            }
            catch (InvalidOperationException)
            {
                return(new ReadOnlyCollection <string>(stack.ToArray()));
            }
            if ((this._sqlTrackingWorkflowInstance != null) || this._sqlTrackingQuery.TryGetWorkflow(this._instanceId, out this._sqlTrackingWorkflowInstance))
            {
                this._sqlTrackingWorkflowInstance.Refresh();
                foreach (UserTrackingRecord record in this._sqlTrackingWorkflowInstance.UserEvents)
                {
                    if (record.UserDataKey == "StateActivity.StateChange")
                    {
                        string userData = record.UserData as string;
                        if (userData == null)
                        {
                            throw new InvalidOperationException(SR.GetInvalidUserDataInStateChangeTrackingRecord());
                        }
                        StateActivity state = StateMachineHelpers.FindStateByName(stateMachineWorkflow, record.QualifiedName);
                        if (state == null)
                        {
                            throw new InvalidOperationException(SR.GetInvalidUserDataInStateChangeTrackingRecord());
                        }
                        if (StateMachineHelpers.IsLeafState(state))
                        {
                            stack.Push(userData);
                        }
                    }
                }
            }
            return(new ReadOnlyCollection <string>(stack.ToArray()));
        }
Esempio n. 7
0
        static void Main()
        {
            // Create WorkflowRuntime
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                try
                {
                    // Add SqlTrackingService
                    SqlTrackingService sqlTrackingService = new SqlTrackingService(connectionString);
                    sqlTrackingService.IsTransactional = false;
                    workflowRuntime.AddService(sqlTrackingService);

                    // Subscribe to Workflow Suspended WorkflowRuntime Event
                    workflowRuntime.WorkflowSuspended += OnWorkflowSuspended;
                    // Subscribe to Workflow Terminated WorkflowRuntime Event
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                    // Start WorkflowRuntime
                    workflowRuntime.StartRuntime();

                    // Execute the ExceptionWorkflow Workflow
                    WriteTitle("Executing the exception workflow");
                    WorkflowInstance exceptionWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(ExceptionWorkflow));
                    exceptionWorkflowInstance.Start();
                    waitHandle.WaitOne();
                    QueryAndWriteTrackingInformationToConsole(exceptionWorkflowInstance.InstanceId, TrackingWorkflowEvent.Exception);
                    QueryAndWriteTrackingInformationToConsole(exceptionWorkflowInstance.InstanceId, TrackingWorkflowEvent.Terminated);

                    // Execute the SuspendedWorkflow Workflow
                    WriteTitle("Executing the suspended workflow");
                    WorkflowInstance suspendedWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(SuspendedWorkflow));
                    suspendedWorkflowInstance.Start();
                    waitHandle.WaitOne();
                    QueryAndWriteTrackingInformationToConsole(suspendedWorkflowInstance.InstanceId, TrackingWorkflowEvent.Suspended);

                    // Stop Runtime
                    workflowRuntime.StopRuntime();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Encountered an exception. Exception Source: {0}, Exception Message: {1} ", e.Source, e.Message);
                }
                finally
                {
                    workflowRuntime.StopRuntime();
                }
            }
        }
Esempio n. 8
0
        static void Main()
        {
            // Create WorkflowRuntime
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                try
                {
                    // Add SqlTrackingService
                    SqlTrackingService sqlTrackingService = new SqlTrackingService(connectionString);
                    sqlTrackingService.IsTransactional = false;
                    workflowRuntime.AddService(sqlTrackingService);

                    // Subscribe to Workflow Suspended WorkflowRuntime Event
                    workflowRuntime.WorkflowSuspended += OnWorkflowSuspended;
                    // Subscribe to Workflow Terminated WorkflowRuntime Event
                    workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;

                    // Start WorkflowRuntime
                    workflowRuntime.StartRuntime();

                    // Execute the ExceptionWorkflow Workflow
                    WriteTitle("Executing the exception workflow");
                    WorkflowInstance exceptionWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(ExceptionWorkflow));
                    exceptionWorkflowInstance.Start();
                    waitHandle.WaitOne();
                    QueryAndWriteTrackingInformationToConsole(exceptionWorkflowInstance.InstanceId, TrackingWorkflowEvent.Exception);
                    QueryAndWriteTrackingInformationToConsole(exceptionWorkflowInstance.InstanceId, TrackingWorkflowEvent.Terminated);

                    // Execute the SuspendedWorkflow Workflow
                    WriteTitle("Executing the suspended workflow");
                    WorkflowInstance suspendedWorkflowInstance = workflowRuntime.CreateWorkflow(typeof(SuspendedWorkflow));
                    suspendedWorkflowInstance.Start();
                    waitHandle.WaitOne();
                    QueryAndWriteTrackingInformationToConsole(suspendedWorkflowInstance.InstanceId, TrackingWorkflowEvent.Suspended);

                    // Stop Runtime
                    workflowRuntime.StopRuntime();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Encountered an exception. Exception Source: {0}, Exception Message: {1} ", e.Source, e.Message);
                }
                finally
                {
                    workflowRuntime.StopRuntime();
                }
            }
        }
Esempio n. 9
0
        static void Main()
        {
            try
            {
                waitHandle = new AutoResetEvent(false);
                version    = GetTrackingProfileVersion(new Version("3.0.0.0"));
                CreateAndInsertTrackingProfile();
                using (WorkflowRuntime runtime = new WorkflowRuntime())
                {
                    SqlTrackingService trackingService = new SqlTrackingService(connectionString);
                    runtime.AddService(trackingService);
                    runtime.StartRuntime();
                    runtime.WorkflowCompleted  += OnWorkflowCompleted;
                    runtime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                    {
                        Console.WriteLine(e.Exception.Message);
                        waitHandle.Set();
                    };

                    WorkflowInstance instance = runtime.CreateWorkflow(typeof(SimpleWorkflow));
                    instance.Start();
                    waitHandle.WaitOne();

                    runtime.StopRuntime();
                    OutputWorkflowTrackingEvents(instance.InstanceId);
                    OutputActivityTrackingEvents(instance.InstanceId);
                    Console.WriteLine("\nDone running the workflow.");
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);
                }
                else
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Esempio n. 10
0
        static void Main()
        {
            try
            {
                waitHandle = new AutoResetEvent(false);
                version = GetTrackingProfileVersion(new Version("3.0.0.0"));
                CreateAndInsertTrackingProfile();
                using (WorkflowRuntime runtime = new WorkflowRuntime())
                {
                    SqlTrackingService trackingService = new SqlTrackingService(connectionString);
                    runtime.AddService(trackingService);
                    runtime.StartRuntime();
                    runtime.WorkflowCompleted += OnWorkflowCompleted;
                    runtime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                    {
                        Console.WriteLine(e.Exception.Message);
                        waitHandle.Set();
                    };

                    WorkflowInstance instance = runtime.CreateWorkflow(typeof(SimpleWorkflow));
                    instance.Start();
                    waitHandle.WaitOne();

                    runtime.StopRuntime();
                    OutputWorkflowTrackingEvents(instance.InstanceId);
                    OutputActivityTrackingEvents(instance.InstanceId);
                    Console.WriteLine("\nDone running the workflow.");
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                    Console.WriteLine(ex.InnerException.Message);
                else
                    Console.WriteLine(ex.Message);
            }
        }
        private ReadOnlyCollection<string> GetStateHistory()
        {
            if (_sqlTrackingService == null)
            {
                _sqlTrackingService = _runtime.GetService<SqlTrackingService>();
                if (_sqlTrackingService == null)
                    throw new InvalidOperationException(SR.GetSqlTrackingServiceRequired());
            }

            if (_sqlTrackingQuery == null)
                _sqlTrackingQuery = new SqlTrackingQuery(_sqlTrackingService.ConnectionString);

            StateMachineWorkflowActivity stateMachineWorkflow;
            Stack<string> stateHistory = new Stack<string>();

            try
            {
                stateMachineWorkflow = this.StateMachineWorkflow;
            }
            catch (InvalidOperationException)
            {
                return new ReadOnlyCollection<string>(stateHistory.ToArray());
            }

            if (_sqlTrackingWorkflowInstance == null)
            {
                bool result = _sqlTrackingQuery.TryGetWorkflow(_instanceId, out _sqlTrackingWorkflowInstance);
                if (!result)
                {
                    // Workflow has not started yet, so we just return an
                    // empty collection
                    return new ReadOnlyCollection<string>(stateHistory.ToArray());
                }
            }

            _sqlTrackingWorkflowInstance.Refresh();
            IList<UserTrackingRecord> events = _sqlTrackingWorkflowInstance.UserEvents;
            foreach (UserTrackingRecord record in events)
            {
                if (record.UserDataKey != StateActivity.StateChangeTrackingDataKey)
                    continue;

                string stateQualifiedName = record.UserData as string;
                if (stateQualifiedName == null)
                    throw new InvalidOperationException(SR.GetInvalidUserDataInStateChangeTrackingRecord());

                StateActivity state = StateMachineHelpers.FindStateByName(stateMachineWorkflow, record.QualifiedName);
                if (state == null)
                    throw new InvalidOperationException(SR.GetInvalidUserDataInStateChangeTrackingRecord());

                if (StateMachineHelpers.IsLeafState(state))
                    stateHistory.Push(stateQualifiedName);
            }

            ReadOnlyCollection<string> history = new ReadOnlyCollection<string>(stateHistory.ToArray());
            return history;
        }
Esempio n. 12
0
        static void Main()
        {
            try
            {
                waitHandle = new AutoResetEvent(false);

                DataAccess.CreateAndInsertTrackingProfile();
                using (WorkflowRuntime runtime = new WorkflowRuntime())
                {
                    SqlTrackingService trackingService = new SqlTrackingService(DataAccess.connectionString);

                    /*
                     *  Set partitioning settings on Sql Tracking Service and database
                     */

                    //Turn on PartitionOnCompletion setting-- Default is false
                    trackingService.PartitionOnCompletion = true;

                    //Set partition interval-- Default is 'm' (monthly)
                    DataAccess.SetPartitionInterval('d');

                    runtime.AddService(trackingService);
                    runtime.StartRuntime();

                    runtime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
                    {
                        waitHandle.Set();
                    };

                    runtime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                    {
                        Console.WriteLine(e.Exception.Message);
                        waitHandle.Set();
                    };

                    WorkflowInstance instance = runtime.CreateWorkflow(typeof(SimpleWorkflow));
                    instance.Start();
                    waitHandle.WaitOne();

                    runtime.StopRuntime();
                    DataAccess.GetWorkflowTrackingEvents(instance.InstanceId);
                    Console.WriteLine("\nDone running the workflow.");

                    /*
                     *  Show tracking partition information and tables
                     */

                    DataAccess.ShowTrackingPartitionInformation();
                    DataAccess.ShowPartitionTableInformation();
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);
                }
                else
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
        private ReadOnlyCollection <string> GetStateHistory()
        {
            if (_sqlTrackingService == null)
            {
                _sqlTrackingService = _runtime.GetService <SqlTrackingService>();
                if (_sqlTrackingService == null)
                {
                    throw new InvalidOperationException(SR.GetSqlTrackingServiceRequired());
                }
            }

            if (_sqlTrackingQuery == null)
            {
                _sqlTrackingQuery = new SqlTrackingQuery(_sqlTrackingService.ConnectionString);
            }

            StateMachineWorkflowActivity stateMachineWorkflow;
            Stack <string> stateHistory = new Stack <string>();

            try
            {
                stateMachineWorkflow = this.StateMachineWorkflow;
            }
            catch (InvalidOperationException)
            {
                return(new ReadOnlyCollection <string>(stateHistory.ToArray()));
            }

            if (_sqlTrackingWorkflowInstance == null)
            {
                bool result = _sqlTrackingQuery.TryGetWorkflow(_instanceId, out _sqlTrackingWorkflowInstance);
                if (!result)
                {
                    // Workflow has not started yet, so we just return an
                    // empty collection
                    return(new ReadOnlyCollection <string>(stateHistory.ToArray()));
                }
            }

            _sqlTrackingWorkflowInstance.Refresh();
            IList <UserTrackingRecord> events = _sqlTrackingWorkflowInstance.UserEvents;

            foreach (UserTrackingRecord record in events)
            {
                if (record.UserDataKey != StateActivity.StateChangeTrackingDataKey)
                {
                    continue;
                }

                string stateQualifiedName = record.UserData as string;
                if (stateQualifiedName == null)
                {
                    throw new InvalidOperationException(SR.GetInvalidUserDataInStateChangeTrackingRecord());
                }

                StateActivity state = StateMachineHelpers.FindStateByName(stateMachineWorkflow, record.QualifiedName);
                if (state == null)
                {
                    throw new InvalidOperationException(SR.GetInvalidUserDataInStateChangeTrackingRecord());
                }

                if (StateMachineHelpers.IsLeafState(state))
                {
                    stateHistory.Push(stateQualifiedName);
                }
            }

            ReadOnlyCollection <string> history = new ReadOnlyCollection <string>(stateHistory.ToArray());

            return(history);
        }
Esempio n. 14
0
        static void Main(string[] args)
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { waitHandle.Set(); };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                {
                    Console.WriteLine(e.Exception.Message);
                    waitHandle.Set();
                };

                // Add Persistence and Tracking
                SqlWorkflowPersistenceService persistenceService;
                persistenceService = new SqlWorkflowPersistenceService(
                            ConfigurationManager.
                            ConnectionStrings["PersistentDataStore"].
                            ConnectionString, true, TimeSpan.MaxValue, TimeSpan.MinValue);
                workflowRuntime.AddService(persistenceService);

                SqlTrackingService trackingService;
                trackingService = new SqlTrackingService(
                            ConfigurationManager.
                            ConnectionStrings["PersistentDataStore"].
                            ConnectionString);
                trackingService.UseDefaultProfile = true;
                workflowRuntime.AddService(trackingService);

                // Set up the data exchange
                ExternalDataExchangeService dataExchange;
                dataExchange = new ExternalDataExchangeService();
                workflowRuntime.AddService(dataExchange);

                // Instatiate the local communication service
                CustomerCallService customerCallService = new CustomerCallService();
                dataExchange.AddService(customerCallService);

                // Create a new workflow instance
                WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(CustomerService));
                instance.Start();

                // Create a new Call
                Call newCall = new Call();
                newCall.CallersFirstName = "Alex";
                newCall.Product = "Widget Number Nine";

                // Change the state using the service and events
                customerCallService.ReceiveCall(instance.InstanceId, newCall);
                customerCallService.SendCallToPhoneResolution(instance.InstanceId, newCall);
                customerCallService.AssignCallToSupportPerson(instance.InstanceId, newCall);

                //Get a look at where we have wound up
                PrintStateMachineState(workflowRuntime, instance.InstanceId);

                // Change the state one last time
                customerCallService.ResolveCall(instance.InstanceId, newCall);

                // Print the history of our instance
                PrintHistory(workflowRuntime, instance.InstanceId);

                waitHandle.WaitOne();

                // Keep the console open until key strokes are entered so that you can see what we did...
                Console.ReadLine();
            }
        }
 private ReadOnlyCollection<string> GetStateHistory()
 {
     StateMachineWorkflowActivity stateMachineWorkflow;
     if (this._sqlTrackingService == null)
     {
         this._sqlTrackingService = this._runtime.GetService<SqlTrackingService>();
         if (this._sqlTrackingService == null)
         {
             throw new InvalidOperationException(SR.GetSqlTrackingServiceRequired());
         }
     }
     if (this._sqlTrackingQuery == null)
     {
         this._sqlTrackingQuery = new SqlTrackingQuery(this._sqlTrackingService.ConnectionString);
     }
     Stack<string> stack = new Stack<string>();
     try
     {
         stateMachineWorkflow = this.StateMachineWorkflow;
     }
     catch (InvalidOperationException)
     {
         return new ReadOnlyCollection<string>(stack.ToArray());
     }
     if ((this._sqlTrackingWorkflowInstance != null) || this._sqlTrackingQuery.TryGetWorkflow(this._instanceId, out this._sqlTrackingWorkflowInstance))
     {
         this._sqlTrackingWorkflowInstance.Refresh();
         foreach (UserTrackingRecord record in this._sqlTrackingWorkflowInstance.UserEvents)
         {
             if (record.UserDataKey == "StateActivity.StateChange")
             {
                 string userData = record.UserData as string;
                 if (userData == null)
                 {
                     throw new InvalidOperationException(SR.GetInvalidUserDataInStateChangeTrackingRecord());
                 }
                 StateActivity state = StateMachineHelpers.FindStateByName(stateMachineWorkflow, record.QualifiedName);
                 if (state == null)
                 {
                     throw new InvalidOperationException(SR.GetInvalidUserDataInStateChangeTrackingRecord());
                 }
                 if (StateMachineHelpers.IsLeafState(state))
                 {
                     stack.Push(userData);
                 }
             }
         }
     }
     return new ReadOnlyCollection<string>(stack.ToArray());
 }