/// <summary>
 /// Initializes the controls after they have been created
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void MainWindow_Initialized(object sender, EventArgs e)
 {
     UnsortedView.InitializeList(new ObservableDictionary <string, string>(), 10, false);
     SortedView.InitializeList(new ObservableSortedDictionary <string, string>(), 10, false);
     ConcurrentUnsortedView.InitializeList(new ConcurrentObservableDictionary <string, string>(), 10, true);
     ConcurrentSortedView.InitializeList(new ConcurrentObservableSortedDictionary <string, string>(), 10, true);
 }
        private void DoSearch()
        {
            try
            {
                if (IsSearching)
                {
                    ClearSearch();
                }
                else
                {
                    if (SearchFilter == null || string.IsNullOrEmpty(SearchFilter.Trim()))
                    {
                        throw new Exception("No search string entered");
                    }

                    items.Clear();
                    List <IDataItem> results = DataManager.Instance().DataStore.Search(SearchFilter);

                    foreach (var i in results)
                    {
                        Items.Add(new ItemViewModel(i, SVMLookup[i.GetSource()]));
                    }
                }

                SortedView.Refresh();
                IsSearching = !IsSearching;

                RefreshViewModel();
            }
            catch (Exception e)
            {
                MessageBoxFactory.ShowError(e);
            }
        }
        private void MarkSelected(object selected)
        {
            List <IDataItem> updated = new List <IDataItem>();

            var items = selected as System.Collections.IList;

            foreach (ItemViewModel ivm in items)
            {
                if (ivm.Data.New)
                {
                    ivm.Data.SetNew(false);
                    updated.Add(ivm.Data);
                }
            }

            DataManager.Instance().DataStore.UpdateItem(updated);
            SortedView.Refresh();
        }
        private void MarkAll()
        {
            if (MessageBox.Show("Mark all items as read?", "Mark All Read", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
            {
                return;
            }

            List <IDataItem> updated = new List <IDataItem>();

            foreach (ItemViewModel ivm in items)
            {
                if (ivm.Data.New)
                {
                    ivm.Data.SetNew(false);
                    updated.Add(ivm.Data);
                }
            }

            DataManager.Instance().DataStore.UpdateItem(updated);
            SortedView.Refresh();
        }
        public void PerformItemAction(object sender)
        {
            var o = SelectedItem;

            if (o != null)
            {
                var provider = DataManager.Instance().GetProviders().First(x => x.ProviderId == o.Provider);
                if (provider != null)
                {
                    try
                    {
                        provider.DoAction(o.Data);
                        o.Data.SetNew(false);
                        DataManager.Instance().DataStore.UpdateItem(o.Data);

                        SortedView.Refresh();
                    }
                    catch (Exception e)
                    {
                        MessageBoxFactory.ShowError("Cannot perform action on: " + o.Data, "Cannot Perform Action");
                    }
                }
            }
        }