private void InitData() { TaskProgressResult currentTaskProgress; if (ApplicationContext.TaskProgressDictionary.ContainsKey(_taskItemViewModel.Id)) { currentTaskProgress = ApplicationContext.TaskProgressDictionary[_taskItemViewModel.Id]; } else { currentTaskProgress = new TaskProgressResult(); currentTaskProgress.Init(); } if (TaskProgressCollection != null) { TaskProgressCollection = null; } TaskProgressCollection = new ObservableCollection <TaskProgressItemView>(); ColorBrushCollection = new BrushCollection(); foreach (var task in currentTaskProgress) { var solidColor = new SolidColorBrush(_dictColorMap[task.Type]); var taskView = new TaskProgressItemView(task) { SolidColor = solidColor }; if (task.TaskCount > 0) { ColorBrushCollection.Add(solidColor); } TaskProgressCollection.Add(taskView); } }
private void RefreshTaskProgressDictionary(List <TaskProgressItem> taskProgressList) { int taskId = 0; ApplicationContext.TaskProgressDictionary = new ConcurrentDictionary <int, TaskProgressResult>(); foreach (var taskProgressItem in taskProgressList) { if (taskProgressItem.TaskId != taskId) { taskId = taskProgressItem.TaskId; var taskProgressResult = new TaskProgressResult(); taskProgressResult.Init(); ApplicationContext.TaskProgressDictionary.AddOrUpdate(taskId, taskProgressResult, (key, oldVal) => taskProgressResult); } ApplicationContext.TaskProgressDictionary[taskId][(int)taskProgressItem.Type] = taskProgressItem; } }