Beispiel #1
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;
        }