Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project Setup (Part 1) #5

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
851810c
Update description
StefanGreve Aug 10, 2024
989948c
Remove placeholder text in readme and add status badges
StefanGreve Aug 10, 2024
a6b0b78
Add automatically generated documentation
StefanGreve Aug 10, 2024
4543d92
Set default values for MsSqlServerSettings
StefanGreve Aug 10, 2024
341cb61
Add null check for connection string builder helper method
StefanGreve Aug 10, 2024
7cfa68b
Start working on unit test project
StefanGreve Aug 10, 2024
20d2a0d
Uncouple provider-specific object instatiations from service, and ref…
StefanGreve Aug 12, 2024
f4b111e
Continue refactoring and uncoupling of implementation details
StefanGreve Aug 26, 2024
66ba76f
Refactor code
StefanGreve Sep 13, 2024
8b5cdac
Format project and enable warning for missing this qualifier
StefanGreve Oct 27, 2024
e3597fa
Setup pre-commit and pre-push hooks
StefanGreve Nov 9, 2024
2c74a7c
Refactor DbConnectionService and add boilerplate code for unit tests
StefanGreve Feb 22, 2025
e6144a8
Continue development of DbConnectionService and DbConnectionServiceFa…
StefanGreve Mar 14, 2025
02a6d08
Refactor and lint code and start implementation of DbConnectionServic…
StefanGreve Mar 15, 2025
1e16317
Rename Provider to DbProvider
StefanGreve Mar 15, 2025
6b3519d
Test AddDbConnectionService
StefanGreve Mar 15, 2025
7f4b612
Add null check prior to DecryptPassword
StefanGreve Mar 15, 2025
cf6a1b7
Restructure and refactor code
StefanGreve Apr 1, 2025
3115e21
Improve testability of DbConnectionService code
StefanGreve Apr 1, 2025
cf15a15
Set default DbProvider in option records
StefanGreve Apr 1, 2025
d30b75c
Split InternalExtensions class into multiple files
StefanGreve Apr 2, 2025
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
13 changes: 13 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"husky": {
"version": "0.7.1",
"commands": [
"husky"
],
"rollForward": false
}
}
}
15 changes: 8 additions & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ dotnet_sort_system_directives_first = true
file_header_template = unset

# this. and Me. preferences
dotnet_style_qualification_for_event = false:silent
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_qualification_for_event = true:warning
dotnet_style_qualification_for_field = true:warning
dotnet_style_qualification_for_method = true:warning
dotnet_style_qualification_for_property = true:warning

# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
Expand Down Expand Up @@ -78,9 +78,9 @@ dotnet_remove_unnecessary_suppression_exclusions = none
[*.cs]

# var preferences
csharp_style_var_elsewhere = false:silent
csharp_style_var_for_built_in_types = false:silent
csharp_style_var_when_type_is_apparent = false:silent
csharp_style_var_elsewhere = false:warning
csharp_style_var_for_built_in_types = false:warning
csharp_style_var_when_type_is_apparent = true:warning

# Expression-bodied members
csharp_style_expression_bodied_accessors = true:silent
Expand Down Expand Up @@ -174,6 +174,7 @@ csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_prefer_system_threading_lock = true:suggestion

#### Naming styles ####
[*.{cs,vb}]
Expand Down
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# lint project based on editorconfig rules
dotnet husky run --group pre-commit
5 changes: 5 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# build project and run unit tests
dotnet husky run --group pre-push
39 changes: 39 additions & 0 deletions .husky/task-runner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"$schema": "https://alirezanet.github.io/Husky.Net/schema.json",
"tasks": [
{
"name": "dotnet-format",
"group": "pre-commit",
"command": "dotnet",
"args": [
"format",
"--include",
"${staged}",
"--verbosity",
"diagnostic"
],
"include": [
"**/*.cs",
"**/*.ps1"
]
},
{
"name": "dotnet-build",
"group": "pre-push",
"command": "dotnet",
"args": [
"build",
"/warnaserror"
]
},
{
"name": "dotnet-test",
"group": "pre-push",
"command": "dotnet",
"args": [
"test",
"--nologo"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>0.0.0-alpha</Version>
<Description>TODO</Description>
<Description>Abstractions for AdvancedSystems.Connector.</Description>
<PackageId>AdvancedSystems.Connector.Abstractions</PackageId>
<RootNamespace>AdvancedSystems.Connector.Abstractions</RootNamespace>
<Title>Advanced Systems Connector Abstractions Library</Title>
Expand Down
16 changes: 0 additions & 16 deletions AdvancedSystems.Connector.Abstractions/DatabaseCommandType.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
namespace AdvancedSystems.Connector;
namespace AdvancedSystems.Connector.Abstractions;

/// <summary>
/// Represents the different database providers supported by the system.
/// </summary>
public enum Provider
public enum DbProvider
{
/// <summary>
/// Generic SQL Server.
/// </summary>
Generic = 0,

/// <summary>
/// Microsoft SQL Server.
/// </summary>
MsSql,
}
MsSql = 1,
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Data.Common;

namespace AdvancedSystems.Connector.Abstractions.Exceptions;

/// <summary>
/// Represents an error that occurs during the communication with a database.
/// Represents an exception that occurs when a database connection fails.
/// </summary>
public class DbConnectionException : Exception
public class DbConnectionException : DbException
{
/// <summary>
/// Initializes a new instance of the <seealso cref="DbConnectionException"/> class.
Expand All @@ -17,10 +18,10 @@ public DbConnectionException()

/// <summary>
/// Initializes a new instance of the <seealso cref="DbConnectionException"/> class
/// with a specified error <paramref name="message"/>.
/// with the specified error <paramref name="message"/>.
/// </summary>
/// <param name="message">
/// The error message that explains the reason for the exception.
/// The message to display for this exception.
/// </param>
public DbConnectionException(string message) : base(message)
{
Expand All @@ -29,17 +30,17 @@ public DbConnectionException(string message) : base(message)

/// <summary>
/// Initializes a new instance of the <seealso cref="DbConnectionException"/> class
/// with a specified error <paramref name="message"/> a reference to the <paramref name="inner"/>
/// exception that is the cause of this exception.
/// with the specified error <paramref name="message"/> and a reference to the
/// <paramref name="innerException"/> that is cause of this exception.
/// </summary>
/// <param name="message">
/// The error message that explains the reason for the exception.
/// The message to display for this exception.
/// </param>
/// <param name="inner">
/// The exception that is the cause of the current exception, or a null reference if no inner exception is specified.
/// <param name="innerException">
/// The inner exception reference.
/// </param>
public DbConnectionException(string message, Exception inner) : base(message, inner)
public DbConnectionException(string message, Exception innerException) : base(message, innerException)
{

}
}
}
48 changes: 0 additions & 48 deletions AdvancedSystems.Connector.Abstractions/IDatabaseCommand.cs

This file was deleted.

41 changes: 41 additions & 0 deletions AdvancedSystems.Connector.Abstractions/IDbCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Generic;
using System.Data;

namespace AdvancedSystems.Connector.Abstractions;

/// <summary>
/// Defines an SQL statement or stored procedure to execute against a data source.
/// </summary>
public interface IDbCommand
{
#region Properties

/// <summary>
/// Gets or sets the Transact-SQL statement or stored
/// procedure to execute at the data source.
/// </summary>
string CommandText { get; set; }

/// <summary>
/// Gets or sets a value indicating how the <seealso cref="CommandText"/>
/// property is to be interpreted.
/// </summary>
CommandType CommandType { get; set; }

/// <summary>
/// Gets a collection of <seealso cref="IDbParameter"/> parameters.
/// </summary>
IReadOnlyList<IDbParameter> Parameters { get; }

#endregion

#region Methods

void AddParameter(string parameterName, object value, DbType type);

void AddParameter<T>(string parameterName, T value);

string ToString();

#endregion
}
9 changes: 9 additions & 0 deletions AdvancedSystems.Connector.Abstractions/IDbCommandFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Data;
using System.Data.Common;

namespace AdvancedSystems.Connector.Abstractions;

public interface IDbCommandFactory
{
DbCommand Create(DbProvider dbProvider, DbConnection dbConnection, string commandText, CommandType commandType);
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
using System;
using System.Data.Common;

namespace AdvancedSystems.Connector.Abstractions;

/// <summary>
/// Defines a factory for creating instances of <seealso cref="IDatabaseConnectionService"/>.
/// Defines a factory for creating instances of <seealso cref="DbConnection"/>.
/// </summary>
public interface IDatabaseConnectionFactory
public interface IDbConnectionFactory
{
#region Methods

/// <summary>
/// Creates a new instance of <see cref="IDatabaseConnectionService"/> based on the
/// Creates a new instance of <see cref="DbConnection"/> based on the
/// specified provider.
/// </summary>
/// <param name="provider">
/// The database provider for which the connection service should be created.
/// </param>
/// <param name="connectionString">
/// The connection string used to establish the connection with the database.
/// </param>
/// <returns>
/// An instance of <see cref="IDatabaseConnectionService"/> configured for the
/// An instance of <see cref="DbConnection"/> configured for the
/// specified provider.
/// </returns>
/// <exception cref="NotSupportedException">
/// Thrown when the specified <paramref name="provider"/> is not supported by the factory.
/// </exception>
IDatabaseConnectionService Create(Provider provider);
}
DbConnection Create(DbProvider provider, string connectionString);

#endregion
}
Loading