コード例 #1
0
        public async Task <ImportStatus> Import(Set set, IEnumerable <Card> cards)
        {
            if (set == null)
            {
                throw new ArgumentNullException("set");
            }

            if (cards == null)
            {
                throw new ArgumentNullException("cards");
            }

            var status = new ImportStatus();

            var setInserted = this.mStore.SetFindAndModify(set);

            if (setInserted.Result == null)
            {
                this.mLoggingService.Warning("Set '{0}' not inserted.", set.Name);

                return(null);
            }

            status.ImportedSet = setInserted.Result;

            List <Card> inserted_Cards = new List <Card>();
            List <Card> failed_Cards   = new List <Card>();

            foreach (Card card in cards)
            {
                this.mLoggingService.Debug("Read card '{0}'...", card.Name);

                var cardInserted = this.mStore.CardFindAndModify(card);

                if (cardInserted.Result != null)
                {
                    this.mLoggingService.Info("Card '{0}' in set '{1}' inserted!",
                                              cardInserted.Result.Name,
                                              setInserted.Result.Name);

                    inserted_Cards.Add(cardInserted.Result);
                }
                else
                {
                    this.mLoggingService.Warning("Card '{0}' in set '{1}' failed to inserted!",
                                                 card.Name,
                                                 setInserted.Result.Name);

                    failed_Cards.Add(card);
                }
            }

            status.ImportedCards = inserted_Cards;
            status.FailedCards   = failed_Cards;

            return(status);
        }
コード例 #2
0
        public async Task <ImportStatus> Import(Set set, IEnumerable <Card> cards)
        {
            if (set == null)
            {
                throw new ArgumentNullException("set");
            }

            if (cards == null)
            {
                throw new ArgumentNullException("cards");
            }

            var status = new ImportStatus();

            var setInserted = this.mStore.SetFindAndModify(set);

            if (setInserted.Result == null)
            {
                this.mLoggingService.Warning("Set '{0}' not inserted.", set.Name);

                return(null);
            }

            status.ImportedSet = setInserted.Result;

            List <Card> inserted_Cards = new List <Card>();
            List <Card> failed_Cards   = new List <Card>();

            foreach (Card card in cards)
            {
                this.mLoggingService.Debug("Read card '{0}'...", card.Name);

                // Don't import card if multiverseId is 0
                if (card.MultiverseId == 0)
                {
                    this.mLoggingService.Warning("Not importing card '{0}' since multiverseId is '0'!", card.Name);

                    continue;
                }

                var cardInserted = this.mStore.CardFindAndModify(card);

                if (cardInserted.Result != null)
                {
                    this.mLoggingService.Info("Card '{0}' in set '{1}' inserted!",
                                              cardInserted.Result.Name,
                                              setInserted.Result.Name);

                    inserted_Cards.Add(cardInserted.Result);
                }
                else
                {
                    this.mLoggingService.Warning("Card '{0}' in set '{1}' failed to inserted!",
                                                 card.Name,
                                                 setInserted.Result.Name);

                    failed_Cards.Add(card);
                }
            }

            // If no cards were imported, remove the imported set
            if (!inserted_Cards.Any())
            {
                var deleted = this.mStore.RemoveSet(set);

                status.ImportedCards = new List <Card>();
                status.FailedCards   = failed_Cards;
            }
            else
            {
                status.ImportedCards = inserted_Cards;
                status.FailedCards   = failed_Cards;
            }



            return(status);
        }