using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Activities;
using FlowChartSample;

namespace WpfClient
{
    /// <summary>
    /// MainWindow.xaml 的互動邏輯
    /// </summary>
    public partial class MainWindow : Window
    {
        WorkflowApplication wfInstance;

        public MainWindow()
        {
            InitializeComponent();

            //wfInstance = new WorkflowApplication(new Workflow1());
            //wfInstance.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
            //{
            //    MessageBox.Show("YA!");
            //};
            //wfInstance.Run();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
           //wfInstance.ResumeBookmark("Input.Username", textBox1.Text);
            if (wfInstance == null) {
                wfInstance = new WorkflowApplication(new ProcessInputData());
                wfInstance.Completed = delegate(WorkflowApplicationCompletedEventArgs args)
                {

                    Dispatcher.BeginInvoke(new Action<int>(UpdateUI),args.Outputs["Result"]);

                    wfInstance = null;
                };
                wfInstance.Run();
            }

            Button btn = sender as Button;
            string data = btn.Tag as string;
            wfInstance.ResumeBookmark("Input.Data", data);

            
            
        }

        private void UpdateUI(int result) {
            textBox1.Text = result.ToString();
        }
    }
}
