コード例 #1
0
 public TestWindow(ImageSource source, string title)
 {
     this.Closed  += OnClosed;
     EnableButtons = false;
     if (ImageSource is BitmapImage)
     {
         Const.Log("Creating Image Download Events");
         (ImageSource as BitmapImage).DownloadCompleted += OnDownloadCompleted;
         (ImageSource as BitmapImage).DownloadFailed    += OnDownloadFailed;
     }
     else
     {
         EnableButtons = true;
     }
     ImageSource = source;
     Const.Log("InitializingComponent");
     InitializeComponent();
     Title = title;
 }
コード例 #2
0
        public static bool RunTest(Test test)
        {
            Const.Log("Running {0}", test.GetType().Name);
            ImageSource source   = null;
            bool?       earlyRet = null;

            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                try
                {
                    Const.Log("Loading Image Source");
                    source = test.LoadImage();
                    Const.Log("Loaded Image Source");
                }
                catch (Exception e)
                {
                    test.Error = new Exception("Error loading image for test " + test.GetType().Name, e);
                    earlyRet   = false;
                }
            }));

            if (earlyRet != null)
            {
                return(earlyRet.Value);
            }
            TestWindow win = null;

            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                try
                {
                    Const.Log("Creating Window");
                    win = new TestWindow(source, test.GetType().Name);
                    Const.Log("Created Window");
                }
                catch (Exception e)
                {
                    test.Error = new Exception("Error initializing window for test " + test.GetType().Name, e);
                    earlyRet   = false;
                }
            }));
            if (earlyRet != null)
            {
                return(earlyRet.Value);
            }

            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                try
                {
                    Const.Log("Showing Window");
                    win.Show();
                    Const.Log("Window Shown");
                }
                catch (Exception e)
                {
                    test.Error = new Exception("Error showing window for test " + test.GetType().Name, e);
                    earlyRet   = false;
                }
            }));
            if (earlyRet != null)
            {
                return(earlyRet.Value);
            }

            Const.Log("Waiting for window to close...");
            while (!win.IsClosed)
            {
                Thread.Sleep(1);
            }
            Const.Log("Window closed Success={0}", win.Success);
            return(win.Success);
        }
コード例 #3
0
 private void OnDownloadCompleted(object sender, EventArgs eventArgs)
 {
     Const.Log("Image download complete");
     EnableButtons = true;
 }
コード例 #4
0
 private void OnDownloadFailed(object sender, ExceptionEventArgs exceptionEventArgs)
 {
     Const.Log("OnDownloadFailed");
     throw exceptionEventArgs.ErrorException;
 }