Beispiel #1
0
        private void DoUpdate(ISortedChangeSet <TObject, TKey> updates, IObservableCollection <TObject> list)
        {
            updates.ForEach(update =>
            {
                switch (update.Reason)
                {
                case ChangeReason.Add:
                    list.Insert(update.CurrentIndex, update.Current);
                    break;

                case ChangeReason.Remove:
                    list.RemoveAt(update.CurrentIndex);
                    break;

                case ChangeReason.Moved:
                    list.Move(update.PreviousIndex, update.CurrentIndex);
                    break;

                case ChangeReason.Update:
                    {
                        list.RemoveAt(update.PreviousIndex);
                        list.Insert(update.CurrentIndex, update.Current);
                    }
                    break;
                }
            });
        }
Beispiel #2
0
        private void DoUpdate(ISortedChangeSet <TObject, TKey> updates, IObservableCollection <TObject> list)
        {
            foreach (var update in updates)
            {
                switch (update.Reason)
                {
                case ChangeReason.Add:
                    list.Insert(update.CurrentIndex, update.Current);
                    break;

                case ChangeReason.Remove:
                    list.RemoveAt(update.CurrentIndex);
                    break;

                case ChangeReason.Moved:
                    list.Move(update.PreviousIndex, update.CurrentIndex);
                    break;

                case ChangeReason.Update:
                    if (update.PreviousIndex != update.CurrentIndex)
                    {
                        list.RemoveAt(update.PreviousIndex);
                        list.Insert(update.CurrentIndex, update.Current);
                    }
                    else
                    {
                        list.Replace(update.Previous.Value, update.Current);
                    }

                    break;
                }
            }
        }
        public bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
        {
            if (managerType == typeof(CollectionChangedEventManager))
            {
                NotifyCollectionChangedEventArgs arg = e as NotifyCollectionChangedEventArgs;
                if (arg != null)
                {
                    switch (arg.Action)
                    {
                    case NotifyCollectionChangedAction.Add:
                        if (arg.NewItems != null)
                        {
                            for (int itemIndex = 0; itemIndex < arg.NewItems.Count; itemIndex++)
                            {
                                _syncCollection.Insert(arg.NewStartingIndex +
                                                       itemIndex, _create(arg.NewItems[itemIndex] as T));
                            }
                            break;
                        }
                        break;

                    case NotifyCollectionChangedAction.Move:
                        _syncCollection.RemoveAt(arg.OldStartingIndex);
                        _syncCollection.Insert(arg.NewStartingIndex, _create(arg.NewItems[0] as T));
                        break;

                    case NotifyCollectionChangedAction.Remove:
                        if (arg.OldItems != null && _syncCollection.Count > 0)
                        {
                            for (int itemIndex = 0; itemIndex < arg.OldItems.Count; itemIndex++)
                            {
                                _syncCollection.RemoveAt(arg.OldStartingIndex);
                            }
                        }
                        break;

                    case NotifyCollectionChangedAction.Replace:
                        if (arg.NewItems == null)
                        {
                            for (int itemIndex = 0; itemIndex < arg.NewItems.Count; itemIndex++)
                            {
                                _syncCollection[arg.NewStartingIndex + itemIndex] = _create(arg.NewItems[itemIndex] as T);
                            }
                        }
                        break;

                    case NotifyCollectionChangedAction.Reset:
                        _syncCollection.Clear();
                        break;

                    default:
                        break;
                    }
                }
                return(true);
            }
            return(false);
        }
Beispiel #4
0
        public ArenaSessionsViewModel(
            IEventAggregator events,
            IRepository <ArenaSession> arenaRepository,
            IRepository <GameResult> gameRepository,
            Func <HearthStatsDbContext> dbContext,
            GameManager.GameManager gameManager)
        {
            IsNotifying          = false;
            this.events          = events;
            this.arenaRepository = arenaRepository;
            this.gameRepository  = gameRepository;
            this.dbContext       = dbContext;
            this.gameManager     = gameManager;
            Order       = 2;
            DisplayName = "Arenas";

            this.events.Subscribe(this);
            ArenaSessions = CollectionViewSource.GetDefaultView(arenaSessions);
            ArenaSessions.SortDescriptions.Add(new SortDescription("StartDate", ListSortDirection.Descending));
            dateFilter.From = DateTime.Now.AddMonths(-1).SetToBeginOfDay();
            totals          = new ArenaSessionTotalsModel();
            servers.Insert(0, new ServerItemModel(""));
            Busy = new BusyWatcher();
            ItemsDragDropCommand = new RelayCommand <DataGridDragDropEventArgs>(
                args => DragDropItem(args),
                args => args != null &&
                args.TargetObject != null &&
                args.DroppedObject != null &&
                args.Effects != DragDropEffects.None);
            PropertyChanged += OnPropertyChanged;
        }
        public ChartsViewModel(
            IEventAggregator events,
            Func <HearthStatsDbContext> dbContext,
            IRepository <GameResult> gameRepository,
            IRepository <ArenaSession> arenaRepository,
            IDeckManager deckManager,
            [ImportMany] IEnumerable <IChartTab> chartTabs)
        {
            this.events          = events;
            this.dbContext       = dbContext;
            this.gameRepository  = gameRepository;
            this.arenaRepository = arenaRepository;
            this.deckManager     = deckManager;
            Order       = 4;
            DisplayName = "Charts";
            Busy        = new BusyWatcher();
            servers.Insert(0, new ServerItemModel(""));

            Items.AddRange(chartTabs.OrderBy(x => x.Order));
            ActivateItem(Items.FirstOrDefault());

            dateFilter.From         = DateTime.Now.AddMonths(-1).SetToBeginOfDay();
            dateFilter.DateChanged += DateFilterOnPropertyChanged;
            PropertyChanged        += OnPropertyChanged;
        }
Beispiel #6
0
        internal void AddPreviousMessages(IEnumerable <ChatMessageViewModel> messages)
        {
            bool hasUpdates = false;

            _messages.IsNotifying = false;

            foreach (var chatMessage in messages.Reverse())
            {
                chatMessage.HasBeenSeen = true;
                var firstMessageGroup = _messages.FirstOrDefault() as ChatMessageGroupViewModel;
                if (firstMessageGroup == null || !firstMessageGroup.TryAddPreviousMessage(chatMessage))
                {
                    var groupMessage = new ChatMessageGroupViewModel(chatMessage);
                    _messages.Insert(0, groupMessage);

                    hasUpdates = true;
                }
            }

            _messages.IsNotifying = true;

            if (hasUpdates)
            {
                _messages.Refresh();
            }

            IsRequestingPreviousMessages = false;
        }
        public bool TryAddPreviousMessage(ChatMessageViewModel message)
        {
            if (!ReferenceEquals(message.User, User))
            {
                return(false);
            }

            _messages.Insert(0, message);
            MessageDateTime = message.MessageDateTime;
            MessageId       = message.MessageId;
            return(true);
        }
Beispiel #8
0
        public LatestGamesViewModel(IEventAggregator events, IRepository <GameResult> gameRepository, IDeckManager deckManager, Func <HearthStatsDbContext> dbContext, GameManager gameManager)
        {
            IsNotifying         = false;
            this.events         = events;
            this.gameRepository = gameRepository;
            this.deckManager    = deckManager;
            this.dbContext      = dbContext;
            this.gameManager    = gameManager;
            this.Order          = 1;
            this.DisplayName    = "Games";
            this.events.Subscribe(this);
            this.totals   = new GameResultTotalsModel();
            gameResultsCV = CollectionViewSource.GetDefaultView(this.gameResults);

            gameResultsCV.SortDescriptions.Add(new SortDescription("Started", ListSortDirection.Descending));
            servers.Insert(0, new ServerItemModel(""));

            dateFilter.From         = DateTime.Now.AddMonths(-1).SetToBeginOfDay();
            Busy                    = new BusyWatcher();
            dateFilter.DateChanged += DateFilterOnPropertyChanged;
            this.PropertyChanged   += this.OnPropertyChanged;
        }
        public StatisticsViewModel(Func <HearthStatsDbContext> dbContext,
                                   IRepository <GameResult> gameRepository,
                                   IRepository <ArenaSession> arenaRepository,
                                   [ImportMany] IEnumerable <IStatsViewModel> statsViewModels)
        {
            IsNotifying          = false;
            this.dbContext       = dbContext;
            this.gameRepository  = gameRepository;
            this.arenaRepository = arenaRepository;
            DisplayName          = Header = "Statistics";
            Order                   = 3;
            dateFilter.From         = DateTime.Now.AddMonths(-1);
            dateFilter.DateChanged += dateFilter_PropertyChanged;
            SelectedFilterType      = FilterTypes.First();

            foreach (var statsViewModel in statsViewModels)
            {
                Items.Add(statsViewModel);
            }
            servers.Insert(0, new ServerItemModel(""));
            Busy             = new BusyWatcher();
            PropertyChanged += OnPropertyChanged;
        }
Beispiel #10
0
 public void Undo() => target.Insert(index, removed);
Beispiel #11
0
 public void Redo() => target.Insert(index, added);
Beispiel #12
0
 internal void LogError(string message, DateTime dateTime)
 {
     exceptions.Insert(0, new ExceptionViewModel(message.Replace("\r\n", " "), dateTime));
 }