コード例 #1
0
        public async void Execute(object parameter)
        {
            IsBusy = true;
            await Task.Run(() =>
            {
                string replaceText = ReplaceTerm ?? "";

                WorkItem[] workItems = WorkItemsListProvider.WorkItems.AsWorkItems().ToArray();
                foreach (var workItem in workItems)
                {
                    workItem.Open();

                    foreach (var fieldName in workItemFieldMap[workItem.Id])
                    {
                        var field    = workItem.Fields[fieldName];
                        var original = field.Value.ToString();
                        var replaced = original.Replace(SearchTerm, replaceText);

                        field.Value = replaced;
                    }
                }

                var store = context.TeamProjectCollection.GetService <WorkItemStore>();
                store.BatchSave(workItems);
            });

            StatusText       = "Replace complete. You may perform a new search.";
            IsPreviewVisible = false;
            WorkItemsListProvider.Clear();
            PreviewFields.Clear();
            IsBusy = false;
        }
コード例 #2
0
        public async void Preview(object parameter)
        {
            IsBusy           = true;
            IsPreviewVisible = false;
            WorkItemsListProvider.Clear();
            PreviewFields.Clear();
            BatchedObservableCollection <WorkItem> foundWorkItems = new BatchedObservableCollection <WorkItem>();

            await Task.Run(() =>
            {
                QueryDefinition query        = TfsContext.WorkItemStore.GetQueryDefinition(queryItem.Id);
                WorkItemCollection workItems = TfsContext.WorkItemStore.Query(query.QueryText, TfsContext.WorkItemManager.Context);

                workItemFieldMap = new Dictionary <int, List <string> >();
                fieldMatches     = new HashSet <string>();

                foreach (WorkItem workItem in workItems)
                {
                    bool matchedCurrent = false;
                    foreach (Field field in workItem.Fields.Cast <Field>().Where(f => IsStringField(f.FieldDefinition)))
                    {
                        if (field.Value.ToString().Contains(SearchTerm))
                        {
                            if (!matchedCurrent)
                            {
                                foundWorkItems.Add(workItem);
                                matchedCurrent = true;
                                workItemFieldMap.Add(workItem.Id, new List <string>());
                            }

                            fieldMatches.Add(field.Name);
                            workItemFieldMap[workItem.Id].Add(field.Name);
                        }
                    }
                }
            });

            WorkItemsListProvider.AddWorkItems(foundWorkItems);
            PreviewFields.AddRange(fieldMatches);

            bool matchFound = WorkItemsListProvider.VisibleCount > 0;

            StatusText       = matchFound? "" : "No matches found.";
            IsPreviewVisible = matchFound;
            IsBusy           = false;
        }