예제 #1
0
        public void Refresh(WorkItemRefreshRequest request)
        {
            ThreadPool.QueueUserWorkItem(
                delegate
            {
                try
                {
                    using (var context = new DataAccessContext())
                    {
                        var broker = context.GetWorkItemBroker();

                        var dbList = broker.GetWorkItems(null, null, null);

                        // send in batches of 200
                        foreach (var batch in BatchItems(dbList, 200))
                        {
                            WorkItemPublishSubscribeHelper.PublishWorkItemsChanged(WorkItemsChangedEventType.Refresh, batch.Select(WorkItemDataHelper.FromWorkItem).ToList());
                        }
                    }
                }
                catch (Exception e)
                {
                    var message          = SR.ExceptionErrorProcessingRefresh;
                    var exceptionMessage = String.Format("{0}\nDetail:{1}", message, e.Message);
                    Platform.Log(LogLevel.Error, e, exceptionMessage);
                    // Don't rethrow here, we're in a thread pool anyways.
                }
            });
        }
예제 #2
0
        /// <summary>
        /// Method for getting next <see cref="WorkItem"/> entry.
        /// </summary>
        /// <param name="count">The count.</param>
        /// <param name="priority">Search for stat items.</param>
        /// <remarks>
        /// </remarks>
        /// <returns>
        /// A <see cref="WorkItem"/> entry if found, or else null;
        /// </returns>
        private List <WorkItem> InternalGetWorkItems(int count, WorkItemPriorityEnum priority)
        {
            _nowRunningWorkItems.Clear();
            _postponedWorkItems.Clear();

            var itemsToPublish = new List <WorkItemData>();

            try
            {
                var             workItemBroker = _context.GetWorkItemBroker();
                List <WorkItem> workItems      = workItemBroker.GetWorkItemsForProcessing(count * 4, priority);
                foreach (var item in workItems)
                {
                    string reason;
                    if (CanStart(item, out reason))
                    {
                        item.Status = WorkItemStatusEnum.InProgress;
                        _nowRunningWorkItems.Add(item);
                    }
                    else
                    {
                        Postpone(item);
                        _postponedWorkItems.Add(item);
                        WorkItemProgress progress = item.Progress;
                        if (progress != null)
                        {
                            progress.StatusDetails = reason;
                            item.Progress          = progress;
                            itemsToPublish.Add(WorkItemDataHelper.FromWorkItem(item));
                        }
                    }

                    if (_nowRunningWorkItems.Count >= count)
                    {
                        break;
                    }
                }

                _context.Commit();

                return(new List <WorkItem>(_nowRunningWorkItems));
            }
            catch (Exception x)
            {
                Platform.Log(LogLevel.Warn, x, "Unexpected error querying for {0} {1} priority WorkItems", count, priority.GetDescription());
                return(null);
            }
            finally
            {
                if (itemsToPublish.Count > 0)
                {
                    WorkItemPublishSubscribeHelper.PublishWorkItemsChanged(WorkItemsChangedEventType.Update, itemsToPublish);
                }
            }
        }