-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b36a24
commit 24169c8
Showing
54 changed files
with
2,462 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace LibgenDesktop.Models.Entities | ||
{ | ||
internal enum LibgenObjectType | ||
{ | ||
NON_FICTION_BOOK = 1, | ||
FICTION_BOOK, | ||
SCIMAG_ARTICLE | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System; | ||
using System.IO; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
|
||
namespace LibgenDesktop.Models.Export | ||
{ | ||
internal class CsvExportWriter : ExportWriter | ||
{ | ||
private const char ZERO_WIDTH_SPACE = '\u200b'; | ||
|
||
private readonly StreamWriter streamWriter; | ||
private readonly char separator; | ||
private bool firstField; | ||
private bool disposed; | ||
|
||
public CsvExportWriter(string filePath, char separator) | ||
{ | ||
streamWriter = new StreamWriter(filePath, false, Encoding.UTF8); | ||
this.separator = separator; | ||
firstField = true; | ||
disposed = false; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public override void WriteField(int value) | ||
{ | ||
WriteSeparatorIfNecessary(); | ||
streamWriter.Write(value); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public override void WriteField(long value) | ||
{ | ||
WriteSeparatorIfNecessary(); | ||
streamWriter.Write(value); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public override void WriteField(string value) | ||
{ | ||
WriteSeparatorIfNecessary(); | ||
value = value.Replace("\"", "\"\""); | ||
if (separator == '\t') | ||
{ | ||
value = value.Replace("\t", String.Empty); | ||
} | ||
value = String.Concat("\"", ZERO_WIDTH_SPACE, value, "\""); | ||
streamWriter.Write(value); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public override void WriteField(DateTime value) | ||
{ | ||
WriteSeparatorIfNecessary(); | ||
streamWriter.Write(value.ToString("yyyy-MM-dd HH:mm:ss")); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public override void WriteField(DateTime? value) | ||
{ | ||
if (value.HasValue) | ||
{ | ||
WriteField(value.Value); | ||
} | ||
else | ||
{ | ||
WriteSeparatorIfNecessary(); | ||
} | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public override void EndRow() | ||
{ | ||
streamWriter.WriteLine(); | ||
firstField = true; | ||
} | ||
|
||
public override void Dispose() | ||
{ | ||
if (!disposed) | ||
{ | ||
streamWriter.Dispose(); | ||
disposed = true; | ||
} | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
private void WriteSeparatorIfNecessary() | ||
{ | ||
if (firstField) | ||
{ | ||
firstField = false; | ||
} | ||
else | ||
{ | ||
streamWriter.Write(separator); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace LibgenDesktop.Models.Export | ||
{ | ||
internal class CsvExporter : Exporter<CsvExportWriter> | ||
{ | ||
public CsvExporter(string filePathTemplate, string fileExtenstion, int? rowsPerFile, bool splitIntoMultipleFiles, char separator) | ||
: base(filePathTemplate, rowsPerFile, splitIntoMultipleFiles, fileExtenstion, filePath => new CsvExportWriter(filePath, separator)) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
using LibgenDesktop.Models.Entities; | ||
|
||
namespace LibgenDesktop.Models.Export | ||
{ | ||
internal abstract class ExportObject<T> where T : LibgenObject | ||
{ | ||
public ExportObject(ExportWriter exportWriter) | ||
{ | ||
ExportWriter = exportWriter; | ||
} | ||
|
||
public abstract IEnumerable<string> FieldList { get; } | ||
|
||
protected ExportWriter ExportWriter { get; } | ||
|
||
public abstract void WriteObject(T libgenObject); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
protected void WriteField(int value) | ||
{ | ||
ExportWriter.WriteField(value); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
protected void WriteField(long value) | ||
{ | ||
ExportWriter.WriteField(value); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
protected void WriteField(string value) | ||
{ | ||
ExportWriter.WriteField(value); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
protected void WriteField(DateTime value) | ||
{ | ||
ExportWriter.WriteField(value); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
protected void WriteField(DateTime? value) | ||
{ | ||
ExportWriter.WriteField(value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace LibgenDesktop.Models.Export | ||
{ | ||
internal class ExportResult | ||
{ | ||
public ExportResult(int itemsExported, int filesCreated, string firstFilePath, bool isExportCancelled, bool isRowsPerFileLimitReached) | ||
{ | ||
ItemsExported = itemsExported; | ||
FilesCreated = filesCreated; | ||
FirstFilePath = firstFilePath; | ||
IsExportCancelled = isExportCancelled; | ||
IsRowsPerFileLimitReached = isRowsPerFileLimitReached; | ||
} | ||
|
||
public int ItemsExported { get; } | ||
public int FilesCreated { get; } | ||
public string FirstFilePath { get; } | ||
public bool IsExportCancelled { get; } | ||
public bool IsRowsPerFileLimitReached { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
|
||
namespace LibgenDesktop.Models.Export | ||
{ | ||
internal abstract class ExportWriter : IDisposable | ||
{ | ||
public abstract void WriteField(int value); | ||
public abstract void WriteField(long value); | ||
public abstract void WriteField(string value); | ||
public abstract void WriteField(DateTime value); | ||
public abstract void WriteField(DateTime? value); | ||
public abstract void EndRow(); | ||
public abstract void Dispose(); | ||
} | ||
} |
Oops, something went wrong.