Пример #1
0
        private void AddViewModel(ITaskViewModel taskViewModel, TabItem tabItem)
        {
            try
            {
                if (tabMap.ContainsKey(taskViewModel.Id))
                {
                    throw new InvalidOperationException("There is already a tab for this task. name=" + taskViewModel.Name + " description=" + taskViewModel.Description);
                }

                taskViewModel.AddStartedCallback(x => TaskStarted(x));

                var taskResultViewModel = new TaskResultViewModel(taskViewModel, tabItem);

                tabItem.DataContext = taskResultViewModel;
                taskResultViewModel.AddClosedCallback(x => CloseTab(x));

                tabMap.Add(taskViewModel.Id, taskResultViewModel);

                var existing = taskController.Tasks.Where(x => x.Id == taskViewModel.Id).FirstOrDefault();
                if (existing == null)
                {
                    taskController.AddTaskViewModel(taskViewModel);
                }
            }
            catch (Exception ex)
            {
                logger.Error("  TaskResultView.AddViewModel", ex);
            }
        }