diff --git a/MainWindow.xaml b/MainWindow.xaml index 64f2830..7ed98c3 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -8,7 +8,7 @@ Title="MainWindow" Height="718" Width="800"> - + diff --git a/Records.cs b/Records.cs index 1969734..6e14e20 100644 --- a/Records.cs +++ b/Records.cs @@ -3,10 +3,11 @@ namespace Txt2Bib.Records { public interface IBib { } + public record class ArticleBib : IBib { public string Type { get; init; } = "article"; - public string[] Author { get; init; } = { "" }; + public string[] Author { get; init; } = { "Gianni e Pinotto" }; public string Title { get; init; } = ""; public string Journal { get; init; } = ""; public ushort Year { get; init; } = 1950; @@ -17,13 +18,32 @@ namespace Txt2Bib.Records public override string ToString() { - return $"@{Type}\\{{{Author[0][..5]}_{Year}," + - $"\ttitle = \"{Title}\"," + - $"\tjournal = \"{Journal}\"," + - $"\tyear = \"{Year}\"," + - $"\tvolume = \"{Volume}\"," + - $"\tnumber = \"{Issue}\"," + - $"\tpages = \"{FirstPage}--{LastPage}\","; + return $"@{Type}" + "{" +$"{Author[0][..5]}_{Year},\n" + + $"\ttitle = \"{Title}\",\n" + + $"\tjournal = \"{Journal}\",\n" + + $"\tyear = \"{Year}\",\n" + + $"\tvolume = \"{Volume}\",\n" + + $"\tnumber = \"{Issue}\",\n" + + $"\tpages = \"{FirstPage}--{LastPage}\",\n" + + "}\n"; + } + } + + public record class BookBib : IBib + { + public string Type { get; init; } = "book"; + public string[] Author { get; init; } = { "Gianni e Pinotto" }; + public string Title { get; init; } = ""; + public string Publisher { get; init; } = ""; + public ushort Year { get; init; } = 1950; + + public override string ToString() + { + return $"@{Type}" + "{" +$"{Author[0][..5]}_{Year},\n" + + $"\ttitle = \"{Title}\",\n" + + $"\tpublisher = \"{Publisher}\",\n" + + $"\tyear = \"{Year}\",\n" + + "}\n"; } } } \ No newline at end of file diff --git a/Text2Bib.cs b/Text2Bib.cs index 49d444f..6a33db2 100644 --- a/Text2Bib.cs +++ b/Text2Bib.cs @@ -41,12 +41,12 @@ namespace Txt2Bib var entries = result.Split('%').ToList().Select(entry => { - return Process(entry); + return Process(entry).ToString(); }); foreach (var entry in entries) { - output += entries; + output += entry; } return output; @@ -54,7 +54,21 @@ namespace Txt2Bib private IBib Process(string entryFromTxt) { - return new ArticleBib(); + var lines = entryFromTxt.Trim().Split("\n"); + var type = lines.First(); + + System.Diagnostics.Debug.WriteLine($"Entry: {entryFromTxt}; Prima riga: {type}"); + + IBib citType = type switch + { + "J" => new ArticleBib(), + "B" => new BookBib(), + //"C" => new ChapterBib(), + //"P" => new ConferenceBib(), + _ => new ArticleBib(), + }; + + return citType; } ///