Unnessesery projects deleted
This commit is contained in:
@@ -155,7 +155,7 @@
|
||||
</site>
|
||||
<site name="MeterProcessState" id="2">
|
||||
<application path="/" applicationPool="Clr4IntegratedAppPool">
|
||||
<virtualDirectory path="/" physicalPath="C:\Users\drabesch_ro\Repo\lab\la_operations\laa_production\Common\Service\MeterProcessState" />
|
||||
<virtualDirectory path="/" physicalPath="C:\Users\SZLATEV\source\repos\laa_production\Common\Service\MeterProcessState" />
|
||||
</application>
|
||||
<bindings>
|
||||
<binding protocol="http" bindingInformation="*:56011:localhost" />
|
||||
|
||||
@@ -100,5 +100,8 @@
|
||||
<Name>Common.Utils.Extensions</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="configuration.json" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -1,10 +1,162 @@
|
||||
namespace CommonConsole
|
||||
{
|
||||
using Common.Logic.Extensions.SQL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
SQLConnection
|
||||
.CreateSQLConnection("Server=SLASQL01.emea.sensus.net; Database=Auftrag; User ID=sa; Password=sqlserver;")
|
||||
.CreateCommand(@"
|
||||
SELECT CONVERT(VARBINARY(8), '0x' + REPLACE(x.Address, '-', ''), 1)
|
||||
, CONVERT(VARBINARY(256), '0x' + REPLACE(x.Value, '-', ''), 1)
|
||||
FROM (SELECT rh.Address
|
||||
, rh.Value
|
||||
, ROW_NUMBER() OVER (PARTITION BY rh.Address ORDER BY rh.date DESC) AS Row
|
||||
FROM GenesisMeterRegisterHistory AS rh
|
||||
WHERE rh.PcbId = @pcbId) AS x
|
||||
WHERE x.Row = 1
|
||||
ORDER BY x.Address")
|
||||
.SetParameter("pcbId", "241330796")
|
||||
.ExecuteReader(reader =>
|
||||
{
|
||||
var address = reader.GetValue<Byte[]>(0);
|
||||
|
||||
if (address.Length == 2)
|
||||
{
|
||||
var value = reader.GetValue<Byte[]>(1);
|
||||
|
||||
Console.WriteLine($"App: {address[0], 5:X2} Register: {address[1], 5:X2} Data: {BitConverter.ToString(value)}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public class Cordonel : Dictionary<String, App>
|
||||
{
|
||||
[OnDeserialized]
|
||||
internal void OnDeserialized(StreamingContext _)
|
||||
{
|
||||
foreach (var x in this)
|
||||
{
|
||||
x.Value.Name = x.Key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class App
|
||||
{
|
||||
public Byte Id { get; set; }
|
||||
|
||||
public String Name { get; set; }
|
||||
|
||||
public V Version { get; set; }
|
||||
|
||||
public Registers Registers { get; set; }
|
||||
|
||||
public Statuses Status { get; set; }
|
||||
}
|
||||
|
||||
public class V
|
||||
{
|
||||
public UInt16? First { get; set; }
|
||||
|
||||
public UInt16? Last { get; set; }
|
||||
}
|
||||
|
||||
public class Registers : Dictionary<String, Register>
|
||||
{
|
||||
[OnDeserialized]
|
||||
internal void OnDeserialized(StreamingContext _)
|
||||
{
|
||||
foreach (var x in this)
|
||||
{
|
||||
x.Value.Name = x.Key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Register
|
||||
{
|
||||
public Byte Id { get; set; }
|
||||
|
||||
public String Name { get; set; }
|
||||
|
||||
public Detail[] Details { get; set; }
|
||||
}
|
||||
|
||||
public class Detail
|
||||
{
|
||||
public V Version { get; set; }
|
||||
|
||||
public String Type { get; set; }
|
||||
|
||||
public String StaticType { get; set; }
|
||||
|
||||
public String Description { get; set; }
|
||||
|
||||
public Privilege Privilege { get; set; }
|
||||
|
||||
public Values Values { get; set; }
|
||||
}
|
||||
|
||||
public class Values
|
||||
{
|
||||
public Object Minimum { get; set; }
|
||||
|
||||
public Object Maximum { get; set; }
|
||||
|
||||
public Object Default { get; set; }
|
||||
}
|
||||
|
||||
public class Privilege
|
||||
{
|
||||
public Privileges Lvl1 { get; set; }
|
||||
|
||||
public Privileges Lvl2 { get; set; }
|
||||
|
||||
public Privileges Lvl3 { get; set; }
|
||||
|
||||
public Privileges Lvl4 { get; set; }
|
||||
|
||||
public Privileges Lvl5 { get; set; }
|
||||
|
||||
public Privileges Lvl6 { get; set; }
|
||||
|
||||
public Privileges Lvl7 { get; set; }
|
||||
|
||||
public Privileges Lvl8 { get; set; }
|
||||
}
|
||||
|
||||
public enum Privileges
|
||||
{
|
||||
NA,
|
||||
RO,
|
||||
WO,
|
||||
RW,
|
||||
}
|
||||
|
||||
public class Statuses : Dictionary<String, Status>
|
||||
{
|
||||
[OnDeserialized]
|
||||
internal void OnDeserialized(StreamingContext _)
|
||||
{
|
||||
foreach (var x in this)
|
||||
{
|
||||
x.Value.Name = x.Key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Status
|
||||
{
|
||||
public Byte Id { get; set; }
|
||||
|
||||
public String Name { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
c43c40a030005a8f189e6179faf40a6d42bfef5c
|
||||
89102b0142e574de38a9f47d370f3334e5e6c268
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace Xylem.Common.Service.MeterProcessState.Controllers
|
||||
namespace Xylem.Common.Service.MeterProcessState.Controllers
|
||||
{
|
||||
[RoutePrefix("api/ConfigurationJson")]
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
|
||||
[RoutePrefix("api/configurationjson")]
|
||||
public class ConfigurationJsonController : ApiController
|
||||
{
|
||||
[HttpGet]
|
||||
[Route]
|
||||
public IHttpActionResult Get()
|
||||
{
|
||||
try
|
||||
|
||||
+1
-1
@@ -4,6 +4,6 @@
|
||||
|
||||
public interface IEOLProgressRepository<T> : IRepositoryCreate<T>, IRepositoryRead<T>, IRepositoryUpdate<T>, IRepositoryDelete<T>
|
||||
{
|
||||
T RunSentinel(Int32 pcbId);
|
||||
void RunSentinel(Int32 pcbId);
|
||||
}
|
||||
}
|
||||
|
||||
+29
-4
@@ -5,6 +5,7 @@
|
||||
using LaaProduction.Data.SQL.Interfaces;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class EOLProgressRepository : IEOLProgressRepository<EOLProgressModel>
|
||||
{
|
||||
@@ -189,7 +190,7 @@
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public EOLProgressModel RunSentinel(int pcbId)
|
||||
public void RunSentinel(int pcbId)
|
||||
{
|
||||
var model = this.Read(new EOLProgressModel
|
||||
{
|
||||
@@ -198,9 +199,30 @@
|
||||
|
||||
if (model is null)
|
||||
{
|
||||
return model;
|
||||
return;
|
||||
}
|
||||
|
||||
var history = new RegisterHistory();
|
||||
this.sqlConnection
|
||||
.CreateCommand(@"
|
||||
SELECT x.Address
|
||||
, x.Value
|
||||
FROM (SELECT rh.Address
|
||||
, rh.Value
|
||||
, ROW_NUMBER() OVER (PARTITION BY rh.Address ORDER BY rh.date DESC) AS Row
|
||||
FROM GenesisMeterRegisterHistory AS rh
|
||||
WHERE rh.PcbId = @pcbId) AS x
|
||||
WHERE x.Row = 1
|
||||
ORDER BY x.Address")
|
||||
.SetParameter(nameof(pcbId), $"{pcbId}")
|
||||
.ExecuteReader(reader =>
|
||||
{
|
||||
var addressBytes = reader.GetValue<String>(0);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
|
||||
this.sqlConnection
|
||||
.CreateCommand($@"
|
||||
@@ -211,8 +233,11 @@
|
||||
WHERE PcbId = @{nameof(model.PcbId)}")
|
||||
.SetParameter(nameof(model.PcbId), model.PcbId)
|
||||
.ExecuteNonQuery();
|
||||
|
||||
return this.Read(model);
|
||||
}
|
||||
}
|
||||
|
||||
public class RegisterHistory : Dictionary<Byte, Dictionary<Byte, Byte[]>>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
namespace LaaProduction.Data.SQL.Interfaces
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public interface ISQLCommand
|
||||
{
|
||||
Int32 ExecuteNonQuery();
|
||||
|
||||
IEnumerable<T> ExecuteReader<T>(Func<ISQLReader, T> expression);
|
||||
|
||||
T ExecuteScalar<T>(Func<ISQLReader, T> expression);
|
||||
|
||||
T FirstOrDefault<T>(Func<ISQLReader, T> expression);
|
||||
|
||||
ISQLCommand SetParameter(String name, Object value);
|
||||
|
||||
ISQLCommand SetParameter(String name, DateTime value);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
namespace LaaProduction.Data.SQL.Interfaces
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="ISQLConnection"/> simply exposes the <see cref="ISQLConnection.CreateCommand(String)"/> method.
|
||||
/// </summary>
|
||||
public interface ISQLConnection
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a command with given command text.
|
||||
/// </summary>
|
||||
/// <param name="commandText"><see cref="System.String"/> - SQL query String.</param>
|
||||
/// <returns></returns>
|
||||
ISQLCommand CreateCommand(String commandText);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace LaaProduction.Data.SQL.Interfaces
|
||||
{
|
||||
using System;
|
||||
|
||||
public interface ISQLReader
|
||||
{
|
||||
T GetValue<T>(Int32 index);
|
||||
|
||||
T GetValue<T>(String column);
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{82D34580-23FE-4315-BC51-51D565ABAE23}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>LaaProduction.Data.SQL</RootNamespace>
|
||||
<AssemblyName>LaaProduction.Data.SQL</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<NoWarn>IDE0003;IDE0049;</NoWarn>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.8.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=8.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.8.0.1\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Interfaces\ISQLCommand.cs" />
|
||||
<Compile Include="Interfaces\ISQLConnection.cs" />
|
||||
<Compile Include="Interfaces\ISQLReader.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SQLCommand.cs" />
|
||||
<Compile Include="SQLConnection.cs" />
|
||||
<Compile Include="SQLReader.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -1,36 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("LaaProduction.Data.SQL")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("LaaProduction.Data.SQL")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2024")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("82d34580-23fe-4315-bc51-51d565abae23")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -1,75 +0,0 @@
|
||||
namespace LaaProduction.Data.SQL
|
||||
{
|
||||
using LaaProduction.Data.SQL.Interfaces;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
|
||||
public class SQLCommand : ISQLCommand
|
||||
{
|
||||
private readonly SQLConnection sqlConnection;
|
||||
private readonly IDictionary<String, SqlParameter> parameters;
|
||||
|
||||
public SQLCommand(SQLConnection sqlConnection, String commandText)
|
||||
{
|
||||
this.parameters = new Dictionary<String, SqlParameter>();
|
||||
this.sqlConnection = sqlConnection;
|
||||
this.CommandText = commandText;
|
||||
}
|
||||
|
||||
internal String CommandText { get; }
|
||||
|
||||
internal SqlParameter[] Parameters
|
||||
=> this.parameters.Values.ToArray();
|
||||
|
||||
public Int32 ExecuteNonQuery()
|
||||
=> this.sqlConnection.ExecuteNonQuery(this);
|
||||
|
||||
public IEnumerable<T> ExecuteReader<T>(Func<ISQLReader, T> expression)
|
||||
{
|
||||
foreach (var result in this.sqlConnection.ExecuteReader(this, expression))
|
||||
{
|
||||
yield return result;
|
||||
}
|
||||
}
|
||||
|
||||
public T ExecuteScalar<T>(Func<ISQLReader, T> expression)
|
||||
=> this.sqlConnection.ExecuteScalar(this, expression);
|
||||
|
||||
public T FirstOrDefault<T>(Func<ISQLReader, T> expression)
|
||||
=> this.sqlConnection.FirstOrDefault(this, expression);
|
||||
|
||||
public ISQLCommand SetParameter(String name, Object value)
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
value = DBNull.Value;
|
||||
}
|
||||
|
||||
var parameter = new SqlParameter(name, value);
|
||||
|
||||
this.parameters[name] = parameter;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISQLCommand SetParameter(String name, DateTime value)
|
||||
{
|
||||
var _default = new DateTime(1753, 1, 1, 12, 0, 0);
|
||||
|
||||
if (value < _default)
|
||||
{
|
||||
value = _default;
|
||||
}
|
||||
|
||||
var parameter = new SqlParameter(name, value);
|
||||
|
||||
this.parameters[name] = parameter;
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,175 +0,0 @@
|
||||
namespace LaaProduction.Data.SQL
|
||||
{
|
||||
using LaaProduction.Data.SQL.Interfaces;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
/// <summary>
|
||||
/// A wrapper class around the <see cref="System.Data.SqlClient"/>.
|
||||
/// Exposes <see cref="System.Data.SqlClient.SqlConnection"/>, <see cref="System.Data.SqlClient.SqlCommand"/> and <see cref="System.Data.SqlClient.SqlDataReader"/> classes
|
||||
/// in a fluent manner, all exposed methods can be chained in a single C# query.
|
||||
/// </summary>
|
||||
public class SQLConnection : ISQLConnection
|
||||
{
|
||||
private readonly String connectionString;
|
||||
private readonly Action<String> errorCallback;
|
||||
|
||||
/// <summary>
|
||||
/// When <paramref name="connectionString"/> is null, white space or is not a valid connection String exception is thrown.
|
||||
/// </summary>
|
||||
/// <param name="connectionString"><see cref="System.String"/> - SQL connection String.</param>
|
||||
public SQLConnection(String connectionString)
|
||||
=> this.connectionString = connectionString;
|
||||
|
||||
/// <summary>
|
||||
/// When <paramref name="connectionString"/> is null, white space or is not a valid connection String exception is thrown.
|
||||
/// Additionaly accepts <see cref="System.Action{System.String}"/> for error handling.
|
||||
/// Whenever the sql query throws error on execution, this will be passesd within the callback.
|
||||
/// </summary>
|
||||
/// <param name="connectionString"><see cref="System.String"/> - SQL connection String.</param>
|
||||
/// <param name="errorCallback"><see cref="System.Action{System.String}"/> - error handler for SQL execution errors.</param>
|
||||
public SQLConnection(String connectionString, Action<String> errorCallback = null)
|
||||
: this(connectionString)
|
||||
=> this.errorCallback = errorCallback;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="LaaProduction.Data.SQL.ISQLCommand"/> wrapper that accepts a SQL query String.
|
||||
/// </summary>
|
||||
/// <param name="commandText"><see cref="System.String"/> - SQL query String</param>
|
||||
/// <returns><see cref="LaaProduction.Data.SQL.ISQLCommand"/> - that exposes basic functionalities from the <see cref="System.Data.SqlClient.SqlCommand" />.</returns>
|
||||
public ISQLCommand CreateCommand(String commandText)
|
||||
=> new SQLCommand(this, commandText);
|
||||
|
||||
/// <summary>
|
||||
/// Internal method called from <see cref="LaaProduction.Data.SQL.ISQLCommand"/>.
|
||||
/// Like in a <see cref="System.Data.SqlClient.SqlCommand"/> performs INSERT, UPDATE, DELETE queries and returns the number of rows affected.
|
||||
/// </summary>
|
||||
/// <param name="command"><see cref="System.String"/> - SQL query String</param>
|
||||
/// <returns><see cref="System.Int32"/> - the number of rows affected.</returns>
|
||||
internal Int32 ExecuteNonQuery(SQLCommand command)
|
||||
{
|
||||
var rowsAffected = 0;
|
||||
|
||||
using (var sqlConnection = new SqlConnection(this.connectionString))
|
||||
{
|
||||
this.OpenWithErrorHandling(sqlConnection);
|
||||
|
||||
using (var sqlCommand = sqlConnection.CreateCommand())
|
||||
{
|
||||
sqlCommand.CommandText = command.CommandText;
|
||||
|
||||
sqlCommand.Parameters.AddRange(command.Parameters);
|
||||
|
||||
rowsAffected = sqlCommand.ExecuteNonQuery();
|
||||
|
||||
sqlCommand.Parameters.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
return rowsAffected;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal method called from <see cref="LaaProduction.Data.SQL.ISQLCommand"/>.
|
||||
/// Like in a <see cref="System.Data.SqlClient.SqlCommand"/> performs SELECT queries and returns a enumerable of the results readed.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Is the type that returns the <see cref="System.Func{IFluentSQLReader, T} expression"/></typeparam>
|
||||
/// <param name="command"><see cref="System.String"/> - SQL query String</param>
|
||||
/// <param name="expression">Expression that reads specified data from the <see cref="LaaProduction.Data.SQL.ISQLReader"/>.</param>
|
||||
/// <returns><see cref="System.Collections.Generic.IEnumerable{T}"/></returns>
|
||||
internal IEnumerable<T> ExecuteReader<T>(SQLCommand command, Func<ISQLReader, T> expression)
|
||||
{
|
||||
using (var sqlConnection = new SqlConnection(this.connectionString))
|
||||
{
|
||||
this.OpenWithErrorHandling(sqlConnection);
|
||||
|
||||
using (var sqlCommand = sqlConnection.CreateCommand())
|
||||
{
|
||||
sqlCommand.CommandText = command.CommandText;
|
||||
|
||||
sqlCommand.Parameters.AddRange(command.Parameters);
|
||||
|
||||
using (SQLReader sqlReader = sqlCommand.ExecuteReader())
|
||||
{
|
||||
sqlCommand.Parameters.Clear();
|
||||
|
||||
while (sqlReader.Read())
|
||||
{
|
||||
yield return expression(sqlReader);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal method called from <see cref="LaaProduction.Data.SQL.ISQLCommand"/>.
|
||||
/// Like in a <see cref="System.Data.SqlClient.SqlCommand"/> performs SELECT, READ, UPDATE, DELETE queries and returns first column from the first row from the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">From user specified.</typeparam>
|
||||
/// <param name="command"><see cref="System.String"/> - SQL query String</param>
|
||||
/// <param name="expression">Expression that reads specified data from the <see cref="LaaProduction.Data.SQL.ISQLReader"/>.</param>
|
||||
/// <returns><see cref="System.Collections.Generic.IEnumerable{T}"/></returns>
|
||||
internal T ExecuteScalar<T>(SQLCommand command, Func<ISQLReader, T> expression)
|
||||
{
|
||||
var scalarResult = default(T);
|
||||
|
||||
using (var sqlConnection = new SqlConnection(this.connectionString))
|
||||
{
|
||||
this.OpenWithErrorHandling(sqlConnection);
|
||||
|
||||
using (var sqlCommand = sqlConnection.CreateCommand())
|
||||
{
|
||||
sqlCommand.CommandText = command.CommandText;
|
||||
|
||||
sqlCommand.Parameters.AddRange(command.Parameters);
|
||||
|
||||
var scalarObject = sqlCommand.ExecuteScalar();
|
||||
|
||||
sqlCommand.Parameters.Clear();
|
||||
|
||||
if (scalarObject is T scalarValue)
|
||||
{
|
||||
scalarResult = scalarValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return scalarResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is same like <see cref="LaaProduction.Data.SQL.SQLConnection.ExecuteReader{T}(SQLCommand, Func{ISQLReader, T})"/> but returns only the first data row.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">From user specified.</typeparam>
|
||||
/// <param name="command"><see cref="System.String"/> - SQL query String</param>
|
||||
/// <param name="expression">Expression that reads specified data from the <see cref="LaaProduction.Data.SQL.ISQLReader"/>.</param>
|
||||
/// <returns><see cref="{T}"/></returns>
|
||||
internal T FirstOrDefault<T>(SQLCommand command, Func<ISQLReader, T> expression)
|
||||
=> this
|
||||
.ExecuteReader(command, expression)
|
||||
.FirstOrDefault();
|
||||
|
||||
private void OpenWithErrorHandling(SqlConnection connection)
|
||||
{
|
||||
connection.FireInfoMessageEventOnUserErrors = true;
|
||||
connection.InfoMessage += (sender, args) =>
|
||||
{
|
||||
var errors = new StringBuilder();
|
||||
|
||||
foreach (SqlError e in args.Errors)
|
||||
{
|
||||
errors.Append($"Server:{e.Server}|Source:{e.Source}|State:{e.State}|Class:{e.Class}|Number:{e.Number}|Line:{e.LineNumber}|Message:{e.Message}");
|
||||
}
|
||||
|
||||
this.errorCallback?.Invoke(errors.ToString());
|
||||
};
|
||||
|
||||
connection.Open();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
namespace LaaProduction.Data.SQL
|
||||
{
|
||||
using LaaProduction.Data.SQL.Interfaces;
|
||||
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
public class SQLReader : ISQLReader, IDisposable
|
||||
{
|
||||
private readonly SqlDataReader sqlDataReader;
|
||||
|
||||
private SQLReader(SqlDataReader sqlDataReader)
|
||||
=> this.sqlDataReader = sqlDataReader;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.sqlDataReader.Close();
|
||||
this.sqlDataReader.Dispose();
|
||||
}
|
||||
|
||||
public T GetValue<T>(Int32 index)
|
||||
{
|
||||
if (!this.sqlDataReader.IsDBNull(index))
|
||||
{
|
||||
var value = this.sqlDataReader.GetValue(index);
|
||||
var type = Nullable.GetUnderlyingType(typeof(T));
|
||||
|
||||
if (type is null)
|
||||
{
|
||||
type = typeof(T);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
value = Convert.ChangeType(value, type);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// TODO:
|
||||
}
|
||||
|
||||
if (value is T _value)
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
}
|
||||
|
||||
return default(T);
|
||||
}
|
||||
|
||||
public T GetValue<T>(String column)
|
||||
{
|
||||
var table = this.sqlDataReader.GetSchemaTable();
|
||||
|
||||
if (table?.Columns?.Contains(column) == true)
|
||||
{
|
||||
var index = this.sqlDataReader.GetOrdinal(column);
|
||||
|
||||
return this.GetValue<T>(index);
|
||||
}
|
||||
|
||||
return default(T);
|
||||
}
|
||||
|
||||
internal Boolean Read()
|
||||
=> this.sqlDataReader.Read();
|
||||
|
||||
public static implicit operator SQLReader(SqlDataReader sqlDataReader)
|
||||
=> new SQLReader(sqlDataReader);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.1" newVersion="8.0.0.1" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net481" />
|
||||
<package id="Microsoft.Extensions.DependencyInjection" version="8.0.0" targetFramework="net481" />
|
||||
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="8.0.1" targetFramework="net481" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net481" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net481" />
|
||||
</packages>
|
||||
@@ -1,120 +0,0 @@
|
||||
namespace LaaProduction.Http
|
||||
{
|
||||
using LaaProduction.Http.Interfaces;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
public class HttpClient : IHttpClient
|
||||
{
|
||||
private static readonly System.Net.Http.HttpClient http = new System.Net.Http.HttpClient();
|
||||
|
||||
private Uri baseURL;
|
||||
|
||||
public HttpClient()
|
||||
{
|
||||
}
|
||||
|
||||
public HttpClient(String baseURL)
|
||||
=> this.BaseURL(baseURL);
|
||||
|
||||
public void BaseURL(String baseURL)
|
||||
=> this.baseURL = new Uri(baseURL, UriKind.Absolute);
|
||||
|
||||
public HttpResponse<T> DELETE<T>(String url, String bearer = null)
|
||||
=> this.HttpRequestHandler<T>(HttpMethod.Delete, url, bearer: bearer);
|
||||
|
||||
public HttpResponse<T> DELETE<T>(String url)
|
||||
=> this.HttpRequestHandler<T>(HttpMethod.Delete, url);
|
||||
|
||||
public HttpResponse<T> GET<T>(String url, String bearer = null)
|
||||
=> this.HttpRequestHandler<T>(HttpMethod.Get, url, bearer: bearer);
|
||||
|
||||
public HttpResponse<T> GET<T>(String url)
|
||||
=> this.HttpRequestHandler<T>(HttpMethod.Get, url);
|
||||
|
||||
public HttpResponse<T> POST<T>(String url, String bearer = null, Object body = null)
|
||||
=> this.HttpRequestHandler<T>(HttpMethod.Post, url, bearer: bearer, body: body);
|
||||
|
||||
public HttpResponse<T> POST<T>(String url)
|
||||
=> this.HttpRequestHandler<T>(HttpMethod.Post, url);
|
||||
|
||||
public HttpResponse<T> POST<T>(String url, Object body)
|
||||
=> this.HttpRequestHandler<T>(HttpMethod.Post, url, body: body);
|
||||
|
||||
public HttpResponse<T> POST<T>(String url, String bearer)
|
||||
=> this.HttpRequestHandler<T>(HttpMethod.Post, url, bearer: bearer);
|
||||
|
||||
public HttpResponse<T> PUT<T>(String url, String bearer = null, Object body = null)
|
||||
=> this.HttpRequestHandler<T>(HttpMethod.Put, url, bearer: bearer, body: body);
|
||||
|
||||
public HttpResponse<T> PUT<T>(String url)
|
||||
=> this.HttpRequestHandler<T>(HttpMethod.Post, url);
|
||||
|
||||
public HttpResponse<T> PUT<T>(String url, Object body)
|
||||
=> this.HttpRequestHandler<T>(HttpMethod.Put, url, body: body);
|
||||
|
||||
public HttpResponse<T> PUT<T>(String url, String bearer)
|
||||
=> this.HttpRequestHandler<T>(HttpMethod.Put, url, bearer: bearer);
|
||||
|
||||
private HttpResponse<T> HttpRequestHandler<T>(HttpMethod method, String url, String bearer = null, Object body = null)
|
||||
{
|
||||
var result = default(HttpResponse<T>);
|
||||
var uri = default(Uri);
|
||||
|
||||
try
|
||||
{
|
||||
uri = new Uri(this.baseURL, new Uri(url, UriKind.Relative));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
uri = new Uri(url);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (var request = new HttpRequestMessage(method, uri))
|
||||
{
|
||||
if (body != null)
|
||||
{
|
||||
request.Content = new StringContent(JsonConvert.SerializeObject(body));
|
||||
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
||||
}
|
||||
|
||||
if (!String.IsNullOrWhiteSpace(bearer))
|
||||
{
|
||||
http.DefaultRequestHeaders
|
||||
.Authorization = new AuthenticationHeaderValue("Bearer", bearer);
|
||||
}
|
||||
|
||||
using (var response = http.SendAsync(request).Result)
|
||||
{
|
||||
using (var content = response.Content)
|
||||
{
|
||||
var text = content.ReadAsStringAsync().Result;
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<T>(text);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = JsonConvert.DeserializeObject<Dictionary<String, String>>(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
result = e;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
namespace LaaProduction.Http
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class HttpResponse<T>
|
||||
{
|
||||
private Exception exception;
|
||||
|
||||
private HttpResponse(Boolean succeeded)
|
||||
=> this.Succeeded = succeeded;
|
||||
|
||||
private HttpResponse(T value) : this(true)
|
||||
=> this.Value = value;
|
||||
|
||||
private HttpResponse(Dictionary<String, String> errors) : this(false)
|
||||
=> this.Errors = errors;
|
||||
|
||||
public HttpResponse(Exception exception) : this(false)
|
||||
=> this.exception = exception;
|
||||
|
||||
public Boolean Succeeded { get; }
|
||||
|
||||
public T Value { get; }
|
||||
|
||||
public Exception Exception { get; }
|
||||
|
||||
public Dictionary<String, String> Errors { get; }
|
||||
|
||||
public static implicit operator HttpResponse<T>(Boolean succeeded)
|
||||
=> new HttpResponse<T>(succeeded);
|
||||
|
||||
public static implicit operator HttpResponse<T>(T value)
|
||||
=> new HttpResponse<T>(value);
|
||||
|
||||
public static implicit operator HttpResponse<T>(Dictionary<String, String> errors)
|
||||
=> new HttpResponse<T>(errors);
|
||||
|
||||
public static implicit operator HttpResponse<T>(Exception exception)
|
||||
=> new HttpResponse<T>(exception);
|
||||
|
||||
public static implicit operator Boolean(HttpResponse<T> result)
|
||||
=> result?.Succeeded ?? false;
|
||||
|
||||
public static implicit operator T(HttpResponse<T> result)
|
||||
=> result is null ? default(T) : result.Value;
|
||||
|
||||
public static implicit operator Dictionary<String, String>(HttpResponse<T> result)
|
||||
=> result?.Errors ?? new Dictionary<String, String>();
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
namespace LaaProduction.Http.Interfaces
|
||||
{
|
||||
using System;
|
||||
|
||||
public interface IHttpClient
|
||||
{
|
||||
void BaseURL(String baseURL);
|
||||
|
||||
HttpResponse<T> DELETE<T>(String uri);
|
||||
|
||||
HttpResponse<T> DELETE<T>(String uri, String bearer);
|
||||
|
||||
HttpResponse<T> GET<T>(String uri);
|
||||
|
||||
HttpResponse<T> GET<T>(String uri, String bearer);
|
||||
|
||||
HttpResponse<T> POST<T>(String uri);
|
||||
|
||||
HttpResponse<T> POST<T>(String uri, Object body);
|
||||
|
||||
HttpResponse<T> POST<T>(String uri, String bearer);
|
||||
|
||||
HttpResponse<T> POST<T>(String uri, String bearer, Object body);
|
||||
|
||||
HttpResponse<T> PUT<T>(String uri);
|
||||
|
||||
HttpResponse<T> PUT<T>(String uri, Object body);
|
||||
|
||||
HttpResponse<T> PUT<T>(String uri, String bearer);
|
||||
|
||||
HttpResponse<T> PUT<T>(String uri, String bearer, Object body);
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{197185D3-53B7-41A1-A099-CE9F85D5C8F9}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>LaaProduction.Http</RootNamespace>
|
||||
<AssemblyName>LaaProduction.Http</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<NoWarn>IDE0003;IDE0049;</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.8.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=8.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.8.0.1\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\newtonsoft.json\11.0.2\lib\netstandard2.0\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="HttpClient.cs" />
|
||||
<Compile Include="HttpResponse[T].cs" />
|
||||
<Compile Include="Interfaces\IHttpClient.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="README.md" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>del "$(TargetDir)*.pdb"
|
||||
del "$(TargetDir)*.xml"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -1,36 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("LaaProduction.Http")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("LaaProduction.Http")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2024")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("197185d3-53b7-41a1-a099-ce9f85d5c8f9")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="RestSharp" publicKeyToken="598062e77f915f75" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-110.2.0.0" newVersion="110.2.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.3" newVersion="8.0.0.3" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.1" newVersion="8.0.0.1" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net481" />
|
||||
<package id="Microsoft.Extensions.DependencyInjection" version="8.0.0" targetFramework="net481" />
|
||||
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="8.0.1" targetFramework="net481" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net481" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net481" />
|
||||
</packages>
|
||||
@@ -1,20 +0,0 @@
|
||||
namespace LaaProduction.SQL.Interfaces
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public interface ISQLCommand
|
||||
{
|
||||
Int32 ExecuteNonQuery();
|
||||
|
||||
IEnumerable<T> ExecuteReader<T>(Func<ISQLReader, T> expression);
|
||||
|
||||
T ExecuteScalar<T>(Func<ISQLReader, T> expression);
|
||||
|
||||
T FirstOrDefault<T>(Func<ISQLReader, T> expression);
|
||||
|
||||
ISQLCommand SetParameter(String name, Object value);
|
||||
|
||||
ISQLCommand SetParameters(IEnumerable<KeyValuePair<String, Object>> parameters);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
namespace LaaProduction.SQL.Interfaces
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="ISQLConnection"/> simply exposes the <see cref="ISQLConnection.CreateCommand(String)"/> method.
|
||||
/// </summary>
|
||||
public interface ISQLConnection
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a command with given command text.
|
||||
/// </summary>
|
||||
/// <param name="commandText"><see cref="System.String"/> - SQL query String.</param>
|
||||
/// <returns></returns>
|
||||
ISQLCommand CreateCommand(String commandText);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace LaaProduction.SQL.Interfaces
|
||||
{
|
||||
using System;
|
||||
|
||||
public interface ISQLReader
|
||||
{
|
||||
T GetValue<T>();
|
||||
|
||||
Object GetValue(String column);
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{5A3F8AA8-D8CB-4AB4-B6B7-C378A582CE75}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>LaaProduction.SQL</RootNamespace>
|
||||
<AssemblyName>LaaProduction.SQL</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<NoWarn>IDE0003;IDE0049;</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.8.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=8.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.8.0.1\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Interfaces\ISQLCommand.cs" />
|
||||
<Compile Include="Interfaces\ISQLConnection.cs" />
|
||||
<Compile Include="Interfaces\ISQLReader.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SQLCommand.cs" />
|
||||
<Compile Include="SQLConnection.cs" />
|
||||
<Compile Include="SQLExtensions.cs" />
|
||||
<Compile Include="SQLReader.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>del "$(TargetDir)*.pdb"
|
||||
del "$(TargetDir)*.xml"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -1,36 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("LaaProduction.SQL")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("LaaProduction.SQL")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2024")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("5a3f8aa8-d8cb-4ab4-b6b7-c378a582ce75")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -1,70 +0,0 @@
|
||||
namespace LaaProduction.SQL
|
||||
{
|
||||
using LaaProduction.SQL.Interfaces;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
|
||||
public class SQLCommand : ISQLCommand
|
||||
{
|
||||
private readonly SQLConnection sqlConnection;
|
||||
private readonly IDictionary<String, SqlParameter> parameters;
|
||||
|
||||
public SQLCommand(SQLConnection sqlConnection, String commandText)
|
||||
{
|
||||
this.sqlConnection = sqlConnection.EnsureNotNull(nameof(sqlConnection));
|
||||
this.CommandText = commandText.EnsureNotNullOrWhiteSpace(nameof(commandText));
|
||||
this.parameters = new Dictionary<String, SqlParameter>();
|
||||
}
|
||||
|
||||
internal String CommandText { get; }
|
||||
|
||||
internal SqlParameter[] Parameters
|
||||
=> this.parameters.Values.ToArray();
|
||||
|
||||
public Int32 ExecuteNonQuery()
|
||||
=> this.sqlConnection.ExecuteNonQuery(this);
|
||||
|
||||
public IEnumerable<T> ExecuteReader<T>(Func<ISQLReader, T> expression)
|
||||
{
|
||||
foreach (var result in this.sqlConnection.ExecuteReader(this, expression))
|
||||
{
|
||||
yield return result;
|
||||
}
|
||||
}
|
||||
|
||||
public T ExecuteScalar<T>(Func<ISQLReader, T> expression)
|
||||
=> this.sqlConnection.ExecuteScalar(this, expression);
|
||||
|
||||
public T FirstOrDefault<T>(Func<ISQLReader, T> expression)
|
||||
=> this.sqlConnection.FirstOrDefault(this, expression);
|
||||
|
||||
public ISQLCommand SetParameter(String name, Object value)
|
||||
{
|
||||
name.ThrowIfNullOrWhiteSpace(nameof(name));
|
||||
|
||||
if (value is null)
|
||||
{
|
||||
value = DBNull.Value;
|
||||
}
|
||||
|
||||
var parameter = new SqlParameter(name, value);
|
||||
|
||||
this.parameters[name] = parameter;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISQLCommand SetParameters(IEnumerable<KeyValuePair<String, Object>> parameters)
|
||||
{
|
||||
foreach (var kvp in parameters)
|
||||
{
|
||||
this.SetParameter(kvp.Key, kvp.Value);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,187 +0,0 @@
|
||||
namespace LaaProduction.SQL
|
||||
{
|
||||
using LaaProduction.SQL.Interfaces;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
|
||||
/// <summary>
|
||||
/// A wrapper class around the <see cref="System.Data.SqlClient"/>.
|
||||
/// Exposes <see cref="System.Data.SqlClient.SqlConnection"/>, <see cref="System.Data.SqlClient.SqlCommand"/> and <see cref="System.Data.SqlClient.SqlDataReader"/> classes
|
||||
/// in a fluent manner, all exposed methods can be chained in a single C# query.
|
||||
/// </summary>
|
||||
public class SQLConnection : ISQLConnection
|
||||
{
|
||||
private readonly String connectionString;
|
||||
private readonly Action<String> errorCallback;
|
||||
|
||||
/// <summary>
|
||||
/// When <paramref name="connectionString"/> is null, white space or is not a valid connection String exception is thrown.
|
||||
/// </summary>
|
||||
/// <param name="connectionString"><see cref="System.String"/> - SQL connection String.</param>
|
||||
public SQLConnection(String connectionString)
|
||||
{
|
||||
connectionString.ThrowIfNullOrWhiteSpace(nameof(connectionString));
|
||||
|
||||
var connectionStringBuilder = new SqlConnectionStringBuilder(connectionString);
|
||||
|
||||
this.connectionString = connectionStringBuilder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When <paramref name="connectionString"/> is null, white space or is not a valid connection String exception is thrown.
|
||||
/// Additionaly accepts <see cref="System.Action{System.String}"/> for error handling.
|
||||
/// Whenever the sql query throws error on execution, this will be passesd within the callback.
|
||||
/// </summary>
|
||||
/// <param name="connectionString"><see cref="System.String"/> - SQL connection String.</param>
|
||||
/// <param name="errorCallback"><see cref="System.Action{System.String}"/> - error handler for SQL execution errors.</param>
|
||||
public SQLConnection(String connectionString, Action<String> errorCallback = null)
|
||||
: this(connectionString)
|
||||
=> this.errorCallback = errorCallback;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="LaaProduction.SQL.Interfaces.ISQLCommand"/> wrapper that accepts a SQL query String.
|
||||
/// </summary>
|
||||
/// <param name="commandText"><see cref="System.String"/> - SQL query String</param>
|
||||
/// <returns><see cref="LaaProduction.SQL.Interfaces.ISQLCommand"/> - that exposes basic functionalities from the <see cref="System.Data.SqlClient.SqlCommand" />.</returns>
|
||||
public ISQLCommand CreateCommand(String commandText)
|
||||
=> new SQLCommand(this, commandText);
|
||||
|
||||
/// <summary>
|
||||
/// Static method that creates a <see cref="LaaProduction.SQL.Interfaces.ISQLConnection"/> client with given connection String.
|
||||
/// </summary>
|
||||
/// <param name="connectionString"><see cref="System.String"/> - SQL connection String.</param>
|
||||
/// <returns><see cref="LaaProduction.SQL.Interfaces.ISQLConnection"/></returns>
|
||||
public static ISQLConnection CreateSQLConnection(String connectionString)
|
||||
=> new SQLConnection(connectionString);
|
||||
|
||||
/// <summary>
|
||||
/// Static method that creates a <see cref="LaaProduction.SQL.Interfaces.ISQLConnection"/> client with given connection String and error callback that receives all error messages.
|
||||
/// </summary>
|
||||
/// <param name="connectionString"><see cref="System.String"/> - SQL connection String.</param>
|
||||
/// <param name="errorCallback"><see cref="System.Action{System.String}"/> - error handler for SQL execution errors.</param>
|
||||
/// <returns><see cref="LaaProduction.SQL.Interfaces.ISQLConnection"/></returns>
|
||||
public static ISQLConnection CreateSQLConnection(String connectionString, Action<String> errorCallback = null)
|
||||
=> new SQLConnection(connectionString, errorCallback);
|
||||
|
||||
/// <summary>
|
||||
/// Internal method called from <see cref="LaaProduction.SQL.Interfaces.ISQLCommand"/>.
|
||||
/// Like in a <see cref="System.Data.SqlClient.SqlCommand"/> performs INSERT, UPDATE, DELETE queries and returns the number of rows affected.
|
||||
/// </summary>
|
||||
/// <param name="command"><see cref="System.String"/> - SQL query String</param>
|
||||
/// <returns><see cref="System.Int32"/> - the number of rows affected.</returns>
|
||||
internal Int32 ExecuteNonQuery(SQLCommand command)
|
||||
{
|
||||
command.ThrowIfNull(nameof(command));
|
||||
|
||||
var rowsAffected = 0;
|
||||
|
||||
using (var sqlConnection = new SqlConnection(this.connectionString))
|
||||
{
|
||||
sqlConnection.OpenWithErrorHandling(this.errorCallback);
|
||||
|
||||
using (var sqlCommand = sqlConnection.CreateCommand())
|
||||
{
|
||||
sqlCommand.CommandText = command.CommandText;
|
||||
|
||||
sqlCommand.Parameters.AddRange(command.Parameters);
|
||||
|
||||
rowsAffected = sqlCommand.ExecuteNonQuery();
|
||||
|
||||
sqlCommand.Parameters.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
return rowsAffected;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal method called from <see cref="LaaProduction.SQL.Interfaces.ISQLCommand"/>.
|
||||
/// Like in a <see cref="System.Data.SqlClient.SqlCommand"/> performs SELECT queries and returns a enumerable of the results readed.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Is the type that returns the <see cref="System.Func{IFluentSQLReader, T} expression"/></typeparam>
|
||||
/// <param name="command"><see cref="System.String"/> - SQL query String</param>
|
||||
/// <param name="expression">Expression that reads specified data from the <see cref="LaaProduction.SQL.Interfaces.ISQLReader"/>.</param>
|
||||
/// <returns><see cref="System.Collections.Generic.IEnumerable{T}"/></returns>
|
||||
internal IEnumerable<T> ExecuteReader<T>(SQLCommand command, Func<ISQLReader, T> expression)
|
||||
{
|
||||
command.ThrowIfNull(nameof(command));
|
||||
expression.ThrowIfNull(nameof(expression));
|
||||
|
||||
using (var sqlConnection = new SqlConnection(this.connectionString))
|
||||
{
|
||||
sqlConnection.OpenWithErrorHandling(this.errorCallback);
|
||||
|
||||
using (var sqlCommand = sqlConnection.CreateCommand())
|
||||
{
|
||||
sqlCommand.CommandText = command.CommandText;
|
||||
|
||||
sqlCommand.Parameters.AddRange(command.Parameters);
|
||||
|
||||
using (SQLReader sqlReader = sqlCommand.ExecuteReader())
|
||||
{
|
||||
sqlCommand.Parameters.Clear();
|
||||
|
||||
while (sqlReader.Read())
|
||||
{
|
||||
yield return expression(sqlReader);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal method called from <see cref="LaaProduction.SQL.Interfaces.ISQLCommand"/>.
|
||||
/// Like in a <see cref="System.Data.SqlClient.SqlCommand"/> performs SELECT, READ, UPDATE, DELETE queries and returns first column from the first row from the result.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">From user specified.</typeparam>
|
||||
/// <param name="command"><see cref="System.String"/> - SQL query String</param>
|
||||
/// <param name="expression">Expression that reads specified data from the <see cref="LaaProduction.SQL.Interfaces.ISQLReader"/>.</param>
|
||||
/// <returns><see cref="System.Collections.Generic.IEnumerable{T}"/></returns>
|
||||
internal T ExecuteScalar<T>(SQLCommand command, Func<ISQLReader, T> expression)
|
||||
{
|
||||
command.ThrowIfNull(nameof(command));
|
||||
expression.ThrowIfNull(nameof(expression));
|
||||
|
||||
var scalarResult = default(T);
|
||||
|
||||
using (var sqlConnection = new SqlConnection(this.connectionString))
|
||||
{
|
||||
sqlConnection.OpenWithErrorHandling(this.errorCallback);
|
||||
|
||||
using (var sqlCommand = sqlConnection.CreateCommand())
|
||||
{
|
||||
sqlCommand.CommandText = command.CommandText;
|
||||
|
||||
sqlCommand.Parameters.AddRange(command.Parameters);
|
||||
|
||||
var scalarObject = sqlCommand.ExecuteScalar();
|
||||
|
||||
sqlCommand.Parameters.Clear();
|
||||
|
||||
if (scalarObject is T scalarValue)
|
||||
{
|
||||
scalarResult = scalarValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return scalarResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is same like <see cref="LaaProduction.SQL.SQLConnection.ExecuteReader{T}(SQLCommand, Func{ISQLReader, T})"/> but returns only the first data row.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">From user specified.</typeparam>
|
||||
/// <param name="command"><see cref="System.String"/> - SQL query String</param>
|
||||
/// <param name="expression">Expression that reads specified data from the <see cref="LaaProduction.SQL.Interfaces.ISQLReader"/>.</param>
|
||||
/// <returns><see cref="{T}"/></returns>
|
||||
internal T FirstOrDefault<T>(SQLCommand command, Func<ISQLReader, T> expression)
|
||||
=> this
|
||||
.ExecuteReader(command, expression)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
namespace LaaProduction.SQL
|
||||
{
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
public static class SQLExtensions
|
||||
{
|
||||
internal static T EnsureNotNull<T>(this T value, [CallerMemberName] String memberName = "")
|
||||
{
|
||||
value.ThrowIfNull(memberName);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
internal static String EnsureNotNullOrWhiteSpace(this String value, [CallerMemberName] String memberName = "")
|
||||
{
|
||||
value.ThrowIfNullOrWhiteSpace(memberName);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
internal static void ThrowIfNull<T>(this T value, [CallerMemberName] String memberName = "")
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new ArgumentException($"{memberName} should not be null.", memberName);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ThrowIfNullOrWhiteSpace(this String value, [CallerMemberName] String memberName = "")
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
throw new ArgumentException($"{memberName} should not be null or white space.", memberName);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void OpenWithErrorHandling(this SqlConnection sqlConnection, Action<String> errorCallback)
|
||||
{
|
||||
sqlConnection.ThrowIfNull(nameof(sqlConnection));
|
||||
|
||||
sqlConnection.FireInfoMessageEventOnUserErrors = true;
|
||||
|
||||
if (errorCallback != null)
|
||||
{
|
||||
sqlConnection.InfoMessage += (_, args) => errorCallback(args.Message);
|
||||
}
|
||||
|
||||
sqlConnection.Open();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
namespace LaaProduction.SQL
|
||||
{
|
||||
using LaaProduction.SQL.Interfaces;
|
||||
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
public class SQLReader : ISQLReader, IDisposable
|
||||
{
|
||||
private readonly SqlDataReader sqlDataReader;
|
||||
|
||||
private Int32 index;
|
||||
|
||||
private SQLReader(SqlDataReader sqlDataReader)
|
||||
=> this.sqlDataReader = sqlDataReader.EnsureNotNull(nameof(sqlDataReader));
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.sqlDataReader.Close();
|
||||
this.sqlDataReader.Dispose();
|
||||
}
|
||||
|
||||
public T GetValue<T>()
|
||||
{
|
||||
this.index++;
|
||||
|
||||
if (!this.sqlDataReader.IsDBNull(this.index))
|
||||
{
|
||||
var value = this.sqlDataReader.GetValue(this.index);
|
||||
var type = Nullable.GetUnderlyingType(typeof(T));
|
||||
|
||||
if (type is null)
|
||||
{
|
||||
type = typeof(T);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
value = Convert.ChangeType(value, type);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// TODO:
|
||||
}
|
||||
|
||||
if (value is T _value)
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
}
|
||||
|
||||
return default(T);
|
||||
}
|
||||
|
||||
public Object GetValue(String column)
|
||||
{
|
||||
column.EnsureNotNullOrWhiteSpace(nameof(column));
|
||||
|
||||
var colIndex = this.sqlDataReader.GetOrdinal(column);
|
||||
|
||||
if (0 <= colIndex && colIndex < this.sqlDataReader.FieldCount)
|
||||
{
|
||||
if (!this.sqlDataReader.IsDBNull(colIndex))
|
||||
{
|
||||
return this.sqlDataReader.GetValue(colIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return default(Object);
|
||||
}
|
||||
|
||||
internal Boolean Read()
|
||||
{
|
||||
this.index = -1;
|
||||
|
||||
return this.sqlDataReader.Read();
|
||||
}
|
||||
|
||||
public static implicit operator SQLReader(SqlDataReader sqlDataReader)
|
||||
=> new SQLReader(sqlDataReader);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.1" newVersion="8.0.0.1" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net481" />
|
||||
<package id="Microsoft.Extensions.DependencyInjection" version="8.0.0" targetFramework="net481" />
|
||||
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="8.0.1" targetFramework="net481" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net481" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net481" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user