Esempio n. 1
0
        public void TestTaskQueuePreProcessing00()
        {
            var schedulerThread = new SampleSchedulerThread();
            var scheduler       = new DynamoScheduler(schedulerThread, TaskProcessMode.Asynchronous);

            // Start scheduling a bunch of tasks.
            var asyncTasks = new AsyncTask[]
            {
                new InconsequentialAsyncTask(scheduler, 500),
                new PrioritizedAsyncTask(scheduler, 3),
                new InconsequentialAsyncTask(scheduler, 100),
                new PrioritizedAsyncTask(scheduler, 5),
                new InconsequentialAsyncTask(scheduler, 300),
                new PrioritizedAsyncTask(scheduler, 1),
                new InconsequentialAsyncTask(scheduler, 200),
                new PrioritizedAsyncTask(scheduler, 6),
                new InconsequentialAsyncTask(scheduler, 700),
                new PrioritizedAsyncTask(scheduler, 2),
            };

            var results = new List <string>();

            foreach (SampleAsyncTask asyncTask in asyncTasks)
            {
                asyncTask.InitializeWithResultList(results);
                scheduler.ScheduleForExecution(asyncTask);
            }

            schedulerThread.GetSchedulerToProcessTasks();

            // Drops all InconsequentialAsyncTask and leave behind one.
            // Kept all PrioritizedAsyncTask instances and sorted them.
            Assert.AreEqual(6, results.Count);
            Assert.AreEqual("PrioritizedAsyncTask: 1", results[0]);
            Assert.AreEqual("PrioritizedAsyncTask: 2", results[1]);
            Assert.AreEqual("PrioritizedAsyncTask: 3", results[2]);
            Assert.AreEqual("PrioritizedAsyncTask: 5", results[3]);
            Assert.AreEqual("PrioritizedAsyncTask: 6", results[4]);
            Assert.AreEqual("InconsequentialAsyncTask: 700", results[5]);
        }
Esempio n. 2
0
        public void TestTaskStateChangedEventHandling()
        {
            var observer        = new TaskEventObserver();
            var schedulerThread = new SampleSchedulerThread();
            var scheduler       = new DynamoScheduler(schedulerThread, false);

            scheduler.TaskStateChanged += observer.OnTaskStateChanged;

            // Start scheduling a bunch of tasks.
            var asyncTasks = new AsyncTask[]
            {
                new ErrorProneAsyncTask(scheduler, 7),
                new InconsequentialAsyncTask(scheduler, 100),
                new PrioritizedAsyncTask(scheduler, 1),
                new PrioritizedAsyncTask(scheduler, 5),
                new ErrorProneAsyncTask(scheduler, 3),
                new InconsequentialAsyncTask(scheduler, 500),
                new InconsequentialAsyncTask(scheduler, 300),
                new PrioritizedAsyncTask(scheduler, 3),
                new ErrorProneAsyncTask(scheduler, 5),
            };

            foreach (SampleAsyncTask asyncTask in asyncTasks)
            {
                scheduler.ScheduleForExecution(asyncTask);
            }

            schedulerThread.GetSchedulerToProcessTasks();

            // Drops all InconsequentialAsyncTask and leave behind one.
            // Kept all PrioritizedAsyncTask instances and sorted them.
            var expected = new List <string>
            {
                // Scheduling notifications...

                "Scheduled: ErrorProneAsyncTask: 7",
                "Scheduled: InconsequentialAsyncTask: 100",
                "Scheduled: PrioritizedAsyncTask: 1",
                "Scheduled: PrioritizedAsyncTask: 5",
                "Scheduled: ErrorProneAsyncTask: 3",
                "Scheduled: InconsequentialAsyncTask: 500",
                "Scheduled: InconsequentialAsyncTask: 300",
                "Scheduled: PrioritizedAsyncTask: 3",
                "Scheduled: ErrorProneAsyncTask: 5",

                // Task discarded notifications...

                "Discarded: InconsequentialAsyncTask: 100",
                "Discarded: InconsequentialAsyncTask: 300",

                // Execution of remaining tasks...

                "ExecutionStarting: ErrorProneAsyncTask: 7",
                "ExecutionFailed: ErrorProneAsyncTask: 7",
                "CompletionHandled: ErrorProneAsyncTask: 7",

                "ExecutionStarting: PrioritizedAsyncTask: 1",
                "ExecutionCompleted: PrioritizedAsyncTask: 1",
                "CompletionHandled: PrioritizedAsyncTask: 1",

                "ExecutionStarting: PrioritizedAsyncTask: 5",
                "ExecutionCompleted: PrioritizedAsyncTask: 5",
                "CompletionHandled: PrioritizedAsyncTask: 5",

                "ExecutionStarting: ErrorProneAsyncTask: 3",
                "ExecutionFailed: ErrorProneAsyncTask: 3",
                "CompletionHandled: ErrorProneAsyncTask: 3",

                "ExecutionStarting: PrioritizedAsyncTask: 3",
                "ExecutionCompleted: PrioritizedAsyncTask: 3",
                "CompletionHandled: PrioritizedAsyncTask: 3",

                "ExecutionStarting: ErrorProneAsyncTask: 5",
                "ExecutionFailed: ErrorProneAsyncTask: 5",
                "CompletionHandled: ErrorProneAsyncTask: 5",

                // Execution of InconsequentialAsyncTask last...

                "ExecutionStarting: InconsequentialAsyncTask: 500",
                "ExecutionCompleted: InconsequentialAsyncTask: 500",
                "CompletionHandled: InconsequentialAsyncTask: 500"
            };

            Assert.AreEqual(expected.Count, observer.Results.Count());

            int index = 0;

            foreach (var actual in observer.Results)
            {
                Assert.AreEqual(expected[index++], actual);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// This method is typically called from the main application thread (as
        /// a result of user actions such as button click or node UI changes) to
        /// schedule an update of the graph. This call may or may not represent
        /// an actual update. In the event that the user action does not result
        /// in actual graph update (e.g. moving of node on UI), the update task
        /// will not be scheduled for execution.
        /// </summary>
        public void Run()
        {
            graphExecuted = true;

            // When Dynamo is shut down, the workspace is cleared, which results
            // in Modified() being called. But, we don't want to run when we are
            // shutting down so we check whether an engine controller is available.
            if (this.EngineController == null)
            {
                return;
            }

            var traceData = PreloadedTraceData;

            if ((traceData != null) && traceData.Any())
            {
                // If we do have preloaded trace data, set it here first.
                var setTraceDataTask = new SetTraceDataAsyncTask(scheduler);
                if (setTraceDataTask.Initialize(EngineController, this))
                {
                    scheduler.ScheduleForExecution(setTraceDataTask);
                }
            }

            // If one or more custom node have been updated, make sure they
            // are compiled first before the home workspace gets evaluated.
            //
            EngineController.ProcessPendingCustomNodeSyncData(scheduler);

            var task = new UpdateGraphAsyncTask(scheduler, verboseLogging);

            if (task.Initialize(EngineController, this))
            {
                task.Completed        += OnUpdateGraphCompleted;
                RunSettings.RunEnabled = false; // Disable 'Run' button.

                // Reset node states
                foreach (var node in Nodes)
                {
                    node.WasInvolvedInExecution = false;
                }

                // The workspace has been built for the first time
                silenceNodeModifications = false;

                // An event handler we can listen to on the NodeViewModel, to update the
                // node's informational state. This is required because Errors and Warnings
                // currently fire differently from one another.
                foreach (NodeModel nodeModel in task.ModifiedNodes)
                {
                    nodeModel.OnNodeMessagesClearing();
                }

                OnEvaluationStarted(EventArgs.Empty);
                scheduler.ScheduleForExecution(task);

                // Setting this to true as the task is scheduled now and will be
                // set back to false once the OnUpdateGraphCompleted event is executed.
                executingTask = true;
            }
            else
            {
                // Notify handlers that evaluation did not take place.
                var e = new EvaluationCompletedEventArgs(false);
                OnEvaluationCompleted(e);
            }
        }