Example #1
0
        public ImportStatus ImportToExistingCollection(string importFilePath, string collectionToCompletName)
        {
            IMagicDatabaseReadAndWriteCardInCollection magicDatabaseCollection = MagicDatabaseManager.ReadAndWriteCardInCollection;
            ICardCollection collection = magicDatabaseCollection.GetCollection(collectionToCompletName);

            if (collection == null)
            {
                throw new ArgumentException("Collection name doesn't exist", nameof(collectionToCompletName));
            }

            return(ImportToCollection(importFilePath, collection));
        }
Example #2
0
        public CardInputViewModel(string name, int defaultQuantity)
        {
            _magicDatabase          = MagicDatabaseManager.ReadAndWriteCardInCollection;
            _magicDatabaseForOption = MagicDatabaseManager.ReadAndWriteOption;
            _defaultQuantity        = defaultQuantity;

            //Set directly field and not property to avoid save the retrieve value
            IOption option = _magicDatabaseForOption.GetOption(TypeOfOption.Input, "Mode");

            if (option != null)
            {
                if (Enum.TryParse(option.Value, out InputMode mode))
                {
                    _inputMode = mode;
                }
            }

            option = _magicDatabaseForOption.GetOption(TypeOfOption.Input, "Language");
            if (option != null)
            {
                if (int.TryParse(option.Value, out int id))
                {
                    _inputLanguage = _magicDatabase.GetLanguage(id);
                }
            }

            Display.Title              = "Input cards";
            Display.OkCommandLabel     = "Add";
            Display.CancelCommandLabel = "Close";
            ChangeCollectionCommand    = new RelayCommand(ChangeCollectionCommandExecute);
            ChangeInputLanguageCommand = new RelayCommand(ChangeInputLanguageCommandExecute);
            IncreaseQuantityCommand    = new RelayCommand(IncreaseQuantityCommandExecute);

            _allCardInfos = _magicDatabase.GetAllInfos().ToArray();
            _collections  = _magicDatabase.GetAllCollections().ToArray();
            SelectCardCollection(name);

            _allLanguages = _magicDatabase.GetAllLanguages().ToArray();

            Cards = new RangeObservableCollection <string>();

            _allEditions = _magicDatabase.GetAllEditionsOrdered();
            Editions     = new RangeObservableCollection <IEdition>();

            Languages = new RangeObservableCollection <ILanguage>();

            RebuildOrder();
            InitWindow();
        }
Example #3
0
        private ImportStatus ImportToCollection(string importFilePath, ICardCollection collection)
        {
            ImportStatus status = ImportStatus.BuildStatus(GetImport(importFilePath));

            IMagicDatabaseReadAndWriteCardInCollection magicDatabase = MagicDatabaseManager.ReadAndWriteCardInCollection;

            using (magicDatabase.BatchMode())
            {
                //Add in database the good one
                foreach (IImportExportCardCount importExportCardCount in status.ReadyToBeInserted)
                {
                    magicDatabase.InsertOrUpdateCardInCollection(collection.Id, importExportCardCount.IdGatherer, importExportCardCount.IdLanguage, importExportCardCount.GetCardCount());
                }
            }

            return(status);
        }
Example #4
0
        //TODO: Test add/remove splitted card and statistics
        public MainViewModel(IDispatcherInvoker dispatcherInvoker)
        {
            AddLinkedProperty(nameof(Hierarchical), nameof(Title));

            HideResultCommand  = new RelayCommand(o => UpgradeStatus = UpgradeStatus.NotChecked);
            _dispatcherInvoker = dispatcherInvoker;
            _allhierarchical   = new HierarchicalViewModel(MagicCards, AllCardAsViewModel);

            _magicDatabase                    = MagicDatabaseManager.ReadOnly;
            _magicDatabaseForOption           = MagicDatabaseManager.ReadAndWriteOption;
            _magicDatabaseForCollection       = MagicDatabaseManager.ReadAndWriteCollection;
            _magicDatabaseForCardInCollection = MagicDatabaseManager.ReadAndWriteCardInCollection;

            Options         = new OptionsViewModel(_magicDatabaseForOption);
            _programUpdater = new ProgramUpgrader();
            UpgradeStatus   = _programUpdater.Status;

            if (Options.AutoCheckUpgrade)
            {
                ThreadPool.QueueUserWorkItem(DoCheckNewVersion);
            }

            Analysers        = new HierarchicalInfoAnalysersViewModel();
            _menuRoot        = new MenuViewModel();
            _contextMenuRoot = new MenuViewModel();

            CreateMenu();

            //Reload last chosen option
            IOption option = _magicDatabase.GetOption(TypeOfOption.SelectedCollection, "Name");

            if (option != null)
            {
                LoadCollection(option.Value);
            }
            else
            {
                LoadCollection();
            }
        }
Example #5
0
        public CollectionInputGraphicViewModel(string name)
        {
            _magicDatabase          = MagicDatabaseManager.ReadAndWriteCardInCollection;
            _magicDatabaseForOption = MagicDatabaseManager.ReadAndWriteOption;

            IOption option = _magicDatabaseForOption.GetOption(TypeOfOption.Input, "Language");

            if (option != null)
            {
                int id;
                if (int.TryParse(option.Value, out id))
                {
                    _inputLanguage = _magicDatabase.GetLanguage(id);
                }
            }
            option = _magicDatabaseForOption.GetOption(TypeOfOption.Input, "Order");
            if (option != null)
            {
                if (Enum.TryParse(option.Value, out DisplayOrder order))
                {
                    _displayOrder = order;
                }
            }
            option = _magicDatabaseForOption.GetOption(TypeOfOption.Input, "ImageSize");
            if (option != null)
            {
                int size;
                if (int.TryParse(option.Value, out size))
                {
                    _size = size;
                }
            }

            Display.Title              = "Input cards";
            Display.OkCommandLabel     = "Add";
            Display.CancelCommandLabel = "Close";

            _allCardInfos = _magicDatabase.GetAllInfos().ToArray();
            _allLanguages = _magicDatabase.GetAllLanguages().ToArray();

            Editions     = _magicDatabase.GetAllEditionsOrdered();
            _cards       = new RangeObservableCollection <CardCollectionInputGraphicViewModel>();
            Cards        = CollectionViewSource.GetDefaultView(_cards);
            Cards.Filter = ToDisplay;

            Colors        = (ShardColor[])Enum.GetValues(typeof(ShardColor));
            DisplayOrders = (DisplayOrder[])Enum.GetValues(typeof(DisplayOrder));
            Types         = ((CardType[])Enum.GetValues(typeof(CardType))).Where(t => t != CardType.Token).ToArray();

            ObservableCollection <ShardColor> colorsSelected = new ObservableCollection <ShardColor>();

            colorsSelected.CollectionChanged += CollectionChanged;
            ColorsSelected = colorsSelected;
            ObservableCollection <CardType> typesSelected = new ObservableCollection <CardType>();

            typesSelected.CollectionChanged += CollectionChanged;
            TypesSelected = typesSelected;
            ChangeInputLanguageCommand = new RelayCommand(ChangeInputLanguageCommandExecute);
            ResetCommand   = new RelayCommand(ResetCommandExecute);
            CardCollection = _magicDatabase.GetAllCollections().First(cc => cc.Name == name);
            AddLinkedProperty(nameof(InputLanguage), nameof(InputLanguageName));

            RebuildOrder();
        }