4 Commits

4 changed files with 46 additions and 24 deletions

View File

@@ -34,7 +34,15 @@ namespace Txt2Bib
return; return;
} }
var txt2bib = new Text2Bib(); var txt2bib = new Text2Bib();
var result = txt2bib.Generate(DropArea.Text); var result = "";
try
{
result = txt2bib.Generate(DropArea.Text);
}
catch (Exception ex)
{
MessageBox.Show($"Errore di esecuzione: {ex.Message}");
}
Debug.Text = result; Debug.Text = result;
using var outputFile = new StreamWriter($@"{OutputDir}\output_bibtex.bib"); using var outputFile = new StreamWriter($@"{OutputDir}\output_bibtex.bib");
outputFile.Write(result); outputFile.Write(result);
@@ -55,7 +63,7 @@ namespace Txt2Bib
if (dataObject.ContainsFileDropList()) if (dataObject.ContainsFileDropList())
{ {
// Clear values // Clear values
DropArea.Text = string.Empty; if (DropArea.Text == InitialDropText) DropArea.Text = string.Empty;
// Process file names // Process file names
var fileNames = dataObject.GetFileDropList(); var fileNames = dataObject.GetFileDropList();
@@ -65,7 +73,7 @@ namespace Txt2Bib
bd.Append(fileName + "\n"); bd.Append(fileName + "\n");
} }
// Set text // Set text
DropArea.Text = bd.ToString(); DropArea.Text += bd.ToString();
} }
} }
@@ -89,6 +97,7 @@ namespace Txt2Bib
private void GoBtn_Click(object sender, RoutedEventArgs e) private void GoBtn_Click(object sender, RoutedEventArgs e)
{ {
Execute(); Execute();
MessageBox.Show("File BibTeX generato correttamente.", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
} }
private void CopyDebug_Click(object sender, RoutedEventArgs e) private void CopyDebug_Click(object sender, RoutedEventArgs e)

View File

@@ -153,10 +153,12 @@ namespace Txt2Bib.Records
{ {
public string Type { get; init; } = "inproceedings"; public string Type { get; init; } = "inproceedings";
public string[] Author { get; set; } = Array.Empty<string>(); public string[] Author { get; set; } = Array.Empty<string>();
public string[] Editor { get; set; } = Array.Empty<string>();
public string Title { get; set; } = ""; public string Title { get; set; } = "";
public string BookTitle { get; set; } = ""; public string BookTitle { get; set; } = "";
public ushort Year { get; set; } = 1950; public ushort Year { get; set; } = 1950;
public string Publisher { get; set; } = ""; public string Publisher { get; set; } = "";
public string Series { get; set; } = "";
public string Address { get; set; } = ""; public string Address { get; set; } = "";
public ushort FirstPage { get; set; } = 1; public ushort FirstPage { get; set; } = 1;
public ushort LastPage { get; set; } = 1; public ushort LastPage { get; set; } = 1;
@@ -168,23 +170,27 @@ namespace Txt2Bib.Records
Author = entryLines[1].Split(',').Select(a => Rearrange(a)).ToArray(); Author = entryLines[1].Split(',').Select(a => Rearrange(a)).ToArray();
Year = ushort.Parse(entryLines[2]); Year = ushort.Parse(entryLines[2]);
Title = entryLines[3]; Title = entryLines[3];
BookTitle = entryLines[4]; Editor = entryLines[4] != String.Empty ?
Address = entryLines[5] != String.Empty ? entryLines[5] : Address; Regex.Replace(entryLines[4], @"\(eds?\.\)", "").Split(',').Select(a => Rearrange(a)).ToArray() :
Publisher = entryLines[6]; Editor;
BookTitle = entryLines[5];
Series = entryLines[6] != String.Empty ? entryLines[6] : Series;
Address = entryLines[7] != String.Empty ? entryLines[7] : Address;
Publisher = entryLines[8];
try try
{ {
FirstPage = ushort.Parse(entryLines[7].Split('-')[0]); FirstPage = ushort.Parse(entryLines[9].Split('-')[0]);
LastPage = ushort.Parse(entryLines[7].Split('-')[1].TrimEnd('.')); LastPage = ushort.Parse(entryLines[9].Split('-')[1].TrimEnd('.'));
} }
catch (Exception) catch (Exception)
{ {
throw; throw new Exception("Formato numeri di pagina errato...");
} }
if (entryLines.Length > 8 ) if (entryLines.Length > 10)
{ {
if (IsDoi(entryLines[8])) Doi = entryLines[8]; if (IsDoi(entryLines[10])) Doi = entryLines[10];
else Url = entryLines[8]; else Url = entryLines[10];
} }
return ToString(); return ToString();
@@ -194,12 +200,16 @@ namespace Txt2Bib.Records
{ {
string label = Author[0][..5].Replace(". ", ""); string label = Author[0][..5].Replace(". ", "");
string authString = $"\tauthor = \"{string.Join(" and ", Author)}\",\n"; string authString = $"\tauthor = \"{string.Join(" and ", Author)}\",\n";
string edsString = Editor.Length != 0 ?
$"\teditor = \"{string.Join(" and ", Editor)}\",\n" : "";
return $"@{Type}{{{label}_{Year},\n" + return $"@{Type}{{{label}_{Year},\n" +
authString + authString +
edsString +
$"\ttitle = {{{Title}}},\n" + $"\ttitle = {{{Title}}},\n" +
$"\tbooktitle = {{{BookTitle}}},\n" + $"\tbooktitle = {{{BookTitle}}},\n" +
$"\tpublisher = \"{Publisher}\",\n" + $"\tpublisher = \"{Publisher}\",\n" +
$"\tseries = {{{Series}}},\n" +
$"\taddress = \"{Address}\",\n" + $"\taddress = \"{Address}\",\n" +
$"\tyear = \"{Year}\",\n" + $"\tyear = \"{Year}\",\n" +
$"\tpages = \"{FirstPage}--{LastPage}\",\n" + $"\tpages = \"{FirstPage}--{LastPage}\",\n" +
@@ -218,6 +228,7 @@ namespace Txt2Bib.Records
public string BookTitle { get; set; } = ""; public string BookTitle { get; set; } = "";
public ushort Year { get; set; } = 1950; public ushort Year { get; set; } = 1950;
public string Publisher { get; set; } = ""; public string Publisher { get; set; } = "";
public string Series { get; set; } = "";
public string Address { get; set; } = ""; public string Address { get; set; } = "";
public ushort FirstPage { get; set; } = 1; public ushort FirstPage { get; set; } = 1;
public ushort LastPage { get; set; } = 1; public ushort LastPage { get; set; } = 1;
@@ -229,24 +240,25 @@ namespace Txt2Bib.Records
Author = entryLines[1].Split(',').Select(a => Rearrange(a)).ToArray(); Author = entryLines[1].Split(',').Select(a => Rearrange(a)).ToArray();
Year = ushort.Parse(entryLines[2]); Year = ushort.Parse(entryLines[2]);
Title = entryLines[3]; Title = entryLines[3];
Editor = entryLines[4].Replace("(eds.)", "").Split(',').Select(a => Rearrange(a)).ToArray(); Editor = Regex.Replace(entryLines[4], @"\(eds?\.\)", "").Split(',').Select(a => Rearrange(a)).ToArray();
BookTitle = entryLines[5]; BookTitle = entryLines[5];
Address = entryLines[6] != String.Empty ? entryLines[6] : Address; Series = entryLines[6] != String.Empty ? entryLines[6] : Series;
Publisher = entryLines[7]; Address = entryLines[7] != String.Empty ? entryLines[7] : Address;
Publisher = entryLines[8];
try try
{ {
FirstPage = ushort.Parse(entryLines[8].Split('-')[0]); FirstPage = ushort.Parse(entryLines[9].Split('-')[0]);
LastPage = ushort.Parse(entryLines[8].Split('-')[1].TrimEnd('.')); LastPage = ushort.Parse(entryLines[9].Split('-')[1].TrimEnd('.'));
} }
catch (Exception) catch (Exception)
{ {
throw; throw new Exception("Formato numeri di pagina errato...");
} }
if (entryLines.Length > 9) if (entryLines.Length > 10)
{ {
if (IsDoi(entryLines[9])) Doi = entryLines[9]; if (IsDoi(entryLines[10])) Doi = entryLines[10];
else Url = entryLines[9]; else Url = entryLines[10];
} }
return ToString(); return ToString();
@@ -264,6 +276,7 @@ namespace Txt2Bib.Records
$"\ttitle = {{{Title}}},\n" + $"\ttitle = {{{Title}}},\n" +
$"\tbooktitle = {{{BookTitle}}},\n" + $"\tbooktitle = {{{BookTitle}}},\n" +
$"\tpublisher = \"{Publisher}\",\n" + $"\tpublisher = \"{Publisher}\",\n" +
$"\tseries = {{{Series}}},\n" +
$"\taddress = \"{Address}\",\n" + $"\taddress = \"{Address}\",\n" +
$"\tyear = \"{Year}\",\n" + $"\tyear = \"{Year}\",\n" +
$"\tpages = \"{FirstPage}--{LastPage}\",\n" + $"\tpages = \"{FirstPage}--{LastPage}\",\n" +

View File

@@ -15,7 +15,7 @@ namespace Txt2Bib
/// </summary> /// </summary>
public class Text2Bib public class Text2Bib
{ {
private string[] _citTypes = { "J", "B", "C", "P" }; private readonly string[] _citTypes = { "J", "B", "C", "P" };
/// <summary> /// <summary>
/// Generate single .bib file from input text files /// Generate single .bib file from input text files
@@ -52,7 +52,7 @@ namespace Txt2Bib
} }
catch (Exception) catch (Exception)
{ {
throw; throw new Exception($"Errore di elaborazione in {entries.Last()}");
} }
var bibtex = ""; var bibtex = "";

View File

@@ -5,7 +5,7 @@
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
<Version>0.1.2</Version> <Version>0.1.7</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>