Voyager.DBConnection.Logging 4.1.2

dotnet add package Voyager.DBConnection.Logging --version 4.1.2                
NuGet\Install-Package Voyager.DBConnection.Logging -Version 4.1.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Voyager.DBConnection.Logging" Version="4.1.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Voyager.DBConnection.Logging --version 4.1.2                
#r "nuget: Voyager.DBConnection.Logging, 4.1.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Voyager.DBConnection.Logging as a Cake Addin
#addin nuget:?package=Voyager.DBConnection.Logging&version=4.1.2

// Install Voyager.DBConnection.Logging as a Cake Tool
#tool nuget:?package=Voyager.DBConnection.Logging&version=4.1.2                

Voyager.DBConnection

Library providing connection to SQL database using DbProviderFactory.

How to use it

Implement interface Voyager.DBConnection.Interfaces.ICommandFactory:

	public interface ICommandFactory : IReadOutParameters
	{
		DbCommand ConstructDbCommand(Database db);
	}

Example code is like:

	internal class SetPilotiDoPowiadomieniaFactory : Voyager.DBConnection.Interfaces.ICommandFactory
	{
		private readonly int idBusMapRNo;
		private readonly DateTime busMapDate;
		private readonly string idAkwizytor;
		private readonly string raport;

		public SetPilotiDoPowiadomieniaFactory(int idBusMapRNo, DateTime busMapDate, string idAkwizytor, string raport)
		{
			this.idBusMapRNo = idBusMapRNo;
			this.busMapDate = busMapDate;
			this.idAkwizytor = idAkwizytor;
			this.raport = raport;
		}
		public DbCommand ConstructDbCommand(Database db)
		{
			var cmd = db.GetStoredProcCommand("BusMap.p_SetPilotiDoPowiadomienia");
			db.AddInParameter(cmd, "IdBusMapRNo", DbType.Int32, this.idBusMapRNo);
			db.AddInParameter(cmd, "BusMapDate", DbType.Date, this.busMapDate);
			db.AddInParameter(cmd, "IdAkwizytor", DbType.AnsiString, this.idAkwizytor);
			db.AddInParameter(cmd, "Raport", DbType.AnsiString, this.raport);

			return cmd;
		}

		public void ReadOutParameters(Database db, DbCommand command)
		{
		}
	}

Using your DbProviderFactory create your type of database object Voyager.DBConnection.Database and Voyager.DBConnection.Connection. On the connection object call ExecuteNonQuery the command factory:

			SetPilotiDoPowiadomieniaFactory factory = new SetPilotiDoPowiadomieniaFactory(tagItem.IdBusMapRNp, tagItem.BusMapDate, tagItem.IdAkwizytor, tagItem.Raport);
			con.ExecuteNonQuery(factory);

For reading data implement IGetConsumer interface:

internal class RegionalSaleCommand : Voyager.DBConnection.Interfaces.ICommandFactory, IGetConsumer<SaleItem[]>
	{
		private RaportRequest request;

		public RegionalSaleCommand(RaportRequest request)
		{
			this.request = request;
		}
		public DbCommand ConstructDbCommand(Database db)
		{
			var cmd = db.GetStoredProcCommand("[dbo].[TestSaleReport]");
			db.AddInParameter(cmd, "IdAkwizytorRowNo", System.Data.DbType.Int32, request.IdAkwizytorRowNo);
			db.AddInParameter(cmd, "IdPrzewoznikRowNo", System.Data.DbType.Int32, request.IdPrzewoznikRowNo);
			db.AddInParameter(cmd, "DataPocz", System.Data.DbType.DateTime, request.DateFrom);
			db.AddInParameter(cmd, "DataKon", System.Data.DbType.DateTime, request.DateTo);

			return cmd;
		}

		public SaleItem[] GetResults(IDataReader dataReader)
		{
			List<SaleItem> lista = new List<SaleItem>();

			while (dataReader.Read())
			{
				int col = 0;
				SaleItem item = new SaleItem();
				item.GidRezerwacji = dataReader.GetString(col++);
				item.GIDL = dataReader.GetString(col++);

				DateTime data = dataReader.GetDateTime(col++);

				var ts = dataReader.GetValue(col++);

				TimeSpan czas = ts.ToString().CastTimeSpan();

				item.DataSprzedazy = data.AddTicks(czas.Ticks);
				item.IdWaluta = dataReader.GetString(col++);
				item.IdWalutaBazowa = DBSafeCast.CastEmptyString(dataReader.GetValue(col++));
				item.KursDniaBaz = (Double)DBSafeCast.Cast<Decimal>(dataReader.GetValue(col++), 1);
				item.NettoZ = DBSafeCast.Cast<Decimal>(dataReader.GetValue(col++), 0);
				item.WalutaZcennika = dataReader.GetBoolean(col++);

				lista.Add(item);
			}


			return lista.ToArray();
		}

		public void ReadOutParameters(Database db, DbCommand command)
		{

		}
	}

Next, call the GetReader method:

		public class RaportDB : Voyager.Raport.DBEntity.Store.Raport
	{
		private readonly Connection connection;

		public RaportDB(Voyager.DBConnection.Connection connection)
		{
			this.connection = connection;
		}
		public RaportResponse GetRaport(RaportRequest request)
		{
			RegionalSaleCommand raport = new RegionalSaleCommand(request);
			return new RaportResponse()
			{
				Items = connection.GetReader(raport, raport)
			};
		}
	}

Logging

There is an extension used to log operations. Voyager.DBConnection.Logging. After installing on the connection obcjet is needed to call extension:


namespace Voyager.DBConnection
{
	public static class ConnectionLogger
	{
		public static void AddLogger(this Connection connection, ILogger logger)
		{
			connection.AddFeature(new LogFeature(logger, connection));
		}
	}
}

MS Sql provider

For using MS SQL Provider is prepared the Nuget Voyager.DBConnection.MySql. There is provided implementation of the connection object:

namespace Voyager.DBConnection.MsSql
{
	public class SqlConnection : Connection
	{
		public SqlConnection(string sqlConnectionString) : base(new SqlDatabase(sqlConnectionString), new ExceptionFactory())
		{
		}
	}
}

✍️ Authors

  • @andrzejswistowski - Idea & work. Please let me know if you find out an error or suggestions.

contributors.

🎉 Acknowledgements

  • Przemysław Wróbel - for the icon.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.1.2 298 12/5/2023
4.1.1 129 12/5/2023
4.1.0 155 11/22/2023
4.0.3 128 11/13/2023
4.0.0 130 10/31/2023
3.0.0 152 5/5/2023