void CommitTask_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { BackgroundTask task = e.Argument as BackgroundTask; if (ChangeList.Count > 0) { int currentItem = 1; int totalItems = ChangeList.Count; foreach (StoreItem item in ChangeList) { if (task.CancellationPending) { e.Cancel = true; e.Result = new BackgroundTaskResult { ResultType = ResultType.Cancelled }; return; } task.ReportProgress((currentItem * 100) / totalItems, item.ID.ToString() + ": " + item.Title, "Change " + currentItem.ToString() + " of " + totalItems.ToString()); BackgroundTaskResult result = CommitItemWorker(item, NewCommittedItems); if (result.ResultType != ResultType.Completed) { e.Result = result; return; } ItemsCommittedSuccessfully.Add(item); currentItem++; } e.Result = new BackgroundTaskResult { ResultType = ResultType.Completed }; } }
void getActiveDirectoryImageValueTask_DoWork(object sender, DoWorkEventArgs e) { BackgroundTask task = e.Argument as BackgroundTask; ImageArgs imageProps = task.TaskArgs as ImageArgs; UserInformation userInfo = new UserInformation(); userInfo.InitializeWithAlias(imageProps.Alias); MemoryStream stream = userInfo.UserPicture; BitmapSource source = null; if (stream != null) { source = FileUtils.GetBitmapSourceFromStream(stream); } if (source != null) { ImageAttachment imageAttachment = new ImageAttachment { BitmapSource = source }; Attachments.Add(imageProps.PublicPropName, imageAttachment); } }
//------------------------------------------------------------------------------------ /// <summary> /// Executes the given query against this data store. Returns false if a cancellation /// request is detected via the given taskWorker. /// </summary> //------------------------------------------------------------------------------------ public BackgroundTaskResult ExecuteQuery(IRepository repository, BaseQuery query, ShouldRefresh shouldRefresh, BackgroundTask taskWorker, bool deferItemCreation) { DatastoreItemList storeItemList = GetStoreItemList(); FieldDefinitions fieldDefs = storeItemList.Datastore.FieldDefinitions; // Set up a query, using QueryDefinition to define the query XML ProductStudio.Query psQuery = new ProductStudio.Query(); psQuery.CountOnly = false; psQuery.DatastoreItemType = PsDatastoreItemTypeEnum.psDatastoreItemTypeBugs; psQuery.SelectionCriteria = query.QueryXml; psQuery.QueryFields.Clear(); psQuery.QuerySortFields.Clear(); psQuery.QuerySortFields.Add(fieldDefs["ID"], PsSortTypeEnum.psSortTypeDescending); // Execute the query try { storeItemList.Query = psQuery; storeItemList.Execute(); } catch (Exception e) { return(new BackgroundTaskResult { ResultType = ResultType.Failed, ResultMessage = e.Message }); } Planner.Instance.WriteToEventLog(StoreName + ": Query results count: " + storeItemList.DatastoreItems.Count.ToString()); repository.ReceiveDSItems(this, storeItemList.DatastoreItems, shouldRefresh, deferItemCreation); return(new BackgroundTaskResult { ResultType = ResultType.Completed }); }