示例#1
0
        /// <summary>
        ///     Initializes the History panel.
        /// </summary>
        void InitializeHistoryPanel()
        {
            Dispatcher.InvokeAsync(() =>
            {
                UserVisibleTrace("History is loading...");

                var dbRecords = SafeRun(() => GetHistory(scope))
                                .IfNull(() => new List <InvocationInfo>())
                                .AddNewOneItemIfListIsEmpty(CreateNewInvocationInfo)
                                .ToList();

                var hasAlreadyHistories = scope.Contains(HistoryItems);
                if (hasAlreadyHistories)
                {
                    var selectedItem = (InvocationInfo)historyListBox.SelectedItem;
                    if (selectedItem != null)
                    {
                        dbRecords.RemoveAll(x => InvocationInfo.IsSame(x, selectedItem));
                        dbRecords.Add(selectedItem);
                    }

                    historyListBox.ItemsSource = dbRecords;

                    CollectionViewSource.GetDefaultView(historyListBox.ItemsSource).Refresh();

                    UserVisibleTrace($"History is refreshed. Fetched record count is {dbRecords.Count}");

                    return;
                }

                scope.Update(HistoryItems, dbRecords);

                UserVisibleTrace("History is loaded.");
            });
        }