Processing stub

This commit is contained in:
Nicolò P 2023-12-21 16:23:20 +01:00
parent 74541f852e
commit 131cd2ea1b
3 changed files with 47 additions and 13 deletions

View File

@ -8,7 +8,7 @@
Title="MainWindow" Height="718" Width="800"> Title="MainWindow" Height="718" Width="800">
<Grid Background="#FF38383E" Margin="0,0,0,-16"> <Grid Background="#FF38383E" Margin="0,0,0,-16">
<TextBox x:Name="DropArea" Text="Trascinare qui i file txt da convertire" ToolTip="Trascinare qui i file txt da convertire" HorizontalAlignment="Left" Margin="48,82,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="526" Height="437" PreviewDragEnter="DropArea_PreviewDragEnter" PreviewDragOver="DropArea_PreviewDragOver" Drop="DropArea_Drop"/> <TextBox x:Name="DropArea" Text="Trascinare qui i file txt da convertire" ToolTip="Trascinare qui i file txt da convertire" HorizontalAlignment="Left" Margin="48,82,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="526" Height="437" PreviewDragEnter="DropArea_PreviewDragEnter" PreviewDragOver="DropArea_PreviewDragOver" Drop="DropArea_Drop"/>
<TextBox x:Name="Debug" IsEnabled="False" HorizontalAlignment="Center" Margin="0,572,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="710" Height="72" RenderTransformOrigin="0.449,1.525"/> <TextBox x:Name="Debug" VerticalScrollBarVisibility="Auto" IsEnabled="True" HorizontalAlignment="Left" Margin="48,571,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="710" Height="106" RenderTransformOrigin="0.449,1.525"/>
<Label Content="Txt2Bib" HorizontalAlignment="Center" Margin="0,10,0,0" VerticalAlignment="Top" Foreground="White" FontFamily="Eras ITC" FontSize="28"/> <Label Content="Txt2Bib" HorizontalAlignment="Center" Margin="0,10,0,0" VerticalAlignment="Top" Foreground="White" FontFamily="Eras ITC" FontSize="28"/>
<Button x:Name="GoBtn" Cursor="Hand" Content="Genera" HorizontalAlignment="Left" Margin="628,244,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Height="68" Width="127" Click="GoBtn_Click" BorderBrush="{x:Null}" Foreground="White" Background="#FF474671" FontFamily="Cascadia Code" FontSize="16"> <Button x:Name="GoBtn" Cursor="Hand" Content="Genera" HorizontalAlignment="Left" Margin="628,244,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Height="68" Width="127" Click="GoBtn_Click" BorderBrush="{x:Null}" Foreground="White" Background="#FF474671" FontFamily="Cascadia Code" FontSize="16">
<Button.RenderTransform> <Button.RenderTransform>
@ -20,7 +20,7 @@
</TransformGroup> </TransformGroup>
</Button.RenderTransform> </Button.RenderTransform>
</Button> </Button>
<Label Content="Output" HorizontalAlignment="Left" Margin="47,545,0,0" VerticalAlignment="Top" Foreground="White"/> <Label Content="Debug" HorizontalAlignment="Left" Margin="44,544,0,0" VerticalAlignment="Top" Foreground="White"/>
</Grid> </Grid>
</Window> </Window>

View File

@ -3,10 +3,11 @@
namespace Txt2Bib.Records namespace Txt2Bib.Records
{ {
public interface IBib { } public interface IBib { }
public record class ArticleBib : IBib public record class ArticleBib : IBib
{ {
public string Type { get; init; } = "article"; 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 Title { get; init; } = "";
public string Journal { get; init; } = ""; public string Journal { get; init; } = "";
public ushort Year { get; init; } = 1950; public ushort Year { get; init; } = 1950;
@ -17,13 +18,32 @@ namespace Txt2Bib.Records
public override string ToString() public override string ToString()
{ {
return $"@{Type}\\{{{Author[0][..5]}_{Year}," + return $"@{Type}" + "{" +$"{Author[0][..5]}_{Year},\n" +
$"\ttitle = \"{Title}\"," + $"\ttitle = \"{Title}\",\n" +
$"\tjournal = \"{Journal}\"," + $"\tjournal = \"{Journal}\",\n" +
$"\tyear = \"{Year}\"," + $"\tyear = \"{Year}\",\n" +
$"\tvolume = \"{Volume}\"," + $"\tvolume = \"{Volume}\",\n" +
$"\tnumber = \"{Issue}\"," + $"\tnumber = \"{Issue}\",\n" +
$"\tpages = \"{FirstPage}--{LastPage}\","; $"\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";
} }
} }
} }

View File

@ -41,12 +41,12 @@ namespace Txt2Bib
var entries = result.Split('%').ToList<string>().Select(entry => var entries = result.Split('%').ToList<string>().Select(entry =>
{ {
return Process(entry); return Process(entry).ToString();
}); });
foreach (var entry in entries) foreach (var entry in entries)
{ {
output += entries; output += entry;
} }
return output; return output;
@ -54,7 +54,21 @@ namespace Txt2Bib
private IBib Process(string entryFromTxt) 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;
} }
/// <summary> /// <summary>