protected override void DoTest()
        {
            BackgroundEventThreads.ShowFormOnBackgroundThread(
                () => new BackgroundEventThreadsTestForm());
            var testForm = WaitForOpenForm <BackgroundEventThreadsTestForm>();

            testForm.BeginInvoke(new Action(testForm.Close));
            WaitForClosedForm <BackgroundEventThreadsTestForm>();

            Assert.AreEqual(0, Program.TestExceptions.Count);
            BackgroundEventThreads.ShowFormOnBackgroundThread(() =>
            {
                var form            = new BackgroundEventThreadsTestForm();
                form.HandleCreated += (sender, args) => throw new TestException();
                return(form);
            });
            WaitForCondition(10000, () => Program.TestExceptions.Any(),
                             "Waiting for exception to be thrown", true, false);
            Assert.AreEqual(1, Program.TestExceptions.Count);
            Assert.IsInstanceOfType(Program.TestExceptions.First(), typeof(TestException));
            Program.TestExceptions.Clear();
            testForm = WaitForOpenForm <BackgroundEventThreadsTestForm>();
            Assert.IsNotNull(testForm);
            testForm.BeginInvoke(new Action(testForm.Close));
        }
        public void LibraryBuildCompleteCallback(LibraryManager.BuildState buildState, bool success)
        {
            // Completion needs to happen on a separate thread because of the access to UI elements
            // In order to make sure the thread handle is released, it needs to call Application.ThreadExit()
            var threadComplete = BackgroundEventThreads.CreateThreadForAction(() =>
            {
                if (success && NotificationContainerForm.IsHandleCreated)
                {
                    // Only one form showing at a time
                    lock (this)
                    {
                        RemoveLibraryBuildNotification();

                        var frm                   = new BuildLibraryNotification(buildState.LibrarySpec.Name);
                        frm.Activated            += notification_Activated;
                        frm.Shown                += notification_Shown;
                        frm.ExploreLibrary       += notification_ExploreLibrary;
                        frm.NotificationComplete += notification_NotificationComplete;
                        Point anchor              = NotificationAnchor;
                        frm.Left                  = anchor.X;
                        frm.Top                   = anchor.Y - frm.Height;
                        NotificationContainerForm.BeginInvoke(new Action(() =>
                        {
                            if (!string.IsNullOrEmpty(buildState.ExtraMessage))
                            {
                                MessageDlg.Show(TopMostApplicationForm, buildState.ExtraMessage);
                            }
                            if (buildState.IrtStandard != null && !buildState.IrtStandard.Name.Equals(IrtStandard.EMPTY.Name) && AddIrts(buildState))
                            {
                                AddRetentionTimePredictor(buildState);
                            }
                        }));
                        frm.Start();
                        Assume.IsNull(Interlocked.Exchange(ref _notification, frm));
                    }
                }
            });

            threadComplete.Name = @"Library Build Completion";
            threadComplete.Start();
        }
        public BuildLibraryNotification(String libraryName)
        {
            InitializeComponent();

            // WINDOWS 10 UPDATE HACK: Because Windows 10 update version 1803 causes unparented non-ShowInTaskbar windows to leak GDI and User handles
            ShowInTaskbar = Program.FunctionalTest;

            _libraryName          = libraryName;
            LibraryNameLabel.Text = string.Format(Resources.BuildLibraryNotification_BuildLibraryNotification_Library__0__, _libraryName);

            var showParams = new FormAnimator.AnimationParams(
                FormAnimator.AnimationMethod.slide,
                FormAnimator.AnimationDirection.up,
                0);
            var hideParams = new FormAnimator.AnimationParams(
                FormAnimator.AnimationMethod.blend,
                FormAnimator.AnimationDirection.up,
                0);

            _animator = new FormAnimator(this, showParams, hideParams)
            {
                ShowParams = { Duration = ANIMATION_DURATION }
            };

            // Not sure why this is necessary, but sometimes the form doesn't
            // appear without it.
            Opacity = 1;

            _thread              = BackgroundEventThreads.CreateThreadForAction(Notify);
            _thread.Name         = @"BuildLibraryNotification";
            _thread.IsBackground = true;

            _windowCreatedEvent = new ManualResetEvent(false);
            HandleCreated      += Notification_HandleCreated;

            _displayTimer          = new Timer();
            _displayTimer.Tick    += OnDisplayTimerEvent;
            _displayTimer.Interval = DISPLAY_DURATION;
        }
Exemple #4
0
        public void LibraryBuildCompleteCallback(IAsyncResult ar)
        {
            var  buildState = (LibraryManager.BuildState)ar.AsyncState;
            bool success    = buildState.BuildFunc.EndInvoke(ar);

            if (success)
            {
                lock (this)
                {
                    RemoveLibraryBuildNotification();

                    var frm = new BuildLibraryNotification(buildState.LibrarySpec.Name);
                    frm.Activated            += notification_Activated;
                    frm.Shown                += notification_Shown;
                    frm.ExploreLibrary       += notification_ExploreLibrary;
                    frm.NotificationComplete += notification_NotificationComplete;
                    Point anchor = NotificationAnchor;
                    frm.Left = anchor.X;
                    frm.Top  = anchor.Y - frm.Height;
                    NotificationContainerForm.BeginInvoke(new Action(() =>
                    {
                        if (!string.IsNullOrEmpty(buildState.ExtraMessage))
                        {
                            MessageDlg.Show(TopMostApplicationForm, buildState.ExtraMessage);
                        }
                        if (buildState.IrtStandard != null && buildState.IrtStandard != IrtStandard.NULL && AddIrts(buildState))
                        {
                            AddRetentionTimePredictor(buildState);
                        }
                    }));
                    var thread = BackgroundEventThreads.CreateThreadForAction(frm.Notify);
                    thread.Name         = "BuildLibraryNotification"; // Not L10N
                    thread.IsBackground = true;
                    thread.Start();
                    Notification = frm;
                }
            }
        }
Exemple #5
0
        public void LibraryBuildCompleteCallback(LibraryManager.BuildState buildState, bool success)
        {
            // Completion needs to happen on a separate thread because of the access to UI elements
            // In order to make sure the thread handle is released, it needs to call Application.ThreadExit()
            var threadComplete = BackgroundEventThreads.CreateThreadForAction(() =>
            {
                if (success && NotificationContainerForm.IsHandleCreated)
                {
                    // Only one form showing at a time
                    lock (this)
                    {
                        RemoveLibraryBuildNotification();

                        var frm                   = new BuildLibraryNotification(buildState.LibrarySpec.Name);
                        frm.Activated            += notification_Activated;
                        frm.Shown                += notification_Shown;
                        frm.ExploreLibrary       += notification_ExploreLibrary;
                        frm.NotificationComplete += notification_NotificationComplete;
                        Point anchor              = NotificationAnchor;
                        frm.Left                  = anchor.X;
                        frm.Top                   = anchor.Y - frm.Height;
                        NotificationContainerForm.BeginInvoke(new Action(() =>
                        {
                            if (!string.IsNullOrEmpty(buildState.ExtraMessage))
                            {
                                MessageDlg.Show(TopMostApplicationForm, buildState.ExtraMessage);
                            }
                            if (buildState.IrtStandard != null && !buildState.IrtStandard.Name.Equals(IrtStandard.EMPTY.Name))
                            {
                                // Load library
                                Library lib = null;
                                using (var longWait = new LongWaitDlg {
                                    Text = Resources.LibraryBuildNotificationHandler_AddIrts_Loading_library
                                })
                                {
                                    var status = longWait.PerformWork(TopMostApplicationForm, 800, monitor =>
                                    {
                                        lib = NotificationContainer.LibraryManager.TryGetLibrary(buildState.LibrarySpec) ??
                                              NotificationContainer.LibraryManager.LoadLibrary(buildState.LibrarySpec, () => new DefaultFileLoadMonitor(monitor));
                                        foreach (var stream in lib.ReadStreams)
                                        {
                                            stream.CloseStream();
                                        }
                                    });
                                    if (status.IsCanceled)
                                    {
                                        lib = null;
                                    }
                                    if (status.IsError)
                                    {
                                        throw status.ErrorException;
                                    }
                                }
                                // Add iRTs to library
                                if (AddIrts(lib, buildState.LibrarySpec, buildState.IrtStandard, NotificationContainerForm, true))
                                {
                                    AddRetentionTimePredictor(buildState);
                                }
                            }
                        }));
                        frm.Start();
                        Assume.IsNull(Interlocked.Exchange(ref _notification, frm));
                    }
                }
            });

            threadComplete.Name = @"Library Build Completion";
            threadComplete.Start();
        }