public async Task <IActionResult> Create([Bind("Id,Name")] BibliographyStyle style)
        {
            if (ModelState.IsValid)
            {
                _context.Add(style);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Edit), new { id = style.Id }));
            }
            return(View(style));
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        /// <exception cref="InvalidOperationException ">The TexFilePath must be provided prior to calling this method.</exception>
        /// <exception cref="DirectoryNotFoundException">The directory containing the TexFilePath, BibFilePath and StyleFilePath must exist.</exception>
        /// <exception cref="FileNotFoundException">The files at TexFilePath, BibFilePath and StyleFilePath (if provided) must exist.</exception>
        public Bibliography Build()
        {
            _logger.LogTrace("Starting build of bibliography.");

            if (!_auxFileParsed)
            {
                if (TexFilePath == null)
                {
                    throw new InvalidOperationException("TexFilePath cannot be null!");
                }
                else if (BibFilePath == null)
                {
                    throw new InvalidOperationException("BibFilePath cannot be null!");
                }
                else if (BibliographyStyle == null && StyleFilePath == null)
                {
                    throw new InvalidOperationException("Either the BibliographyStyle, or the StyleFilePath cannot be null!");
                }

                _fileManager.ThrowIfFileDoesNotExist(BibFilePath);
                _fileManager.ThrowIfFileDoesNotExist(TexFilePath);

                if (StyleFilePath != null)
                {
                    _fileManager.ThrowIfFileDoesNotExist(StyleFilePath);
                }

                _auxPath    = _fileManager.ReplaceExtension(TexFilePath, "aux");
                _auxEntries = _auxParser.ParseFile(_auxPath).ToList();
            }

            if (BibliographyStyle == null && StyleFilePath != null)
            {
                try
                {
                    BibliographyStyle = JsonConvert.DeserializeObject <BibliographyStyle>(_fileManager.ReadFileContents(StyleFilePath));
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "An error occurred parsing the style file.");
                    throw;
                }
            }

            var bibtexDatabase = _bibParser.ParseFile(BibFilePath);
            var bibliography   = new Bibliography(_fileManager, _bibliographyLogger, BibliographyStyle.OrderBy)
            {
                TargetPath    = _fileManager.ReplaceExtension(TexFilePath, "bbl"),
                TargetAuxPath = _auxPath,
                Preambles     = bibtexDatabase.Preambles.Select(x => x.Content).ToList(),
                Bibitems      = BibliographyStyle.OrderBy switch
                {
                    BibliographyOrder.AuthorLastName => GetBibitemsOrderedByFirstAuthorLastName(bibtexDatabase),
                    BibliographyOrder.Title => GetBibitemsOrderedByTitle(bibtexDatabase),
                    _ => GetBibitemsInOrderOfAppearance(bibtexDatabase).ToList()
                }
            };

            PerformStringSubstitutions(bibliography, bibtexDatabase);

            _logger.LogTrace("Bibliography build completed.");

            return(bibliography);
        }