//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
//----------------------------------------------------------------
using System;
using System.Windows;
using Microsoft.Win32;

namespace Microsoft.Samples.VisualWorkflowTracking
{
    /// <summary>
    /// Interaction logic for VisualWorkflowTrackingWindow.xaml
    /// </summary>
    public partial class VisualWorkflowTrackingWindow : Window
    {
        public VisualWorkflowTrackingWindow()
        {
            InitializeComponent();
        }

         //Event handler for Run Workflow Menu Item
        private void fileMenuOpenWorkflow_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                Filter = "Xaml files (*.xaml, *.xamlx)|*.xaml;*.xamlx",
                Multiselect = false,
                Title = "Open Workflow Definition"
            };
            Nullable<bool> fileSelected = openFileDialog.ShowDialog();
            if (fileSelected.HasValue && fileSelected.Value)
            {
                WFHost.WorkflowName = openFileDialog.FileName;
            }
        }

        //Event handler for Run Workflow Menu Item
        private void fileRunLoadedWorkflow_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                WFHost.StartTracking();
            }
            catch (Exception ex) 
            {
                System.Windows.MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void fileMenuExit_Click(object sender, RoutedEventArgs e)
        {
            App.Current.Shutdown();
        }
    }
}
