private void NewGame_Click(object sender, EventArgs e)
        {
            var inputs = new Dictionary <string, object>();

            inputs.Add("MaxNumber", Convert.ToInt32(NumberRange.SelectedItem));

            WorkflowIdentity identity = null;

            switch (WorkflowType.SelectedItem.ToString())
            {
            case "SequentialNumberGuessWorkflow":
                identity = WorkflowVersionMap.SequentialNumberGuessIdentity;
                break;

            case "StateMachineNumberGuessWorkflow":
                identity = WorkflowVersionMap.StateMachineNumberGuessIdentity;
                break;

            case "FlowchartNumberGuessWorkflow":
                identity = WorkflowVersionMap.FlowchartNumberGuessIdentity;
                break;
            }
            ;

            Activity wf = WorkflowVersionMap.GetWorkflowDefinition(identity);

            WorkflowApplication wfApp = new WorkflowApplication(wf, inputs, identity);

            // Add the workflow to the list and display the version information.
            WorkflowStarting         = true;
            InstanceId.SelectedIndex = InstanceId.Items.Add(wfApp.Id);
            WorkflowVersion.Text     = identity.ToString();
            WorkflowStarting         = false;

            // Updates the status with the events results
            // Configure the instance store, extensions, and
            // workflow lifecycle handlers.
            _workflowApplication.ConfigureWorkflowApplication(wfApp);
        }
        private void EnterGuess_Click(object sender, EventArgs e)
        {
            if (WorkflowInstanceId == Guid.Empty)
            {
                MessageBox.Show("Please select a workflow.");
                return;
            }
            int guess;

            if (!Int32.TryParse(Guess.Text, out guess))
            {
                MessageBox.Show("Please enter an integer.");
                Guess.SelectAll();
                Guess.Focus();
                return;
            }

            var instance = _workflowApplication.GetInstance(this.WorkflowInstanceId);


            // Use the persisted WorkflowIdentity to retrieve the correct workflow
            // definition from the dictionary.
            Activity wf = WorkflowVersionMap.GetWorkflowDefinition(instance.DefinitionIdentity);

            // Associate the WorkflowApplication with the correct definition
            WorkflowApplication wfApp = new WorkflowApplication(wf, instance.DefinitionIdentity);

            // Configure the extensions and lifecycle handlers.
            // Do this before the instance is loaded. Once the instance is
            // loaded it is too late to add extensions.

            // Configure the instance store, extensions, and
            // workflow lifecycle handlers.
            var events = _workflowApplication.ConfigureWorkflowApplication(wfApp);

            // Load the workflow.
            //wfApp.Load(instance);

            // Create game Id
            GameId = Guid.NewGuid();

            var game = new Game()
            {
                Id = GameId, InstanceId = WorkflowInstanceId, Guess = guess, WorkflowType = WorkflowType.SelectedItem.ToString(), MaxNumber = Convert.ToInt32(NumberRange.SelectedItem)
            };

            // Resume the workflow.
            wfApp.ResumeBookmark("Game", game);

            // Clear the Guess textbox.
            Guess.Clear();
            Guess.Focus();

            Game display = null;

            while (display == null)
            {
                display = RetrieveData();
            }

            UpdateStatus(string.Format("Lets see how well you did: \r\n\r\nGuess = {0}\r\n MaxNumber = {1}\r\nResult = {2}\r\nTurns = {3}\r\nWorkflowType = {4}", display.Guess, display.MaxNumber, display.Result, display.Turns, display.WorkflowType));
        }