Exemple #1
0
        private void RemoveCommandExecute(object o)
        {
            HierarchicalResultViewModel vm = Hierarchical.Selected;

            if (vm == null)
            {
                return;
            }

            ICardCollection sourceCollection = _magicDatabase.GetAllCollections().First(cc => cc.Name == Hierarchical.Name);

            InputViewModel questionViewModel = InputViewModelFactory.Instance.CreateQuestionViewModel("Remove", string.Format("Remove selected from {0}?", sourceCollection.Name));

            OnInputRequested(questionViewModel);

            if (questionViewModel.Result == true)
            {
                using (_magicDatabaseForCardInCollection.BatchMode())
                {
                    foreach (ICardInCollectionCount cicc in GetCardInCollectionInSelected(vm, sourceCollection))
                    {
                        ICardCount cardCount = new CardCount();
                        foreach (KeyValuePair <ICardCountKey, int> kv in cicc.GetCardCount())
                        {
                            cardCount.Add(kv.Key, -kv.Value);
                        }

                        _magicDatabaseForCardInCollection.InsertOrUpdateCardInCollection(sourceCollection.Id, cicc.IdGatherer, cicc.IdLanguage, cardCount);
                    }
                }

                LoadCardsHierarchy();
            }
        }
Exemple #2
0
        public void MakeHierarchy(IHierarchicalInfoAnalyser[] analysers, bool[] orders)
        {
            CardViewModel saveSelected = null;

            if (Selected is HierarchicalResultNodeViewModel selected)
            {
                saveSelected = selected.Card;
            }

            _buildingRoot.Children.Clear();
            _globalStatictics.Reset();

            foreach (CardViewModel card in _getCardViewModels(Name))
            {
                MakeHierarchy(analysers, orders, card);
                _globalStatictics.Add(card);
            }

            Root = (new List <HierarchicalResultViewModel> {
                _buildingRoot
            });

            if (saveSelected != null)
            {
                HierarchicalResultNodeViewModel bestmatch = FindBestName(_buildingRoot, saveSelected);
                if (bestmatch != null)
                {
                    Selected = bestmatch;
                }
            }
        }
Exemple #3
0
 public HierarchicalViewModel(string name, Func <string, IEnumerable <CardViewModel> > getCardViewModels)
 {
     Name = name;
     _globalStatictics  = new GlobalStatictics(name);
     _getCardViewModels = getCardViewModels;
     _buildingRoot      = new HierarchicalResultViewModel(name);
     Root = new List <HierarchicalResultViewModel>();
 }
Exemple #4
0
        private void MakeHierarchy(IHierarchicalInfoAnalyser[] analysers, bool[] orders, CardViewModel card)
        {
            HierarchicalResultViewModel current = _buildingRoot;

            for (int index = 0; index <= analysers.Length; index++)
            {
                IList <HierarchicalResultViewModel> children = current.Children;
                HierarchicalResultViewModel         next     = null;

                IComparable value = index < analysers.Length ? analysers[index].Analyse(card) : card.Name;

                bool isAscendentOrder = index >= orders.Length || orders[index];
                int  i;

                for (i = 0; i < children.Count; i++)
                {
                    int result = value.CompareTo(children[i].Value);
                    if (result == 0)
                    {
                        next = children[i];
                        break;
                    }

                    if ((result < 0) == isAscendentOrder)
                    {
                        break;
                    }
                }

                if (next == null)
                {
                    next = index < analysers.Length ? new HierarchicalResultViewModel(value) : new HierarchicalResultNodeViewModel(value);
                    current.Children.Insert(i, next);
                }

                if (index == analysers.Length)
                {
                    // ReSharper disable PossibleNullReferenceException
                    (next as HierarchicalResultNodeViewModel).AddCard(card);
                    // ReSharper restore PossibleNullReferenceException
                }

                current = next;
            }
        }
Exemple #5
0
        private HierarchicalResultNodeViewModel FindBestName(HierarchicalResultViewModel toInspect, CardViewModel saveSelected)
        {
            if (toInspect == null || saveSelected == null)
            {
                return(null);
            }

            HierarchicalResultNodeViewModel res    = null;
            HierarchicalResultNodeViewModel nodevm = toInspect as HierarchicalResultNodeViewModel;
            Matching resMatch = FindBestMatch(nodevm, saveSelected);

            if (resMatch == Matching.Full)
            {
                return(nodevm);
            }

            if (resMatch == Matching.Name)
            {
                res = nodevm;
            }

            foreach (HierarchicalResultViewModel child in toInspect.Children)
            {
                nodevm = FindBestName(child, saveSelected);

                resMatch = FindBestMatch(nodevm, saveSelected);
                if (resMatch == Matching.Full)
                {
                    return(nodevm);
                }

                if (resMatch == Matching.Name && res == null)
                {
                    res = nodevm;
                }
            }

            return(res);
        }