Skip to content

Commit

Permalink
Export
Browse files Browse the repository at this point in the history
  • Loading branch information
libgenapps committed Jan 22, 2018
1 parent 0b36a24 commit 24169c8
Show file tree
Hide file tree
Showing 54 changed files with 2,462 additions and 152 deletions.
1 change: 1 addition & 0 deletions LibgenDesktop.Setup/AppFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static string[] GetFileList(bool is64Bit)
"Dragablz.dll",
"System.Data.SQLite.dll",
"NLog.dll",
"EPPlus.dll",
(is64Bit ? "x64" : "x86") + @"\SQLite.Interop.dll",
"mirrors.config"
};
Expand Down
2 changes: 1 addition & 1 deletion LibgenDesktop.Setup/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
internal static class Constants
{
public const string CURRENT_VERSION = "0.10.1";
public const string CURRENT_VERSION = "0.11";
public const string PRODUCT_TITLE_FORMAT = "Libgen Desktop " + CURRENT_VERSION + " ({0}-bit)";
public const string SHORTCUT_TITLE_FORMAT = "Libgen Desktop ({0}-bit)";
public const string PRODUCT_COMPANY = "Libgen Apps";
Expand Down
9 changes: 5 additions & 4 deletions LibgenDesktop/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
internal static class Constants
{
public const string CURRENT_VERSION = "0.10.1";
public const string CURRENT_VERSION = "0.11";
public const string CURRENT_DATABASE_VERSION = "0.7";

public const string APP_SETTINGS_FILE_NAME = "libgen.config";
Expand Down Expand Up @@ -44,9 +44,9 @@ internal static class Constants
public const int IMPORT_WINDOW_MIN_WIDTH = 500;
public const int IMPORT_WINDOW_MIN_HEIGHT = 400;
public const int CREATE_DATABASE_WINDOW_WIDTH = 500;
public const int SETTINGS_WINDOW_DEFAULT_WIDTH = 750;
public const int SETTINGS_WINDOW_DEFAULT_WIDTH = 760;
public const int SETTINGS_WINDOW_DEFAULT_HEIGHT = 550;
public const int SETTINGS_WINDOW_MIN_WIDTH = 750;
public const int SETTINGS_WINDOW_MIN_WIDTH = 760;
public const int SETTINGS_WINDOW_MIN_HEIGHT = 550;
public const int SYNCHRONIZATION_WINDOW_MIN_WIDTH = 500;
public const int SYNCHRONIZATION_WINDOW_MIN_HEIGHT = 400;
Expand Down Expand Up @@ -85,8 +85,9 @@ internal static class Constants
public const string DEFAULT_MIRROR_NAME = "libgen.io";
public const int DEFAULT_MAXIMUM_SEARCH_RESULT_COUNT = 50000;

public const int SEARCH_REPORT_PROGRESS_BATCH_SIZE = 2000;
public const double SEARCH_PROGRESS_REPORT_INTERVAL = 0.1;
public const int DATABASE_TRANSACTION_BATCH = 500;
public const int MAX_EXPORT_ROWS_PER_FILE = 1000000;

public const string USER_AGENT = "LibgenDesktop/" + CURRENT_VERSION;
public const int MIN_PROXY_PORT = 1;
Expand Down
30 changes: 30 additions & 0 deletions LibgenDesktop/LibgenDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
<HintPath>..\packages\Dragablz.0.0.3.197\lib\net45\Dragablz.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EPPlus, Version=4.1.1.0, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL">
<HintPath>..\packages\EPPlus.4.1.1\lib\net40\EPPlus.dll</HintPath>
</Reference>
<Reference Include="MaterialDesignColors">
<HintPath>..\packages\MaterialDesignColors.1.1.3\lib\net45\MaterialDesignColors.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -123,7 +126,19 @@
<Compile Include="Models\Entities\DatabaseMetadata.cs" />
<Compile Include="Models\Entities\FictionBook.cs" />
<Compile Include="Models\Entities\LibgenObject.cs" />
<Compile Include="Models\Entities\LibgenObjectType.cs" />
<Compile Include="Models\Entities\SciMagArticle.cs" />
<Compile Include="Models\Export\XlsxExporter.cs" />
<Compile Include="Models\Export\CsvExporter.cs" />
<Compile Include="Models\Export\XlsxExportWriter.cs" />
<Compile Include="Models\Export\CsvExportWriter.cs" />
<Compile Include="Models\Export\Exporter.cs" />
<Compile Include="Models\Export\ExportObject.cs" />
<Compile Include="Models\Export\ExportResult.cs" />
<Compile Include="Models\Export\ExportWriter.cs" />
<Compile Include="Models\Export\SciMagExportObject.cs" />
<Compile Include="Models\Export\FictionExportObject.cs" />
<Compile Include="Models\Export\NonFictionExportObject.cs" />
<Compile Include="Models\Import\FictionImporter.cs" />
<Compile Include="Models\Import\SciMagImporter.cs" />
<Compile Include="Models\JsonApi\JsonApiClient.cs" />
Expand All @@ -133,6 +148,7 @@
<Compile Include="Models\ProgressArgs\ImportSearchTableDefinitionProgress.cs" />
<Compile Include="Models\ProgressArgs\ImportTableDefinitionFoundProgress.cs" />
<Compile Include="Models\ProgressArgs\JsonApiDownloadProgress.cs" />
<Compile Include="Models\ProgressArgs\ExportProgress.cs" />
<Compile Include="Models\ProgressArgs\SearchProgress.cs" />
<Compile Include="Models\Settings\Mirrors.cs" />
<Compile Include="Models\Settings\MirrorStorage.cs" />
Expand All @@ -146,8 +162,11 @@
<Compile Include="Models\SqlDump\TableDefinitions.cs" />
<Compile Include="Models\SqlDump\TableType.cs" />
<Compile Include="Models\Utils\UrlGenerator.cs" />
<Compile Include="ViewModels\ExportPanelViewModel.cs" />
<Compile Include="ViewModels\FictionDetailsTabViewModel.cs" />
<Compile Include="ViewModels\LibgenWindowViewModel.cs" />
<Compile Include="ViewModels\ProgressLogItemViewModel.cs" />
<Compile Include="ViewModels\SearchResultsTabViewModel.cs" />
<Compile Include="ViewModels\SynchronizationWindowViewModel.cs" />
<Compile Include="ViewModels\NonFictionDetailsTabViewModel.cs" />
<Compile Include="ViewModels\SciMagDetailsTabViewModel.cs" />
Expand All @@ -171,6 +190,9 @@
<Compile Include="Views\Controls\CloseTabButton.xaml.cs">
<DependentUpon>CloseTabButton.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Controls\ExportPanel.xaml.cs">
<DependentUpon>ExportPanel.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Controls\TabControl.cs" />
<Compile Include="Views\MessageBoxWindow.xaml.cs">
<DependentUpon>MessageBoxWindow.xaml</DependentUpon>
Expand Down Expand Up @@ -253,10 +275,18 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Controls\ExportPanel.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\MessageBoxWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Styles\ExportPanelStyles.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Styles\MessageBoxWindowStyles.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
9 changes: 9 additions & 0 deletions LibgenDesktop/Models/Entities/LibgenObjectType.cs
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
}
}
17 changes: 9 additions & 8 deletions LibgenDesktop/Models/Entities/NonFictionBook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,20 @@ internal class NonFictionBook : LibgenObject
public string ColorString => StringBooleanToLabelString(Color, "да", "нет", "неизвестно");
public string CleanedString => StringBooleanToLabelString(Cleaned, "да", "нет", "неизвестно");

public string ContentPageCountString
{
get
{
return !String.IsNullOrWhiteSpace(Pages) ? Pages : "неизвестно";
}
}

public string PagesString
{
get
{
StringBuilder resultBuilder = new StringBuilder();
if (!String.IsNullOrWhiteSpace(Pages))
{
resultBuilder.Append(Pages);
}
else
{
resultBuilder.Append("неизвестно");
}
resultBuilder.Append(ContentPageCountString);
resultBuilder.Append(" (содержательная часть) / ");
resultBuilder.Append(PagesInFile.ToString());
resultBuilder.Append(" (всего в файле)");
Expand Down
101 changes: 101 additions & 0 deletions LibgenDesktop/Models/Export/CsvExportWriter.cs
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);
}
}
}
}
10 changes: 10 additions & 0 deletions LibgenDesktop/Models/Export/CsvExporter.cs
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))
{
}
}
}
51 changes: 51 additions & 0 deletions LibgenDesktop/Models/Export/ExportObject.cs
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);
}
}
}
20 changes: 20 additions & 0 deletions LibgenDesktop/Models/Export/ExportResult.cs
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; }
}
}
15 changes: 15 additions & 0 deletions LibgenDesktop/Models/Export/ExportWriter.cs
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();
}
}
Loading

0 comments on commit 24169c8

Please sign in to comment.