public partial class MainWindow : Window
{
private WorkflowApplication _app;
public MainWindow()
{
InitializeComponent();
}
private void Grid_Loaded(object sender, RoutedEventArgs e)
{
Console.SetOut(new TextBoxTextWriter(txtConsole));
DesactiverBoutons();
}
private void DesactiverBoutons()
{
ActiverBouton(btnOral, false);
ActiverBouton(btnTechnique, false);
}
private void ActiverBouton(Button bouton, bool valeur)
{
bouton.Dispatcher.BeginInvoke(new Action(() => bouton.IsEnabled = valeur));
}
private void btnStart_Click(object sender, RoutedEventArgs e)
{
// démarre le workflow
btnStart.IsEnabled = false;
_app = new WorkflowApplication(new EmbaucheLibrary.EmbaucheWorkflow());
_app.Idle += new Action<WorkflowApplicationIdleEventArgs>(WorkflowVeille);
_app.Completed += new Action<WorkflowApplicationCompletedEventArgs>(WorflowTermine);
_app.Run();
}
private void WorkflowVeille(WorkflowApplicationIdleEventArgs args)
{
var signet = args.Bookmarks.FirstOrDefault();
if (signet == null)
return;
DesactiverBoutons();
switch (signet.BookmarkName)
{
case "signetTechnique" :
ActiverBouton(btnTechnique, true);
break;
case "signetOral":
ActiverBouton(btnOral, true);
break;
}
}
private void WorflowTermine(WorkflowApplicationCompletedEventArgs args)
{
DesactiverBoutons();
ActiverBouton(btnStart, true);
Console.WriteLine("Workflow terminé");
Console.WriteLine("--------------------------------------");
}
private void btnTechnique_Click(object sender, RoutedEventArgs e)
{
txtConsole.AppendText(string.Format("La commission technique a donné une note de {0}\n",cbEval.SelectedIndex + 1));
_app.ResumeBookmark("signetTechnique", cbEval.SelectedIndex + 1);
}
private void btnOral_Click(object sender, RoutedEventArgs e)
{
txtConsole.AppendText(string.Format("La commission orale a donné une note de {0}\n", cbEval.SelectedIndex + 1));
_app.ResumeBookmark("signetOral", cbEval.SelectedIndex + 1);
}
}