/// <summary> /// Initializes the specified sender. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="PageInitializeEventArgs"/> instance containing the event data.</param> public override void Initialize(object sender, PageInitializeEventArgs e) { base.Initialize(sender, e); this.Title = Resources.PlanWorkItemPage_Title; PlanWorkItemPageModel pageModel = e.Context as PlanWorkItemPageModel; if (pageModel == null) { pageModel = _storedPageModel; if (pageModel == null) { Debug.WriteLine("[PlanWorkItemPage] CreateViewModel: e.Context must be of type PlanWorkItemPageModel"); return; } } else { _storedPageModel = pageModel; } pageModel.PropertyChanged -= pageModel_PropertyChanged; pageModel.PropertyChanged += pageModel_PropertyChanged; // Assign the WPF Control this.PageContent = new PlanWorkItemView() { DataContext = pageModel }; }
/// <summary> /// Handles the PropertyChanged event of the pageModel control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.ComponentModel.PropertyChangedEventArgs"/> instance containing the event data.</param> private void pageModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { PlanWorkItemPageModel pgModel = sender as PlanWorkItemPageModel; switch (e.PropertyName) { case "IsBusy": this._isBusy = pgModel.IsBusy; this.RaisePropertyChanged("IsBusy"); break; } }
/// <summary> /// Builds the planning templates. /// </summary> /// <param name="pageModel">The page model.</param> /// <param name="configuration">The configuration.</param> private void BuildPlanningTemplates(PlanWorkItemPageModel pageModel, ConfigurationRoot configuration) { if (configuration.Templates != null && configuration.Templates.Count > 0) { ObservableCollection <PlanningTemplate> planningTemplates = new ObservableCollection <PlanningTemplate>(); foreach (Template template in configuration.Templates.OrderBy(x => x.DisplayOrder).ThenBy(x => x.DisplayName)) { planningTemplates.Add((PlanningTemplate)template); } pageModel.PlanningTemplates = planningTemplates; } }
private async void LoadWorkItems() { if (this.PageModel.AreWorkItemsSelected) { PlanWorkItemPageModel pgModel = this.PageModel; pgModel.IsBusy = true; // Load WorkItems await System.Threading.Tasks.Task.Run(() => { var workItems = pgModel.TfsClient.GetWorkItems(pgModel.WorkItemIds); String aggregatedTitle = null; String aggregatedIterationPath = null; for (int i = 0; i < workItems.Length; i++) { if (aggregatedTitle == null) { aggregatedTitle = workItems[i].Title; } else if (aggregatedTitle != workItems[i].Title) { aggregatedTitle = "(multiple work items selected)"; } if (aggregatedIterationPath == null) { aggregatedIterationPath = workItems[i].IterationPath; } else if (aggregatedIterationPath != workItems[i].IterationPath) { aggregatedIterationPath = "(multiple work items selected)"; } } pgModel.AggregatedWorkItemTitle = aggregatedTitle; pgModel.AggregatedWorkItemIterationPath = aggregatedIterationPath; }); pgModel.AreWorkItemsSelected = true; pgModel.IsBusy = false; } }
/// <summary> /// Handles the Click event of the buttonCreateWorkItems control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private async void buttonCreateWorkItems_Click(object sender, RoutedEventArgs e) { this.PageModel.IsBusy = true; PlanWorkItemPageModel pgModel = this.PageModel; foreach (TaskTemplate taskTemplate in pgModel.SelectedPlanningTemplate.TasksToCreateCollection) { foreach (TaskTemplateInstance taskTemplateInstance in taskTemplate.InstancesCollection) { if (String.IsNullOrWhiteSpace(taskTemplateInstance.AssignedTo)) { var dlgResult = MessageBox.Show("There are instances without an assigned User. Do you want to continue?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes); if (dlgResult != MessageBoxResult.Yes) { this.PageModel.IsBusy = false; return; } } } } await System.Threading.Tasks.Task.Run(() => { var addedCreatedWorkItems = pgModel.TfsClient.CreateRelatedWorkItems(pgModel.WorkItemIds, pgModel.SelectedPlanningTemplate); if (pgModel.CreatedWorkItems != null) { List <WorkItem> previousWorkItems = pgModel.CreatedWorkItems.ToList(); previousWorkItems.AddRange(addedCreatedWorkItems); pgModel.CreatedWorkItems = new ObservableCollection <WorkItem>(previousWorkItems.OrderByDescending(x => x.CreatedDate)); } else { pgModel.CreatedWorkItems = new ObservableCollection <WorkItem>(addedCreatedWorkItems.OrderByDescending(x => x.CreatedDate)); } }); this.PageModel.IsBusy = false; }
/// <summary> /// Builds the planning templates. /// </summary> /// <param name="pageModel">The page model.</param> /// <param name="configuration">The configuration.</param> private void BuildPlanningTemplates(PlanWorkItemPageModel pageModel, ConfigurationRoot configuration) { if (configuration.Templates != null && configuration.Templates.Count > 0) { ObservableCollection<PlanningTemplate> planningTemplates = new ObservableCollection<PlanningTemplate>(); foreach (Template template in configuration.Templates.OrderBy(x => x.DisplayOrder).ThenBy(x => x.DisplayName)) { planningTemplates.Add((PlanningTemplate)template); } pageModel.PlanningTemplates = planningTemplates; } }