Пример #1
0
        public ProjectController(IProjectTreeModel projectTreeModel, IEventAggregator eventAggregator, IFileSystem fileSystem,
                                 IFileWatcher fileWatcher, IUnhandledExceptionPolicy unhandledExceptionPolicy, ITestProjectManager testProjectManager)
        {
            this.projectTreeModel         = projectTreeModel;
            this.eventAggregator          = eventAggregator;
            this.fileSystem               = fileSystem;
            this.fileWatcher              = fileWatcher;
            this.unhandledExceptionPolicy = unhandledExceptionPolicy;
            this.testProjectManager       = testProjectManager;

            TestFilters = new Observable <IList <FilterInfo> >(new List <FilterInfo>());
            TestFilters.PropertyChanged += (s, e) =>
            {
                if (updating)
                {
                    return;
                }

                projectTreeModel.TestProject.ClearTestFilters();
                GenericCollectionUtils.ForEach(TestFilters.Value, x =>
                                               projectTreeModel.TestProject.AddTestFilter(x));
            };

            fileWatcher.FileChangedEvent += delegate(string fullPath)
            {
                string fileName = Path.GetFileName(fullPath);
                EventHandlerPolicy.SafeInvoke(FileChanged, this, new FileChangedEventArgs(fileName));
            };
        }
Пример #2
0
        private void Update()
        {
            // Do this work in the background to avoid a possible deadlock acquiring the report lock
            // on the UI thread.
            taskManager.ClearQueue(QueueId);
            taskManager.QueueTask(QueueId, new DelegateCommand((pm => testController.ReadReport(report =>
            {
                TestModelData = report.TestModel;

                var testStepRuns = new List <TestStepRun>();

                if (report.TestPackageRun != null)
                {
                    foreach (var testStepRun in report.TestPackageRun.AllTestStepRuns)
                    {
                        if (RelevantStep(testStepRun))
                        {
                            testStepRuns.Add(testStepRun);
                        }
                    }
                }

                EventHandlerPolicy.SafeInvoke(ExecutionLogUpdated, this,
                                              new ExecutionLogUpdatedEventArgs(testStepRuns));
            }))));
        }
Пример #3
0
        public ProgressController(ITaskManager taskManager, IOptionsController optionsController)
        {
            this.taskManager = taskManager;

            timer.Interval = TimeSpan.FromSeconds(2).TotalMilliseconds;
            timer.Elapsed += (sender, e) =>
            {
                if (!optionsController.ShowProgressDialogs)
                {
                    return;
                }

                // HACK: we don't want to display the progress dialog when running tests
                // but relying on the task name is not ideal
                if (ProgressMonitor.TaskName == Resources.RunTestsCommand_Running_tests)
                {
                    return;
                }

                EventHandlerPolicy.SafeInvoke(DisplayProgressDialog, this,
                                              new ProgressEvent(ProgressMonitor));
            };

            Status        = new Observable <string>();
            TotalWork     = new Observable <double>();
            CompletedWork = new Observable <double>();
        }
Пример #4
0
        /// <summary>
        /// Sets the runtime instance.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method should only be used by applications that host Gallio
        /// and not generally by client code.
        /// </para>
        /// </remarks>
        /// <param name="runtime">The runtime instance, or null if none.</param>
        public static void SetRuntime(IRuntime runtime)
        {
            EventHandler instanceChangedHandlers = InstanceChanged;

            instance = runtime;

            EventHandlerPolicy.SafeInvoke(instanceChangedHandlers, null, EventArgs.Empty);
        }
Пример #5
0
        /// <inheritdoc />
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                EventHandlerPolicy.SafeInvoke(Disposed, this, EventArgs.Empty);
            }

            base.Dispose(disposing);
        }
Пример #6
0
        private void LogErrorData(object sender, DataReceivedEventArgs e)
        {
            if (captureConsoleError && e.Data != null)
            {
                consoleErrorCaptureWriter.WriteLine(e.Data);
            }

            EventHandlerPolicy.SafeInvoke(ConsoleErrorDataReceived, this, e);
        }
Пример #7
0
        private void HandleTaskAborted(object sender, TaskEventArgs e)
        {
            EventHandler <TaskEventArgs> cachedChain;

            lock (this)
                cachedChain = aborted;

            EventHandlerPolicy.SafeInvoke(cachedChain, this, e);
        }
Пример #8
0
        /// <summary>
        /// Aborts the processing of the command.
        /// </summary>
        protected override void StopProcessing()
        {
            EventHandler handler;

            lock (this)
                handler = stopRequested;

            EventHandlerPolicy.SafeInvoke(handler, this, EventArgs.Empty);
        }
Пример #9
0
 private void NotifyFinishing(object sender, EventArgs e)
 {
     try
     {
         EventHandlerPolicy.SafeInvoke(finishingHandlers, this, EventArgs.Empty);
     }
     catch (Exception ex)
     {
         LogWriter.Failures.WriteException(ex, "An exception during Finishing event processing.");
     }
 }
Пример #10
0
        private void Notify(ref EventHandler <TaskEventArgs> chain)
        {
            EventHandler <TaskEventArgs> cachedChain;

            lock (this)
            {
                cachedChain = chain;
                chain       = Signal;
            }

            EventHandlerPolicy.SafeInvoke(cachedChain, this, new TaskEventArgs(this));
        }
Пример #11
0
        private void HandleTaskStarted(object sender, TaskEventArgs e)
        {
            EventHandler <TaskEventArgs> cachedChain;

            lock (this)
            {
                activeTasks.Add(e.Task);
                cachedChain = started;
            }

            EventHandlerPolicy.SafeInvoke(cachedChain, this, e);
        }
Пример #12
0
        public ProgressController(ITaskManager taskManager)
        {
            this.taskManager = taskManager;

            timer.Interval = TimeSpan.FromSeconds(2).TotalMilliseconds;
            timer.Elapsed += (sender, e) => EventHandlerPolicy.SafeInvoke(DisplayProgressDialog,
                                                                          this, new ProgressEvent(ProgressMonitor));

            Status        = new Observable <string>();
            TotalWork     = new Observable <double>();
            CompletedWork = new Observable <double>();
        }
Пример #13
0
            public void Dispatch(LogSeverity severity, string message, ExceptionData exceptionData)
            {
                EventHandlerPolicy.SafeInvoke(LogMessage, this, new LogEntrySubmittedEventArgs(severity, message, exceptionData));

                foreach (ILogger logger in Listeners)
                {
                    try
                    {
                        logger.Log(severity, message, exceptionData);
                    }
                    catch (Exception ex)
                    {
                        UnhandledExceptionPolicy.Report(
                            "An exception occurred while dispatching a message to a log listener.", ex);
                    }
                }
            }
Пример #14
0
        /// <summary>
        /// Sets the state of the host to disconnected and notifies clients.
        /// </summary>
        protected void NotifyDisconnected()
        {
            EventHandler cachedDisconnectedHandlers;

            lock (syncRoot)
            {
                if (hostService == null)
                {
                    return;
                }

                cachedDisconnectedHandlers = disconnectedHandlers;
                disconnectedHandlers       = null;
                hostService = null;
            }

            EventHandlerPolicy.SafeInvoke(cachedDisconnectedHandlers, this, EventArgs.Empty);
        }
Пример #15
0
        private void SetupParentDirectoryWatcher(string reportDirectory, string parentDirectory, string reportNameFormat)
        {
            var reportDirectoryWatcher = new FileSystemWatcher
            {
                NotifyFilter        = NotifyFilters.DirectoryName,
                Path                = parentDirectory,
                EnableRaisingEvents = true
            };

            reportDirectoryWatcher.Created += (s, e) =>
            {
                if (e.FullPath != reportDirectory)
                {
                    return;
                }

                EventHandlerPolicy.SafeInvoke(ReportDirectoryCreated, this, EventArgs.Empty);
                SetupDirectoryWatcher(reportDirectory, reportNameFormat);
            };

            reportDirectoryWatcher.Deleted += (s, e) =>
            {
                if (e.FullPath == reportDirectory)
                {
                    EventHandlerPolicy.SafeInvoke(ReportDirectoryDeleted, this, EventArgs.Empty);
                }
            };

            reportDirectoryWatcher.Renamed += (s, e) =>
            {
                if (e.OldFullPath == reportDirectory)
                {
                    EventHandlerPolicy.SafeInvoke(ReportDirectoryDeleted, this, EventArgs.Empty);
                }
                else if (e.FullPath == reportDirectory)
                {
                    EventHandlerPolicy.SafeInvoke(ReportDirectoryCreated, this, EventArgs.Empty);
                }
            };
        }
Пример #16
0
        private void Abort(TestOutcome outcome, string message, bool throwIfDisposed)
        {
            EventHandler cachedHandler;

            ThreadAbortScope[] cachedScopes;
            lock (syncRoot)
            {
                if (throwIfDisposed)
                {
                    ThrowIfDisposed();
                }

                if (abortOutcome.HasValue)
                {
                    return;
                }

                abortOutcome = outcome;
                abortMessage = message;

                cachedScopes = scopesAndThreads != null
                    ? GenericCollectionUtils.ConvertAllToArray(scopesAndThreads, pair => pair.First)
                    : null;

                scopesAndThreads = null;

                cachedHandler = aborted;
                aborted       = null;
            }

            if (cachedScopes != null)
            {
                foreach (ThreadAbortScope scope in cachedScopes)
                {
                    scope.Abort();
                }
            }

            EventHandlerPolicy.SafeInvoke(cachedHandler, this, EventArgs.Empty);
        }
        /// <summary>
        /// Notifies that the task has actually been canceled.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If this is the first time <see cref="NotifyCanceled" /> has been called,
        /// sets <see cref="IsCanceled" /> to true and fires the <see cref="Canceled" /> event.
        /// Otherwise does nothing.
        /// </para>
        /// <para>
        /// This is the ONLY method of the progress monitor that is allowed to
        /// be called concurrently from multiple threads.  It needs to be this
        /// way so that cancelation can be initiated by either participant in the
        /// progress monitoring dialog.
        /// </para>
        /// </remarks>
        /// <returns>True if cancelation has just occurred, false if no
        /// state change was performed.</returns>
        protected bool NotifyCanceled()
        {
            EventHandler currentCanceledHandler;

            lock (this)
            {
                if (isCanceled)
                {
                    return(false);
                }

                isCanceled             = true;
                currentCanceledHandler = canceledHandler;

                // We will never call these handlers again so there's no point
                // keeping them around anymore.
                canceledHandler = null;
            }

            EventHandlerPolicy.SafeInvoke(currentCanceledHandler, this, EventArgs.Empty);
            return(true);
        }
Пример #18
0
        private void SetupDirectoryWatcher(string reportDirectory, string reportNameFormat)
        {
            var regex = new Regex("{.}");

            reportNameFormat = regex.Replace(reportNameFormat, "*") + "*.xml";

            var reportDirectoryWatcher = new FileSystemWatcher
            {
                Filter              = reportNameFormat,
                NotifyFilter        = NotifyFilters.FileName,
                Path                = reportDirectory,
                EnableRaisingEvents = true
            };

            reportDirectoryWatcher.Created += (s, e) => EventHandlerPolicy.SafeInvoke(ReportCreated,
                                                                                      this, new ReportCreatedEventArgs(e.FullPath));

            reportDirectoryWatcher.Deleted += (s, e) => EventHandlerPolicy.SafeInvoke(ReportDeleted,
                                                                                      this, new ReportDeletedEventArgs(e.FullPath));

            reportDirectoryWatcher.Renamed += (s, e) =>
            {
                // if the new filename is a valid report format, then rename the node
                if (new Regex(reportNameFormat.Replace("*", ".*")).Match(e.FullPath).Success)
                {
                    EventHandlerPolicy.SafeInvoke(ReportRenamed, this,
                                                  new ReportRenamedEventArgs(e.OldFullPath, e.FullPath));
                }
                else
                {
                    // otherwise delete it
                    EventHandlerPolicy.SafeInvoke(ReportDeleted, this,
                                                  new ReportDeletedEventArgs(e.OldFullPath));
                }
            };
        }
Пример #19
0
        private void HandleTaskTerminated(object sender, TaskEventArgs e)
        {
            try
            {
                EventHandler <TaskEventArgs> cachedChain;
                lock (this)
                {
                    cachedChain = terminated;
                }

                EventHandlerPolicy.SafeInvoke(cachedChain, this, e);
            }
            finally
            {
                // Do this last to ensure that all event handlers have executed
                // before we remove the task from the list.  This helps to ensure
                // that JoinAll fully synchronizes with the task and with any
                // final event-based processing that needs to occur.
                lock (this)
                {
                    activeTasks.Remove(e.Task);
                }
            }
        }
 public void Handle(ExploreFinished @event)
 {
     EventHandlerPolicy.SafeInvoke(RestoreState, this,
                                   EventArgs.Empty);
     testExplorerModel.CanEditTree.Value = true;
 }
Пример #21
0
 public void ViewSourceCode(CodeLocation codeLocation)
 {
     // fire event for view
     EventHandlerPolicy.SafeInvoke(ShowSourceCode, this,
                                   new ShowSourceCodeEventArgs(codeLocation));
 }
Пример #22
0
 /// <summary>
 /// Dispatches the <see cref="TestStepLogStreamEmbed" /> event.
 /// </summary>
 /// <param name="e">The event arguments.</param>
 public void NotifyTestStepLogStreamEmbed(TestStepLogStreamEmbedEventArgs e)
 {
     EventHandlerPolicy.SafeInvoke(TestStepLogStreamEmbed, this, e);
 }
Пример #23
0
 /// <summary>
 /// Dispatches the <see cref="TestStepLogStreamEndBlock" /> event.
 /// </summary>
 /// <param name="e">The event arguments.</param>
 public void NotifyTestStepLogStreamEndBlock(TestStepLogStreamEndBlockEventArgs e)
 {
     EventHandlerPolicy.SafeInvoke(TestStepLogStreamEndBlock, this, e);
 }
Пример #24
0
        private TestResult FinishStep(TestOutcome outcome, TimeSpan?actualDuration, bool isDisposing)
        {
            EventHandler cachedFinishingHandlers;

            lock (syncRoot)
            {
                if (!IsRunning)
                {
                    if (isDisposing)
                    {
                        return(result ?? new TestResult(TestOutcome.Error));
                    }
                    throw new InvalidOperationException("Cannot finish a step unless the test step is running.");
                }

                this.outcome    = outcome;
                executionStatus = StatusFinishing;
                LifecyclePhase  = LifecyclePhases.Finishing;

                cachedFinishingHandlers = finishingHandlers;
                finishingHandlers       = null;
            }

            // Note: We no longer need to hold the lock because none of the state used from here on can change
            //       since the status is now StatusFinishing.
            try
            {
                if (parent != null)
                {
                    parent.Finishing -= HandleParentFinishedBeforeThisContext;
                }

                using (Enter())
                    EventHandlerPolicy.SafeInvoke(cachedFinishingHandlers, this, EventArgs.Empty);

                if (isDisposing)
                {
                    logWriter.Failures.Write("The test step was orphaned by the test runner!\n");
                }

                logWriter.Close();

                result = new TestResult(outcome)
                {
                    AssertCount = assertCount,
                    Duration    = actualDuration.GetValueOrDefault(stopwatch.Elapsed)
                };

                MessageSink.Publish(new TestStepFinishedMessage()
                {
                    StepId = testStep.Id,
                    Result = result
                });

                if (contextCookie != null)
                {
                    if (!isDisposing)
                    {
                        contextCookie.Dispose();
                    }
                    contextCookie = null;
                }

                return(result);
            }
            catch (Exception ex)
            {
                UnhandledExceptionPolicy.Report("An unhandled exception occurred while finishing a test step.", ex);
                return(new TestResult(TestOutcome.Error));
            }
            finally
            {
                lock (syncRoot)
                    executionStatus = StatusFinished;
            }
        }
Пример #25
0
 /// <summary>
 /// Called when a new progress monitor is created.
 /// </summary>
 protected virtual void OnSubProgressMonitorCreated(ObservableProgressMonitor subProgressMonitor)
 {
     EventHandlerPolicy.SafeInvoke(SubProgressMonitorCreated, this, new SubProgressMonitorCreatedEventArgs(subProgressMonitor));
 }
Пример #26
0
 /// <summary>
 /// Called when a state change occurs.
 /// </summary>
 protected virtual void OnChange()
 {
     EventHandlerPolicy.SafeInvoke(Changed, this, EventArgs.Empty);
 }
Пример #27
0
        /// <summary>
        /// Called when <see cref="Done" /> performs its updates.
        /// </summary>
        protected virtual void OnDone()
        {
            OnChange();

            EventHandlerPolicy.SafeInvoke(TaskFinished, this, EventArgs.Empty);
        }
Пример #28
0
        /// <summary>
        /// Called after <see cref="BeginTask" /> performs its updates.
        /// </summary>
        /// <param name="taskName">The task name.</param>
        /// <param name="totalWorkUnits">The total number of work units.</param>
        protected virtual void OnBeginTask(string taskName, double totalWorkUnits)
        {
            EventHandlerPolicy.SafeInvoke(TaskStarting, this, EventArgs.Empty);

            OnChange();
        }
Пример #29
0
 public void Handle(RunStarted @event)
 {
     TestModelData = null;
     EventHandlerPolicy.SafeInvoke(ExecutionLogReset,
                                   true, System.EventArgs.Empty);
 }
 private void TriggerStateSave()
 {
     EventHandlerPolicy.SafeInvoke(SaveState, this, EventArgs.Empty);
 }