示例#1
0
        public StatisticViewModel(ICardInCollectionCount cardInCollectionCount)
        {
            IMagicDatabaseReadOnly magicDatabase = MagicDatabaseManager.ReadOnly;

            FoilAltArtNumber = cardInCollectionCount.FoilAltArtNumber;
            AltArtNumber     = cardInCollectionCount.AltArtNumber;
            FoilNumber       = cardInCollectionCount.FoilNumber;
            Number           = cardInCollectionCount.Number;
            Collection       = magicDatabase.GetCollection(cardInCollectionCount.IdCollection).Name;
            Edition          = magicDatabase.GetEdition(cardInCollectionCount.IdGatherer).Name;
            Language         = magicDatabase.GetLanguage(cardInCollectionCount.IdLanguage).Name;
        }
示例#2
0
        public void Export(string[] collectionNames, string outpath, ExportFormat exportFormatSelected)
        {
            if (!Directory.Exists(outpath))
            {
                throw new ArgumentException("output path doesn't exist", nameof(outpath));
            }

            IImportExportFormatter formatter = ImportExportFormatterFactory.Create(exportFormatSelected);

            if (formatter == null)
            {
                throw new ArgumentException("Can't find appropriate formatter for " + exportFormatSelected, nameof(exportFormatSelected));
            }

            IMagicDatabaseReadOnly magicDatabase = MagicDatabaseManager.ReadOnly;

            foreach (string collectionName in collectionNames)
            {
                ICardCollection cardcollection = magicDatabase.GetCollection(collectionName);
                IEnumerable <ICardInCollectionCount> cardsInCollection = magicDatabase.GetCardCollection(cardcollection);

                if (cardsInCollection == null)
                {
                    throw new ImportExportException("Can't find collection named {0}", collectionName);
                }

                string filePath = Path.Combine(outpath, collectionName + formatter.Extension);

                try
                {
                    using (StreamWriter sw = new StreamWriter(filePath, false))
                    {
                        sw.Write(formatter.ToFile(cardsInCollection));
                    }
                }
                catch (ImportExportException)
                {
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }

                    throw;
                }
            }
        }
示例#3
0
        private IEnumerable <AuditInfo> GetAudit()
        {
            foreach (IAudit audit in _allAudit.Where(a => a.OperationDate >= MinDate && a.OperationDate < MaxDate.AddDays(1)))
            {
                AuditInfo info = new AuditInfo
                {
                    Quantity      = audit.Quantity,
                    OperationDate = audit.OperationDate.ToLocalTime().ToString("G"),
                    IsFoil        = audit.IsFoil.HasValue && audit.IsFoil.Value,
                    IsAltArt      = audit.IsAltArt.HasValue && audit.IsAltArt.Value,
                };

                ICardCollection cardCollection = _magicDatabase.GetCollection(audit.IdCollection);
                info.CollectionName = cardCollection == null ? "(Deleted) " + audit.IdCollection : cardCollection.Name;

                if (audit.IdGatherer.HasValue)
                {
                    ICard card = _magicDatabase.GetCard(audit.IdGatherer.Value);
                    if (card == null)
                    {
                        info.CardName    = "(Not found) " + audit.IdGatherer.Value;
                        info.EditionName = "(Not found) " + audit.IdGatherer.Value;
                    }
                    else
                    {
                        info.CardName = card.Name;
                        IEdition edition = _magicDatabase.GetEdition(audit.IdGatherer.Value);
                        info.EditionName = edition == null ? "(Not found) " + audit.IdGatherer.Value : edition.Name;
                    }
                    if (audit.IdLanguage.HasValue)
                    {
                        ILanguage language = _magicDatabase.GetLanguage(audit.IdLanguage.Value);
                        info.Language = language == null ? "(Not found) " + audit.IdLanguage.Value : language.Name;
                    }
                    else
                    {
                        info.Language = "(Missing language)";
                    }
                }

                yield return(info);
            }
        }