-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Улучшен функционал загрузки дистрибутивов ФИАС
- Добавлено тестовое приложение для загрузки дистрибутива ФИАС - Улучшен вспомогательный класс работы с API ФИАС * Оптимизировано обращение через HTTP-клиент * Добавлена возможность многопоточной загрузки данных * Реализована обработка события изменения прогреса загрузки файла - Выделен список файлов дистрибутивов для загрузки - Добавлены вспомогательные методы получения URL и загрузки файла по типу файла дистрибутива - Загрузка файлов и другие HTTP-запросы теперь выполняются с "User Agent" от имени обычного браузера - Удалены неиспользуемые элементы решения и проектов - Очистка кода - Расширены тесты в части загрузки файлов дистрибутивов
- Loading branch information
Showing
16 changed files
with
441 additions
and
44 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
Apps/YPermitin.FIASToolSet.DistributionDownloader/Program.cs
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,47 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
|
||
using YPermitin.FIASToolSet.DistributionBrowser; | ||
using YPermitin.FIASToolSet.DistributionBrowser.Enums; | ||
using YPermitin.FIASToolSet.DistributionBrowser.Models; | ||
|
||
Console.WriteLine("Тестовая загрузка полного дистрибутива ФИАС."); | ||
|
||
IFIASDistributionBrowser loader = new FIASDistributionBrowser(); | ||
var lastInfo = await loader.GetLastDistributionInfo(); | ||
var xmlFullUrl = lastInfo?.GetUrlByFileType(DistributionFileType.GARFIASXmlComplete); | ||
|
||
var tempFileToDownload = Path.Combine( | ||
Path.GetTempPath(), | ||
"FIAS_FULL.zip"); | ||
|
||
DateTime downloadStarted = DateTime.UtcNow; | ||
DateTime lastProgressShow = DateTime.MinValue; | ||
double lastProgressPercentage = 0; | ||
await lastInfo?.DownloadDistributionByFileTypeAsync( | ||
DistributionFileType.GARFIASXmlComplete, | ||
tempFileToDownload, | ||
(args) => | ||
{ | ||
double progress = Math.Round(args.ProgressPercentage, 2); | ||
double progressChanged = lastProgressPercentage - progress; | ||
var showProgressTimeLeft = DateTime.UtcNow - lastProgressShow; | ||
if (args.State != DownloadDistributionFileProgressChangedEventType.Downloading | ||
|| showProgressTimeLeft.TotalSeconds > 10 | ||
|| progressChanged >= 1) | ||
{ | ||
var downloadDuration = DateTime.UtcNow - downloadStarted; | ||
Console.WriteLine($"[{DateTime.UtcNow}] {args.State}. Progress: {progress} %. Seconds left: {downloadDuration.TotalSeconds}"); | ||
if (args.ErrorInfo != null) | ||
{ | ||
Console.WriteLine(args.ErrorInfo.GetBaseException().Message); | ||
} | ||
lastProgressPercentage = progress; | ||
lastProgressShow = DateTime.UtcNow; | ||
} | ||
}); | ||
|
||
Console.WriteLine("Для выхода нажмите любую клавишу..."); | ||
Console.ReadKey(); |
14 changes: 14 additions & 0 deletions
14
...in.FIASToolSet.DistributionDownloader/YPermitin.FIASToolSet.DistributionDownloader.csproj
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,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Libs\YPermitin.FIASToolSet.DistributionBrowser\YPermitin.FIASToolSet.DistributionBrowser.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
16 changes: 16 additions & 0 deletions
16
Libs/YPermitin.FIASToolSet.DistributionBrowser/Enums/DistributionFileType.cs
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,16 @@ | ||
namespace YPermitin.FIASToolSet.DistributionBrowser.Enums; | ||
|
||
/// <summary> | ||
/// Типы файлов дистрибутива ФИАС для загрузки | ||
/// </summary> | ||
public enum DistributionFileType | ||
{ | ||
FIASDbfComplete, | ||
FIASDbfDelta, | ||
FIASXmlComplete, | ||
FIASXmlDelta, | ||
GARFIASXmlComplete, | ||
GARFIASXmlDelta, | ||
KLADR4ArjComplete, | ||
KLADR47zComplete | ||
} |
54 changes: 54 additions & 0 deletions
54
Libs/YPermitin.FIASToolSet.DistributionBrowser/GeneralResources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
Libs/YPermitin.FIASToolSet.DistributionBrowser/GeneralResources.resx
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,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<root> | ||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> | ||
<xsd:element name="root" msdata:IsDataSet="true"> | ||
|
||
</xsd:element> | ||
</xsd:schema> | ||
<resheader name="resmimetype"> | ||
<value>text/microsoft-resx</value> | ||
</resheader> | ||
<resheader name="version"> | ||
<value>1.3</value> | ||
</resheader> | ||
<resheader name="reader"> | ||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<resheader name="writer"> | ||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<data name="DefaultUserAgent" xml:space="preserve"> | ||
<value>Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 YaBrowser/23.5.1.800 Yowser/2.5 Safari/537.36</value> | ||
</data> | ||
</root> |
20 changes: 20 additions & 0 deletions
20
Libs/YPermitin.FIASToolSet.DistributionBrowser/Models/DownloadDistributionFileEventArgs.cs
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 @@ | ||
using System; | ||
|
||
namespace YPermitin.FIASToolSet.DistributionBrowser.Models; | ||
|
||
public class DownloadDistributionFileProgressChangedEventArgs | ||
{ | ||
public DownloadDistributionFileProgressChangedEventType State { get; } | ||
public double ProgressPercentage { get; } | ||
public Exception ErrorInfo { get; } | ||
|
||
public DownloadDistributionFileProgressChangedEventArgs( | ||
DownloadDistributionFileProgressChangedEventType state, | ||
double progressPercentage, | ||
Exception errorInfo = null) | ||
{ | ||
ProgressPercentage = progressPercentage; | ||
State = state; | ||
ErrorInfo = errorInfo; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...IASToolSet.DistributionBrowser/Models/DownloadDistributionFileProgressChangedEventType.cs
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 YPermitin.FIASToolSet.DistributionBrowser.Models; | ||
|
||
public enum DownloadDistributionFileProgressChangedEventType | ||
{ | ||
Started, | ||
Downloading, | ||
Compleated, | ||
Failure, | ||
Canceled | ||
} |
Oops, something went wrong.