Пример #1
0
        public void TestOnRequestDispatcherBeginInvoke()
        {
            //Arrange
            //We need to create an event and include an exception
            EvaluationCompletedEventArgs e = new EvaluationCompletedEventArgs(true, new Exception("Test"));

            //This will subcribe to the EvaluationCompleted event
            CurrentDynamoModel.EvaluationCompleted += CurrentDynamoModel_EvaluationCompleted;

            //Act
            //This will call the OnRequestDispatcherBeginInvoke method in the else section (no subscribers to the event)
            CurrentDynamoModel.OnEvaluationCompleted(this, e);

            //This will subscribe our local method to the RequestDispatcherBeginInvoke event
            DynCmd.RequestDispatcherBeginInvoke += DynamoModel_RequestDispatcherBeginInvoke;

            //This will call the OnRequestDispatcherBeginInvoke method when we have subscribers
            CurrentDynamoModel.OnEvaluationCompleted(this, e);

            //Assert
            DynCmd.RequestDispatcherBeginInvoke    -= DynamoModel_RequestDispatcherBeginInvoke;
            CurrentDynamoModel.EvaluationCompleted -= CurrentDynamoModel_EvaluationCompleted;
            //This will validate that the local handler was executed and set the flag in true
            Assert.IsTrue(dispatcherExecuted);
            Assert.IsTrue(evaluationCompleted);
        }
Пример #2
0
        void hwm_EvaluationCompleted(object sender, EvaluationCompletedEventArgs e)
        {
            bool hasWarnings = Model.Nodes.Any(n => n.State == ElementState.Warning);

            if (!hasWarnings)
            {
                if (Model.ScaleFactorChanged)
                {
                    SetCurrentWarning(NotificationLevel.Mild, Properties.Resources.RunCompletedWithScaleChangeMessage);
                }
                else
                {
                    SetCurrentWarning(NotificationLevel.Mild, Properties.Resources.RunCompletedMessage);
                }
            }
            else
            {
                if (Model.ScaleFactorChanged)
                {
                    SetCurrentWarning(NotificationLevel.Moderate, Properties.Resources.RunCompletedWithScaleChangeAndWarningsMessage);
                }
                else
                {
                    SetCurrentWarning(NotificationLevel.Moderate, Properties.Resources.RunCompletedWithWarningsMessage);
                }
            }
        }
Пример #3
0
 private void OnEvaluationCompleted(object sender, EvaluationCompletedEventArgs e)
 {
     if (this.IsEnabled)
     {
         this.dynamoSession.End();
     }
 }
Пример #4
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;

                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);
            }
        }
Пример #5
0
 /// <summary>
 /// Event handler for EvaluationCompleted event
 /// </summary>
 /// <param name="sender">sender</param>
 /// <param name="e">EvaluationCompletedEventArgs</param>
 void OnGraphEvaluationCompleted(object sender, EvaluationCompletedEventArgs e)
 {
     if (e.EvaluationSucceeded)
     {
         // Signal the signalEvent ready
         signalEvent.Set();
     }
 }
Пример #6
0
        public override void OnEvaluationCompleted(object sender, EvaluationCompletedEventArgs e)
        {
            //  Debug.WriteLine(ElementIDLifecycleManager<int>.GetInstance());



            base.OnEvaluationCompleted(sender, e);
        }
Пример #7
0
        public override void OnEvaluationCompleted(object sender, EvaluationCompletedEventArgs e)
        {
            Debug.WriteLine(ElementIDLifecycleManager <int> .GetInstance());

            // finally close the transaction!
            TransactionManager.Instance.ForceCloseTransaction();

            base.OnEvaluationCompleted(sender, e);
        }
Пример #8
0
        void hwm_EvaluationCompleted(object sender, EvaluationCompletedEventArgs e)
        {
            if (DynamoViewModel.UIDispatcher != null)
            {
                DynamoViewModel.UIDispatcher.BeginInvoke(new Action(() =>
                {
                    UpdateNodeInfoBubbleContent(e);
                }));
            }
            else
            {
                //just call it directly
                UpdateNodeInfoBubbleContent(e);
            }

            bool hasWarnings = Model.Nodes.Any(n => n.State == ElementState.Warning || n.State == ElementState.PersistentWarning);

            if (!hasWarnings)
            {
                if (Model.ScaleFactorChanged)
                {
                    SetCurrentWarning(NotificationLevel.Mild, Properties.Resources.RunCompletedWithScaleChangeMessage);
                }
                else
                {
                    SetCurrentWarning(NotificationLevel.Mild, Properties.Resources.RunCompletedMessage);
                }
            }
            else
            {
                if (Model.ScaleFactorChanged)
                {
                    SetCurrentWarning(NotificationLevel.Moderate, Properties.Resources.RunCompletedWithScaleChangeAndWarningsMessage);
                }
                else
                {
                    SetCurrentWarning(NotificationLevel.Moderate, Properties.Resources.RunCompletedWithWarningsMessage);
                }
            }

            void UpdateNodeInfoBubbleContent(EvaluationCompletedEventArgs evalargs)
            {
                if (e.MessageKeys == null)
                {
                    return;
                }
                foreach (var messageID in evalargs.MessageKeys)
                {
                    var node = this.Nodes.FirstOrDefault(n => n.Id == messageID);
                    if (node == null)
                    {
                        continue;
                    }
                    node.UpdateBubbleContent();
                }
            }
        }
Пример #9
0
        /// <summary>
        /// When the graph is evaluated .. ?
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnEvaulationCompleted(object sender, EvaluationCompletedEventArgs e)
        {
            // WORKS
            MessageBox.Show($"The current Graph name is {FileName}");

            var dataToExport = ExportData.Export(FileName, DynamoVersion);

            ExportSheets.Execute(dataToExport);
        }
Пример #10
0
        /// <summary>
        /// Triggers RefreshCompleted event
        /// </summary>
        /// <param name="e">The event data containing information
        /// if graph evaluation has completed successfully.</param>
        public virtual void OnRefreshCompleted(EvaluationCompletedEventArgs e)
        {
            var handler = RefreshCompleted;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Пример #11
0
        /// <summary>
        /// Triggers EvaluationCompleted event.
        /// </summary>
        /// <param name="e">The event data containing information
        /// if graph evaluation has completed successfully.</param>
        public virtual void OnEvaluationCompleted(EvaluationCompletedEventArgs e)
        {
            this.HasRunWithoutCrash = e.EvaluationSucceeded;

            var handler = EvaluationCompleted;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Пример #12
0
        private void OnEvalCompleted(object sender, EvaluationCompletedEventArgs e)
        {
            MemoryInstrumentationSink sink = (MemoryInstrumentationSink)e.Submission.Sink;

            var methods = sink.GetRootCalls();

            if (methods == null || methods.Count == 0)
            {
                return;
            }

            RootCall = methods.Values.First();
            Status   = null;
        }
Пример #13
0
        public override void OnEvaluationCompleted(object sender, EvaluationCompletedEventArgs e)
        {
            Debug.WriteLine(ElementIDLifecycleManager <int> .GetInstance());

            if (historicalElementData.ContainsKey(CurrentWorkspace.Guid))
            {
                ReconcileHistoricalElements();
            }

            // finally close the transaction!
            TransactionManager.Instance.ForceCloseTransaction();

            base.OnEvaluationCompleted(sender, e);
        }
Пример #14
0
        public void TestOnRequestLayoutUpdate()
        {
            //Arrange
            EvaluationCompletedEventArgs e = new EvaluationCompletedEventArgs(true, new Exception("Test"));

            //Act
            //This will subscribe our local method to the RequestLayoutUpdate event
            CurrentDynamoModel.RequestLayoutUpdate += Model_RequestLayoutUpdate;

            //This method needs to be called directly since we are not loading any dyn file to manage events
            CurrentDynamoModel.OnRequestLayoutUpdate(this, e);

            //Assert
            CurrentDynamoModel.RequestLayoutUpdate -= Model_RequestLayoutUpdate;
            //This will validate that the local handler was executed and set the flag in true
            Assert.IsTrue(layoutUpdate);
        }
Пример #15
0
        /// <summary>
        /// When the graph is evaluated .. ?
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnEvaulationCompleted(object sender, EvaluationCompletedEventArgs e)
        {
            /*
             * if (FileName == null)
             * {
             *  FileName = "New Graph";
             * }
             */

            // @todo if EvaluationCount greater than 1..

            // WORKS
            MessageBox.Show($"The current Graph name is {FileName}");

            var dataToExport = ExportData.Export(FileName, DynamoVersion);

            ExportSheets.Execute(dataToExport);
        }
Пример #16
0
        /// <summary>
        /// When the graph is evaluated .. ?
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnEvaulationCompleted(object sender, EvaluationCompletedEventArgs e)
        {
            // Record Run Data
            Data.Record(Model.CurrentWorkspace);

            // If running in DEBUG mode display a MessageBox
            #if DEBUG
            string[] message = new string[] {
                $"Hi {Data.user},",
                $"You're currently running {Data.filename} on {Data.computerName} from {Data.city}, {Data.country} using Dynamo {Data.dynamoVersion}."
            };
            string title = "Binoculars";
            MessageBox.Show(string.Join("\n\n", message), title);
            #endif

            // When graph evaluation is complete
            // Get all the data we want to store and then store it
            var dataToExport = Data.Export();
            ExportSheets.Execute(dataToExport);
        }
Пример #17
0
        internal void OnRunExpressionCompleted(object sender,
                                               EvaluationCompletedEventArgs evaluationCompletedEventArgs)
        {
            lock (stateMutex)
            {
                // Mark evaluation as being done.
                evaluationInProgress = false;

                // If there is no pending request to perform another round of
                // evaluation (i.e. the timer has not ticked while evaluation
                // was taking place), then bail.
                //
                if (!evaluationRequestPending)
                {
                    return;
                }

                // Further evaluation was requested.
                evaluationRequestPending = false;
                BeginRunExpression();
            }
        }
Пример #18
0
        private void OnEvaluationCompleted(object sender, EvaluationCompletedEventArgs e)
        {
            if (e.Exception != null)
            {
                Exception ex = e.Exception;

                var target = e.Exception as TargetInvocationException;
                if (target != null)
                {
                    ex = target.InnerException;
                }

                this.statusbar.SetText(String.Format("{0}: {1}", ex.GetType().Name, ex.Message));
                return;
            }

            this.statusbar.SetText("Evaluation completed.");

            var sink = (MemoryInstrumentationSink)e.Submission.Sink;

            var methods = sink.GetRootCalls() ?? this.context.LastData;

            if (methods == null || methods.Count == 0)
            {
                return;
            }

            Tuple <ITextSnapshot, string> adornContext = (Tuple <ITextSnapshot, string>)e.Submission.Tag;

            this.dispatcher.BeginInvoke((Action <ITextSnapshot, string, IDictionary <int, MethodCall> >)
                                            ((s, c, m) =>
            {
                this.context.LastData = m;
                AdornCode(s, c, m);
            }),
                                        adornContext.Item1, adornContext.Item2, methods);
        }
Пример #19
0
		private void OnEvalCompleted (object sender, EvaluationCompletedEventArgs e)
		{
			MemoryInstrumentationSink sink = (MemoryInstrumentationSink)e.Submission.Sink;

			var methods = sink.GetRootCalls();
			if (methods == null || methods.Count == 0)
				return;

			RootCall = methods.Values.First();
			Status = null;
		}
Пример #20
0
 private async void Model_EvaluationCompleted(object sender, EvaluationCompletedEventArgs e)
 {
     DispatcherUtil.DoEvents();
 }
Пример #21
0
        /// <summary>
        /// This callback method is invoked in the context of ISchedulerThread
        /// when UpdateGraphAsyncTask is completed.
        /// </summary>
        /// <param name="task">The original UpdateGraphAsyncTask instance.</param>
        private void OnUpdateGraphCompleted(AsyncTask task)
        {
            var updateTask = (UpdateGraphAsyncTask)task;
            var messages   = new Dictionary <Guid, string>();

            // Runtime warnings take precedence over build warnings.
            foreach (var warning in updateTask.RuntimeWarnings)
            {
                var message = string.Join("\n", warning.Value.Select(w => w.Message));
                messages.Add(warning.Key, message);
            }

            foreach (var warning in updateTask.BuildWarnings)
            {
                // If there is already runtime warnings for
                // this node, then ignore the build warnings.
                // But for cyclic dependency warnings, it is
                // easier to understand to report a build warning.
                string message = string.Empty;
                if (messages.ContainsKey(warning.Key))
                {
                    if (!warning.Value.Any(w => w.ID == ProtoCore.BuildData.WarningID.InvalidStaticCyclicDependency))
                    {
                        continue;
                    }

                    messages.Remove(warning.Key);
                    message = string.Join("\n", warning.Value.
                                          Where(w => w.ID == ProtoCore.BuildData.WarningID.InvalidStaticCyclicDependency).
                                          Select(w => w.Message));
                }
                else
                {
                    message = string.Join("\n", warning.Value.Select(w => w.Message));
                }

                if (!string.IsNullOrEmpty(message))
                {
                    messages.Add(warning.Key, message);
                }
            }

            var workspace = updateTask.TargetedWorkspace;

            foreach (var message in messages)
            {
                var guid = message.Key;
                var node = workspace.Nodes.FirstOrDefault(n => n.GUID == guid);
                if (node == null)
                {
                    continue;
                }

                node.Warning(message.Value); // Update node warning message.
            }

            // Notify listeners (optional) of completion.
            RunSettings.RunEnabled = true; // Re-enable 'Run' button.

            executingTask = false;         // setting back to false

            //set the node execution preview to false;
            OnSetNodeDeltaState(new DeltaComputeStateEventArgs(new List <Guid>(), graphExecuted));

            // This method is guaranteed to be called in the context of
            // ISchedulerThread (for Revit's case, it is the idle thread).
            // Dispatch the failure message display for execution on UI thread.
            //
            EvaluationCompletedEventArgs e = task.Exception == null || IsTestMode
                ? new EvaluationCompletedEventArgs(true)
                : new EvaluationCompletedEventArgs(true, task.Exception);

            EvaluationCount++;

            OnEvaluationCompleted(e);

            if (EngineController.IsDisposed)
            {
                return;
            }

            EngineController.ReconcileTraceDataAndNotify();

            // Refresh values of nodes that took part in update.
            var nodes = new HashSet <NodeModel>(updateTask.ExecutedNodes.Concat(updateTask.ModifiedNodes));

            foreach (var executedNode in nodes)
            {
                executedNode.RequestValueUpdate(EngineController);
            }

            scheduler.Tasks.AllComplete(_ =>
            {
                OnRefreshCompleted(e);
            });
        }
Пример #22
0
		private void OnEvaluationCompleted (object sender, EvaluationCompletedEventArgs e)
		{
			if (e.Exception != null)
			{
				Exception ex = e.Exception;

				var target = e.Exception as TargetInvocationException;
				if (target != null)
					ex = target.InnerException;

				this.statusbar.SetText (String.Format ("{0}: {1}", ex.GetType().Name, ex.Message));
				return;
			}

			this.statusbar.SetText ("Evaluation completed.");

			var sink = (MemoryInstrumentationSink)e.Submission.Sink;

			var methods = sink.GetRootCalls() ?? this.context.LastData;
			if (methods == null || methods.Count == 0)
				return;

			Tuple<ITextSnapshot, string> adornContext = (Tuple<ITextSnapshot,string>)e.Submission.Tag;

			this.dispatcher.BeginInvoke ((Action<ITextSnapshot,string,IDictionary<int,MethodCall>>)
				((s,c,m) =>
				{
					this.context.LastData = m;
					AdornCode (s, c, m);
				}),
				adornContext.Item1, adornContext.Item2, methods);
		}
Пример #23
0
 private void CurrentDynamoModel_EvaluationCompleted(object sender, EvaluationCompletedEventArgs e)
 {
     evaluationCompleted = true;
 }
Пример #24
0
 protected virtual void OnEvaluationCompleted(object sender, EvaluationCompletedEventArgs e)
 {
     // Override in derived classes
 }
Пример #25
0
 protected override void OnEvaluationCompleted(object sender, EvaluationCompletedEventArgs e)
 {
     Draw();
 }