Exemplo n.º 1
0
        public void AllComplete_ExecutesCallbackWhenSomeDiscardedSomeCompleted()
        {
            var run = false;

            var s = MockMaker.Empty <IScheduler>();

            var t1 = new DelegateBasedAsyncTask(s);
            var t2 = new DelegateBasedAsyncTask(s);

            var l = new List <AsyncTask>()
            {
                t1,
                t2
            };

            l.AllComplete((_) =>
            {
                run = true;
            });

            t1.HandleTaskDiscarded();
            t2.HandleTaskCompletion();

            Assert.True(run);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add a new task to the scheduler to be executed and after that run a
        /// follow-up task.
        /// </summary>
        /// <param name="a">The task to be run in the scheduler</param>
        /// <param name="h">The follow up handler to be executed</param>
        private void RunOnSchedulerSync(Action a, AsyncTaskCompletedHandler h)
        {
            var task = new DelegateBasedAsyncTask(scheduler, a);

            task.ThenPost(h, SynchronizationContext.Current);
            scheduler.ScheduleForExecution(task);
        }
Exemplo n.º 3
0
        public void AllComplete_ReturnsDisposableThatDisposesAllRegistrations()
        {
            var run = false;

            var s = MockMaker.Empty <IScheduler>();

            var t1 = new DelegateBasedAsyncTask(s);
            var t2 = new DelegateBasedAsyncTask(s);

            var l = new List <AsyncTask>()
            {
                t1,
                t2
            };

            l.AllComplete((_) =>
            {
                run = true;
            }).Dispose();

            t1.HandleTaskCompletion();
            t2.HandleTaskDiscarded();

            Assert.False(run);
        }
Exemplo n.º 4
0
        public static void ExecuteOnIdleAsync(Action p)
        {
            var scheduler = DynamoRevit.RevitDynamoModel.Scheduler;
            var task      = new DelegateBasedAsyncTask(scheduler);

            task.Initialize(p);
            scheduler.ScheduleForExecution(task);
        }
Exemplo n.º 5
0
        private void UpdateHtmlString()
        {
            var s = _dynamoViewModel.Model.Scheduler;
            var t = new DelegateBasedAsyncTask(s, () =>
            {
                _mandrillNode.MyHtml = _mandrillNode.GetInputString(_dynamoModel.EngineController);
            });

            s.ScheduleForExecution(t);
        }
Exemplo n.º 6
0
        private void UpdateNode()
        {
            var s = _dynamoViewModel.Model.Scheduler;
            var t = new DelegateBasedAsyncTask(s, () =>
            {
                _customNode.Input = _customNode.GetInputString(_dynamoModel.EngineController);
            });

            s.ScheduleForExecution(t);
        }
Exemplo n.º 7
0
        private void ResetWatch()
        {
            // When the node has no input connected, the preview should be empty
            // Without doing this, the preview would say "null"
            if (watch.IsPartiallyApplied)
            {
                rootWatchViewModel.Children.Clear();
                rootWatchViewModel.IsCollection = false;
                return;
            }

            // If the node hasn't been evaluated, no need to update the UI
            if (!watch.HasRunOnce)
            {
                return;
            }

            var s = dynamoViewModel.Model.Scheduler;

            WatchViewModel wvm = null;

            // prevent data race by running on scheduler
            var t = new DelegateBasedAsyncTask(s, () =>
            {
                wvm = GetWatchViewModel();
            });

            // then update on the ui thread
            t.ThenPost((_) =>
            {
                //If wvm is not computed successfully then don't post.
                if (wvm == null)
                {
                    return;
                }

                // store in temp variable to silence binding
                var temp = rootWatchViewModel.Children;


                rootWatchViewModel.Children = null;
                temp.Clear();
                temp.Add(wvm);

                // rebind
                rootWatchViewModel.Children = temp;
                rootWatchViewModel.CountNumberOfItems();
                rootWatchViewModel.CountLevels();
                rootWatchViewModel.Children[0].IsTopLevel = true;
            }, syncContext);

            s.ScheduleForExecution(t);
        }
        private void UpdateCollection()
        {
            // (Konrad) We pass a list of items already selected so that we can update them rather than create a new list.
            var selected  = View._listBox.SelectedItems;
            var scheduler = DynamoViewmodel.Model.Scheduler;
            var delegateBasedAsyncTask = new DelegateBasedAsyncTask(scheduler, delegate
            {
                ViewModel.PopulateItems(selected);
            });

            delegateBasedAsyncTask.ThenSend(delegate { }, SyncContext);
            scheduler.ScheduleForExecution(delegateBasedAsyncTask);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Call this method to schedule a DelegateBasedAsyncTask for execution.
        /// </summary>
        /// <param name="p">The delegate to execute on the idle thread.</param>
        /// <param name="completionHandler">Event handler that will be invoked
        /// when the scheduled DelegateBasedAsyncTask is completed. This parameter
        /// is optional.</param>
        ///
        internal static void ExecuteOnIdleAsync(Action p,
                                                AsyncTaskCompletedHandler completionHandler = null)
        {
            var scheduler = DynamoRevit.RevitDynamoModel.Scheduler;
            var task      = new DelegateBasedAsyncTask(scheduler, p);

            if (completionHandler != null)
            {
                task.Completed += completionHandler;
            }

            scheduler.ScheduleForExecution(task);
        }
Exemplo n.º 10
0
        private void OnRequestScheduledTask(Action action)
        {
            var s = dynamoViewModel.Model.Scheduler;

            var t = new DelegateBasedAsyncTask(s, () =>
            {
            });

            t.ThenSend((_) =>
            {
                action();
            }, syncContext);

            s.ScheduleForExecution(t);
        }
Exemplo n.º 11
0
        private void UpdateParameterSelector()
        {
            var scheduler = _dynamoViewmodel.Model.Scheduler;
            var delegateBasedAsyncTask = new DelegateBasedAsyncTask(scheduler, delegate
            {
                _viewModel.PopulateItems();
            });

            delegateBasedAsyncTask.ThenSend(delegate
            {
                _viewModel.SelectedItem = _viewModel.SelectedItem ?? _viewModel.ItemsCollection.FirstOrDefault();
            }, _syncContext);

            scheduler.ScheduleForExecution(delegateBasedAsyncTask);
        }
Exemplo n.º 12
0
        private void UpdateColorRange()
        {
            var s = dynamoViewModel.Model.Scheduler;

            // prevent data race by running on scheduler
            var t = new DelegateBasedAsyncTask(s, () =>
            {
                colorRange = colorRangeNode.ComputeColorRange(dynamoModel.EngineController);
            });

            // then update on the ui thread
            t.ThenSend((_) =>
            {
                var bmp = CreateColorRangeBitmap(colorRange);
                gradientImage.Source = bmp;
            }, syncContext);

            s.ScheduleForExecution(t);
        }
Exemplo n.º 13
0
        private void UpdateParameterSelector()
        {
            DynamoScheduler        scheduler = DynamoViewmodel.Model.Scheduler;
            DelegateBasedAsyncTask delegateBasedAsyncTask = new DelegateBasedAsyncTask(scheduler, delegate
            {
                ViewModel.PopulateItems();
            });

            AsyncTaskExtensions.ThenSend(delegateBasedAsyncTask, delegate(AsyncTask _)
            {
                if (ViewModel.SelectedItem != null)
                {
                    ViewModel.SelectedItem = ViewModel.SelectedItem;
                }
                else
                {
                    ViewModel.SelectedItem = ViewModel.ItemsCollection.FirstOrDefault <ParameterWrapper>();
                }
            }, SyncContext);
            scheduler.ScheduleForExecution(delegateBasedAsyncTask);
        }
Exemplo n.º 14
0
 protected void AsyncSchedule(DelegateBasedAsyncTask task)
 {
     viewModel.Model.Scheduler.ScheduleForExecution(task);
 }
Exemplo n.º 15
0
 protected DelegateBasedAsyncTask AsyncThenUI(DelegateBasedAsyncTask task, Action action)
 {
     task.ThenSend((_) => action?.BeginInvoke(action.EndInvoke, null), syncContext);
     return(task);
 }