Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions FIAS.Core/API/FIASInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Newtonsoft.Json.Converters;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using Newtonsoft.Json;

namespace FIAS.Core.API
{
Expand Down
73 changes: 1 addition & 72 deletions FIAS.Core/Extensions/SQLExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Data.SqlClient;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace FIAS.Core.Extensions
{
Expand All @@ -16,73 +12,6 @@ public static SqlParameter AddParameter(this SqlCommand command, string paramete
return command.Parameters.AddWithValue(parameter, value);
}

public static void ExecuteNonQuery(this SqlCommand command, string connection)
{
using (var Connection = new SqlConnection(connection))
{
Connection.Open();
command.Connection = Connection;
command.ExecuteNonQuery();
}
}

public static Task ExecuteNonQueryAsync(this SqlCommand command, string connection) => ExecuteNonQueryAsync(command, connection, default);

public static async Task ExecuteNonQueryAsync(this SqlCommand command, string connection, CancellationToken token)
{
using (var Connection = new SqlConnection(connection))
{
Connection.Open();
command.Connection = Connection;
await command.ExecuteNonQueryAsync(token);
}
}

public static object ExecuteScalar(this SqlCommand command, string connection)
{
using (var Connection = new SqlConnection(connection))
{
Connection.Open();
command.Connection = Connection;
return command.ExecuteScalar();
}
}

public static T ExecuteScalar<T>(this SqlCommand command, string connection)
{
using (var Connection = new SqlConnection(connection))
{
Connection.Open();
command.Connection = Connection;
return (T)command.ExecuteScalar();
}
}

public static DataTable ExecuteSelect(this SqlCommand command)
{
return command.ExecuteSelect(DefaultConnection);
}

public static DataTable ExecuteSelect(this SqlCommand command, string connection)
{
using (var Connection = new SqlConnection(connection))
{
Connection.Open();
return command.ExecuteSelect(Connection);
}
}

public static DataTable ExecuteSelect(this SqlCommand command, SqlConnection connection)
{
var Result = new DataTable { Locale = CultureInfo.CurrentCulture };
command.Connection = connection;
using (var Reader = command.ExecuteReader())
{
Result.Load(Reader);
}
return Result;
}

public static SqlCommand SetSchema(this SqlCommand command, string schema)
{
var name = command.CommandText.Split('.').Last();
Expand Down
5 changes: 0 additions & 5 deletions FIAS.Core/Models/DownloadState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
{
public class DownloadState
{
public DownloadState(float progress)
{
Progress = progress;
}

public DownloadState(long totalBytes, long downloadedBytes)
{
TotalBytes = totalBytes;
Expand Down
41 changes: 20 additions & 21 deletions FIAS.Core/Stores/FIASDatabaseStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,62 +96,61 @@ public List<FIASTableInfo> TablesInfo()

private T UP_DatabasePropertyGet<T>(string name)
{
using (var Command = NewProcedure())
using (var command = NewProcedure())
{
var P = Command.Parameters;
var P = command.Parameters;
P.AddWithValue("@Name", name);
return Command.ExecuteScalar<T>(Connection);
return Execute(command).Scalar<T>();
}
}

private void UP_DatabasePropertySet(string name, object value)
{
using (var Command = NewProcedure())
using (var command = NewProcedure())
{
var P = Command.Parameters;
var P = command.Parameters;
P.AddWithValue("@Name", name);
P.AddWithValue("@Value", value);
Command.ExecuteNonQuery(Connection);
Execute(command).NonQuery();
}
}

private async Task UP_RefreshRegistry(FIASDivision division, CancellationToken token)
{
using (var Command = NewProcedure())
using (var command = NewProcedure())
{
Command.SetSchema($"{division}");
Command.CommandTimeout = 0;
await Command.ExecuteNonQueryAsync(Connection, token);
command.SetSchema($"{division}");
command.CommandTimeout = 0;
await Execute(command).NonQueryAsync(token);
}
}

private object UP_TablePropertyGet(string table, string name)
{
using (var Command = NewProcedure())
using (var command = NewProcedure())
{
var P = Command.Parameters;
var P = command.Parameters;
P.AddWithValue("@Table", table);
P.AddWithValue("@Name", name);
return Command.ExecuteScalar(Connection);
return Execute(command).Scalar();
}
}

private void UP_TablePropertySet(string table, string name, object value)
{
using (var Command = NewProcedure())
using (var command = NewProcedure())
{
var P = Command.Parameters;
P.AddWithValue("@Table", table);
P.AddWithValue("@Name", name);
P.AddWithValue("@Value", value);
Command.ExecuteNonQuery(Connection);
command.AddParameter("@Table", table);
command.AddParameter("@Name", name);
command.AddParameter("@Value", value);
Execute(command).NonQuery();
}
}

private DataTable UP_TablesInfo()
{
using (var Command = NewProcedure())
return Command.ExecuteSelect(Connection);
using (var command = NewProcedure())
return Execute(command).Select();
}

#endregion SQL
Expand Down
29 changes: 14 additions & 15 deletions FIAS.Core/Stores/FIASStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using FIAS.Core.Models;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -129,44 +128,44 @@ public async Task<Dictionary<string, string>> Statistics()
private DataTable UP_CB_Levels()
{
using (var command = NewProcedure())
return command.ExecuteSelect(Connection);
return Execute(command).Select();
}

private DataTable UP_FIAS_Statistics()
{
using (var command = NewProcedure())
{
command.CommandTimeout = 300;
return command.ExecuteSelect(Connection);
return Execute(command).Select();
}
}

private DataTable UP_RegistryHierarchy(string GUID, FIASDivision H)
private long UP_IDByGUID(string GUID)
{
using (var command = NewProcedure())
{
command.SetSchema($"{H}");
command.AddParameter("@GUID", GUID);
return command.ExecuteSelect(Connection);
return Execute(command).Scalar<long>();
}
}

private long UP_IDByGUID(string GUID)
private DataTable UP_ObjectParameters(string GUID)
{
using (var command = NewProcedure())
{
command.CommandTimeout = 300;
command.AddParameter("@GUID", GUID);
return command.ExecuteScalar<long>(Connection);
return Execute(command).Select();
}
}

private DataTable UP_ObjectParameters(string GUID)
private DataTable UP_RegistryHierarchy(string GUID, FIASDivision H)
{
using (var command = NewProcedure())
{
command.CommandTimeout = 300;
command.SetSchema($"{H}");
command.AddParameter("@GUID", GUID);
return command.ExecuteSelect(Connection);
return Execute(command).Select();
}
}

Expand All @@ -178,7 +177,7 @@ private DataTable UP_RegistrySelect(string GUID, FIASDivision H)
{
command.SetSchema($"{H}");
command.AddParameter("@GUID", GUID);
return command.ExecuteSelect(Connection);
return Execute(command).Select();
}
}

Expand All @@ -188,7 +187,7 @@ private DataTable UP_RegistrySelectChild(string GUID, FIASDivision H)
{
command.SetSchema($"{H}");
command.AddParameter("@GUID", GUID);
return command.ExecuteSelect(Connection);
return Execute(command).Select();
}
}

Expand All @@ -200,7 +199,7 @@ private DataTable UP_SearchRegistry(FIASDivision H, string Search, int? Level, i
command.AddParameter("@Search", Search);
command.AddParameter("@Level", Level);
command.AddParameter("@Limit", Limit);
return command.ExecuteSelect(Connection);
return Execute(command).Select();
}
}

Expand All @@ -212,7 +211,7 @@ private DataTable UP_SearchRegistryByGUID(FIASDivision H, string GUID, int? Leve
command.AddParameter("@GUID", GUID);
command.AddParameter("@Level", Level);
command.AddParameter("@Limit", Limit);
return command.ExecuteSelect(Connection);
return Execute(command).Select();
}
}

Expand Down
Loading
Loading