2014-04-04 05:04:53 -07:00
|
|
|
|
using Stylet;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2014-05-10 12:11:02 -07:00
|
|
|
|
using System.Windows;
|
2014-04-04 05:04:53 -07:00
|
|
|
|
|
|
|
|
|
namespace StyletIntegrationTests
|
|
|
|
|
{
|
|
|
|
|
public class ShellViewModel : Screen
|
|
|
|
|
{
|
2015-10-03 07:50:53 -07:00
|
|
|
|
private readonly IWindowManager windowManager;
|
|
|
|
|
|
2014-04-04 05:04:53 -07:00
|
|
|
|
public ShellViewModel(IWindowManager windowManager)
|
|
|
|
|
{
|
|
|
|
|
this.windowManager = windowManager;
|
|
|
|
|
|
|
|
|
|
this.DisplayName = "ShellViewModel";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-10-03 07:50:53 -07:00
|
|
|
|
|
2014-04-04 05:04:53 -07:00
|
|
|
|
private bool? _showDialogAndDialogResultDialogResult;
|
|
|
|
|
public bool? ShowDialogAndDialogResultDialogResult
|
|
|
|
|
{
|
|
|
|
|
get { return this._showDialogAndDialogResultDialogResult; }
|
|
|
|
|
set { SetAndNotify(ref this._showDialogAndDialogResultDialogResult, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowDialogAndDialogResult()
|
|
|
|
|
{
|
|
|
|
|
var dialog = new ShowDialogAndDialogResult.DialogViewModel();
|
|
|
|
|
this.ShowDialogAndDialogResultDialogResult = this.windowManager.ShowDialog(dialog);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowWindowLifecycle()
|
|
|
|
|
{
|
2014-05-21 03:32:51 -07:00
|
|
|
|
var window = new WindowLifecycle.WindowViewModel(this.windowManager);
|
2014-04-04 05:04:53 -07:00
|
|
|
|
this.windowManager.ShowWindow(window);
|
|
|
|
|
}
|
2014-04-09 04:35:59 -07:00
|
|
|
|
|
2014-05-10 12:11:02 -07:00
|
|
|
|
public void ThrowException()
|
2014-05-09 06:40:40 -07:00
|
|
|
|
{
|
2014-05-10 12:11:02 -07:00
|
|
|
|
throw new Exception("Hello");
|
2014-05-09 06:40:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-10 12:11:02 -07:00
|
|
|
|
public async void TestDispatcher()
|
2014-05-09 07:43:55 -07:00
|
|
|
|
{
|
2014-05-10 12:11:02 -07:00
|
|
|
|
var dispatcher = Execute.Dispatcher;
|
|
|
|
|
var log = new List<string>();
|
2014-05-09 07:43:55 -07:00
|
|
|
|
|
2014-05-10 12:11:02 -07:00
|
|
|
|
await Task.Run(() => dispatcher.Send(() => { lock(log) { log.Add("One"); }; }));
|
|
|
|
|
lock (log) { log.Add("Two"); };
|
|
|
|
|
|
|
|
|
|
await Task.Run(() => dispatcher.Post(() => { lock (log) { log.Add("Three"); }; }));
|
|
|
|
|
lock (log) { log.Add("Four"); };
|
|
|
|
|
|
|
|
|
|
// OK, so at this point there's a queued message saying to add Three to the log
|
|
|
|
|
// Give the main thread time to process that message
|
|
|
|
|
await Task.Delay(100);
|
|
|
|
|
|
|
|
|
|
if (log.SequenceEqual(new[] { "One", "Two", "Four", "Three" }))
|
2014-12-02 08:13:33 -08:00
|
|
|
|
this.windowManager.ShowMessageBox("Success", icon: MessageBoxImage.Information);
|
2014-05-10 12:11:02 -07:00
|
|
|
|
else
|
2014-05-21 03:32:51 -07:00
|
|
|
|
this.windowManager.ShowMessageBox("Failure");
|
2014-04-09 04:35:59 -07:00
|
|
|
|
}
|
2015-10-03 07:50:53 -07:00
|
|
|
|
|
2015-10-06 04:49:22 -07:00
|
|
|
|
public void ShowActionTargetSaved()
|
2015-10-03 07:50:53 -07:00
|
|
|
|
{
|
|
|
|
|
this.windowManager.ShowMessageBox("Success!");
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-04 05:04:53 -07:00
|
|
|
|
}
|