Skip to content

Commit

Permalink
chore: мелкие правки x2
Browse files Browse the repository at this point in the history
  • Loading branch information
Virenbar committed Apr 5, 2024
1 parent 60d391f commit deb965e
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 25 deletions.
35 changes: 22 additions & 13 deletions FIAS.Core/Extensions/IOExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ namespace FIAS.Core.Extensions
{
public static class IOExtensions
{
public static Task CopyToAsync(this Stream source, Stream destination, int bufferSize) => CopyToAsync(source, destination, bufferSize, default, default);

public static Task CopyToAsync(this Stream source, Stream destination, int bufferSize, IProgress<long> progress) => CopyToAsync(source, destination, bufferSize, progress, default);

/// <summary>
/// https://stackoverflow.com/a/46497896
/// </summary>
public static async Task CopyToAsync(this Stream source, Stream destination, int bufferSize, IProgress<long> progress = default, CancellationToken cancellationToken = default)
public static async Task CopyToAsync(this Stream source, Stream destination, int bufferSize, IProgress<long> progress, CancellationToken cancellationToken)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (!source.CanRead)
throw new ArgumentException("Has to be readable", nameof(source));
if (destination == null)
throw new ArgumentNullException(nameof(destination));
if (!destination.CanWrite)
throw new ArgumentException("Has to be writable", nameof(destination));
if (bufferSize < 0)
throw new ArgumentOutOfRangeException(nameof(bufferSize));
if (source is null) { throw new ArgumentNullException(nameof(source)); }
if (!source.CanRead) { throw new ArgumentException("Has to be readable", nameof(source)); }
if (destination is null) { throw new ArgumentNullException(nameof(destination)); }
if (!destination.CanWrite) { throw new ArgumentException("Has to be writable", nameof(destination)); }
if (bufferSize < 0) { throw new ArgumentOutOfRangeException(nameof(bufferSize)); }

var buffer = new byte[bufferSize];
long totalBytesRead = 0;
Expand All @@ -38,7 +37,12 @@ public static async Task CopyToAsync(this Stream source, Stream destination, int
/// <summary>
/// Асинхронно скачать файл
/// </summary>
public static async Task DownloadAsync(this HttpClient client, string requestUri, Stream destination, CancellationToken cancellationToken = default)
public static Task DownloadAsync(this HttpClient client, string requestUri, Stream destination) => DownloadAsync(client, requestUri, destination, default(CancellationToken));

/// <summary>
/// Асинхронно скачать файл
/// </summary>
public static async Task DownloadAsync(this HttpClient client, string requestUri, Stream destination, CancellationToken cancellationToken)
{
// Считать только заголовок
using (var response = await client.GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead, cancellationToken))
Expand All @@ -53,7 +57,12 @@ public static async Task DownloadAsync(this HttpClient client, string requestUri
/// <summary>
/// Асинхронно скачать файл с отчётом о прогрессе
/// </summary>
public static async Task DownloadAsync(this HttpClient client, string requestUri, Stream destination, IProgress<float> progress, CancellationToken cancellationToken = default)
public static Task DownloadAsync(this HttpClient client, string requestUri, Stream destination, IProgress<float> progress) => DownloadAsync(client, requestUri, destination, progress, default);

/// <summary>
/// Асинхронно скачать файл с отчётом о прогрессе
/// </summary>
public static async Task DownloadAsync(this HttpClient client, string requestUri, Stream destination, IProgress<float> progress, CancellationToken cancellationToken)
{
// Get the http headers first to examine the content length
using (var response = await client.GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead, cancellationToken))
Expand Down
2 changes: 1 addition & 1 deletion FIASUpdate/ArchiveDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ArchiveDownloader() : this(4) { }
/// <param name="threads">Количество "потоков" для скачивания</param>
public ArchiveDownloader(int threads)
{
Client = new HttpClient(new HttpClientHandler() { MaxConnectionsPerServer = threads });
Client = new HttpClient(new HttpClientHandler { MaxConnectionsPerServer = threads });
Semaphore = new SemaphoreSlim(threads);
}

Expand Down
1 change: 0 additions & 1 deletion FIASUpdate/Controls/ToolStripTaskProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class ToolStripTaskProgress : ToolStripStatusLabel
public ToolStripTaskProgress()
{
Progress = new Progress<TaskProgress>(Handler);
UpdateText();
}

public void Clear()
Expand Down
2 changes: 1 addition & 1 deletion FIASUpdate/Database/DBCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class DBCreate : DBClient

public DBCreate() : this(default) { }

public DBCreate(IProgress<TaskProgress> TaskProgress) : base()
public DBCreate(IProgress<TaskProgress> TaskProgress)
{
SP = TaskProgress;
}
Expand Down
2 changes: 1 addition & 1 deletion FIASUpdate/Database/DBImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal abstract class DBImport : DBClient
protected IProgress<TaskProgress> SP;
protected CancellationToken Token;

protected DBImport() : base()
protected DBImport()
{
Events = new SyncEvent(this);
}
Expand Down
1 change: 0 additions & 1 deletion FIASUpdate/Forms/FormAddressSearch.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion FIASUpdate/Forms/FormAddressSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private void UIState(bool value)
TB_Search.ReadOnly = !value;
B_Search.Enabled = value;
CB_Level.Enabled = value;
NUD_Limit.Enabled = value;
RB_ADM.Enabled = value;
RB_MUN.Enabled = value;
}
Expand Down Expand Up @@ -170,7 +171,7 @@ private async void MI_Parameters_Click(object sender, EventArgs e)
try
{
var parameters = await Store.GetObjectParameters(TB_GUID.Text);
var F = new FormDictionaryView()
var F = new FormDictionaryView
{
Text = "Параметры объекта",
KeyHeader = "Параметр",
Expand Down
2 changes: 0 additions & 2 deletions FIASUpdate/Forms/FormDictionaryView.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions FIAS_GAR/adm/Functions/UF_RegistryChild.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ BEGIN
, [R].[Name]
, CAST([R].[AddressFull] AS VARCHAR(1000))
FROM
[FIAS_GAR].[adm].[A_IndexRegistry] [R]
[adm].[A_IndexRegistry] [R]
WHERE [R].[ParentGUID] = @ObjectGUID
UNION ALL
SELECT
Expand All @@ -40,7 +40,7 @@ BEGIN
, [R].[Name]
, [R].[AddressFull]
FROM
[FIAS_GAR].[adm].[A_IndexRegistry] [R]
[adm].[A_IndexRegistry] [R]
JOIN [Hierarchy] [H] ON [H].[ObjectGUID] = [R].[ParentGUID]
WHERE [H].[ObjectGUID] IS NOT NULL)

Expand Down
4 changes: 2 additions & 2 deletions FIAS_GAR/mun/Functions/UF_RegistryChild.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ BEGIN
, [R].[Name]
, CAST([R].[AddressFull] AS VARCHAR(1000))
FROM
[FIAS_GAR].[mun].[A_IndexRegistry] [R]
[mun].[A_IndexRegistry] [R]
WHERE [R].[ParentGUID] = @ObjectGUID
UNION ALL
SELECT
Expand All @@ -40,7 +40,7 @@ BEGIN
, [R].[Name]
, [R].[AddressFull]
FROM
[FIAS_GAR].[mun].[A_IndexRegistry] [R]
[mun].[A_IndexRegistry] [R]
JOIN [Hierarchy] [H] ON [H].[ObjectGUID] = [R].[ParentGUID]
WHERE [H].[ObjectGUID] IS NOT NULL)

Expand Down

0 comments on commit deb965e

Please sign in to comment.