Exemplo n.º 1
0
        private void GetDataFromTfs(int?lastId, int itemSize, bool isFullCall = false)
        {
            IEnumerable <TFSCore.IHistoryItem> historyItems;

            Debug.WriteLine($"Getting HistoryItems from TFS {lastId} {itemSize}");
            historyItems = Tfs.GetHistory(TeamProject.ServerItem, lastId, itemSize);

            IList <TFSCore.IHistoryItem> modifiedHistoryItems = new List <IHistoryItem>();

            foreach (HistoryItem historyItem in historyItems)
            {
                if (CancellationTokenSource.IsCancellationRequested)
                {
                    return;
                }


                modifiedHistoryItems.Add(HistoryItems.AddOrUpdateWithoutNotification(historyItem, (item, item1) => item.ChangeSetId == item1.ChangeSetId, (items, index, newItem) =>
                {
                    // make sure we keep our "ExtendedProperties"
                    IHistoryItem.CopyTo(items[index], newItem);
                }));
            }
            HistoryItems.NotifyReset();

            Debug.WriteLine($"Got {historyItems.Count()} HistoryItems from TFS");

            SaveDataToCache(true, false);

            Debug.WriteLine($"Resolving Workitems for {historyItems.Count()}");
            foreach (HistoryItem historyItem in modifiedHistoryItems)
            {
                if (CancellationTokenSource.IsCancellationRequested)
                {
                    return;
                }
                foreach (WorkItem workItem in historyItem.WorkItems)
                {
                    if (CancellationTokenSource.IsCancellationRequested)
                    {
                        return;
                    }
                    Debug.WriteLine($"Resolved Workitems for {historyItem.ChangeSetId}");
                    workItem.UpdateIndexedWords(true);
                    WorkItems.AddOrUpdate(workItem, (item, item1) => item.Id == item1.Id, (items, index, newItem) => items[index] = newItem);
                }
                // Updating Cache
                historyItem.UpdateIndexedWords(true);
            }

            SaveDataToCache(true, true);
            if (!isFullCall)
            {
                GetDataFromTfs(null, Int32.MaxValue, true);
            }
        }
Exemplo n.º 2
0
        private void GetData(bool skipCache, bool skipTFS)
        {
            if (IsWorking)
            {
                return;
            }
            IsWorking = true;

            int?lastId = null;

            if (!skipCache)
            {
                lock (SqliteConnection)
                {
                    SqliteConnection.Open();
                    Debug.WriteLine("Getting HistoryItems from Cache");
                    var historyItems = DBLoader.GetHistoryItems();
                    if (historyItems.Any())
                    {
                        HistoryItems.AddRangeWithoutNotification(historyItems);

                        /*foreach (var item in historyItems)
                         * {
                         *      item.GotWorkItems += ItemOnGotWorkItems;
                         * }*/
                    }
                    Debug.WriteLine($"Got {historyItems.Count()} HistoryItems from Cache");

                    if (historyItems.Any())
                    {
                        lastId = historyItems.Max(x => x.ChangeSetId);
                    }


                    Debug.WriteLine("Getting WorkItems from Cache");
                    var workItems = DBLoader.GetWorkItems(Settings);
                    if (workItems.Any())
                    {
                        WorkItems.AddRangeWithoutNotification(workItems);
                    }

                    Debug.WriteLine($"Got {workItems.Count()} WorkItems from Cache");
                    SqliteConnection.Close();

                    // Resolve CachedWorkItems in HistoryItems
                    foreach (var item in HistoryItems)
                    {
                        var resolvedWorkItems = new List <WorkItem>();
                        foreach (int id in item.CachedWorkItemIds)
                        {
                            var resolvedWorkItem = WorkItems.FirstOrDefault(x => x.Id == id);
                            if (resolvedWorkItem != null)
                            {
                                resolvedWorkItems.Add(resolvedWorkItem);
                            }
                        }
                        item.CachedWorkItems   = resolvedWorkItems.ToArray();
                        item.CachedWorkItemIds = resolvedWorkItems.Select(x => x.Id).ToArray();
                    }
                    HistoryItems.NotifyReset();
                    WorkItems.NotifyReset();
                }
            }
            if (!skipTFS)
            {
                GetDataFromTfs(lastId, lastId.HasValue ? Int32.MaxValue : InitialItemSize);
            }
            IsWorking = false;
        }