Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Aug 5, 2024
1 parent bc379ae commit cd0f402
Show file tree
Hide file tree
Showing 17 changed files with 774 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# EditorConfig: https://EditorConfig.org

root = true

# All Files
[*]
charset = utf-8
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

# XML Configuration Files
[*.{xml,config,props,targets,nuspec,resx,ruleset,vsixmanifest,vsct,refactorlog,runsettings}]
indent_size = 2

# JSON Files
[*.{json,json5,webmanifest}]
indent_size = 2

# Project Files
[*.{csproj,sqlproj}]
indent_size = 2

# YAML Files
[*.{yml,yaml}]
indent_size = 2

# Markdown Files
[*.md]
trim_trailing_whitespace = false

# Web Files
[*.{htm,html,js,jsm,ts,tsx,css,sass,scss,less,pcss,svg,vue}]
indent_size = 2

# Batch Files
[*.{cmd,bat}]
end_of_line = crlf

# Bash Files
[*.sh]
end_of_line = lf

[*.{cs,vb}]
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = true
dotnet_style_namespace_match_folder = true

[*.cs]
csharp_using_directive_placement = outside_namespace
csharp_style_namespace_declarations = file_scoped:warning
45 changes: 45 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
* text=auto

*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

*.bmp binary
*.gif binary
*.jpg binary
*.png binary

*.ascx text
*.cmd text
*.coffee text
*.config text
*.cs text diff=csharp
*.csproj text merge=union
*.css text
*.cshtml text
*.htm text
*.html text
*.htm text
*.js text
*.msbuild text
*.resx text merge=union
*.ruleset text
*.Stylecop text
*.sql text
*.targets text
*.tt text
*.txt text
*.vb text
*.vbhtml text
*.vbproj text merge=union
*.xml text
*.xunit text

*.sln text eol=crlf merge=union
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: daily
time: "01:00"
open-pull-requests-limit: 10

- package-ecosystem: nuget
directory: "/"
schedule:
interval: daily
time: "11:00"
open-pull-requests-limit: 10
99 changes: 99 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Build

env:
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_ENVIRONMENT: github
ASPNETCORE_ENVIRONMENT: github
BUILD_PATH: '${{github.workspace}}/artifacts'

on:
push:
branches:
- main
- develop
tags:
- 'v*'
paths-ignore:
- 'docs/**'
- 'mkdocs.yml'
pull_request:
branches:
- main
- develop

jobs:

build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Restore Dependencies
run: dotnet restore

- name: Build Solution
run: dotnet build --no-restore --configuration Release

- name: Run Test
run: dotnet test --no-build --configuration Release --collect:"XPlat Code Coverage" --settings coverlet.runsettings

- name: Report Coverage
if: success()
uses: coverallsapp/github-action@v2
with:
file: '${{github.workspace}}/test/*/TestResults/*/coverage.info'
format: lcov

- name: Create Packages
if: success() && github.event_name != 'pull_request'
run: dotnet pack --configuration Release --include-symbols --include-source --no-build --output "${{env.BUILD_PATH}}"

- name: Upload Packages
if: success() && github.event_name != 'pull_request'
uses: actions/upload-artifact@v4
with:
name: packages
path: '${{env.BUILD_PATH}}'

deploy:
runs-on: ubuntu-latest
needs: build
if: success() && github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))

steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: packages

- name: Publish Packages GitHub
run: |
for package in $(find -name "*.nupkg"); do
echo "${0##*/}": Pushing $package...
dotnet nuget push $package --source https://nuget.pkg.github.com/loresoft/index.json --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
done
- name: Publish Packages feedz
run: |
for package in $(find -name "*.nupkg"); do
echo "${0##*/}": Pushing $package...
dotnet nuget push $package --source https://f.feedz.io/loresoft/open/nuget/index.json --api-key ${{ secrets.FEEDDZ_KEY }} --skip-duplicate
done
- name: Publish Packages Nuget
if: startsWith(github.ref, 'refs/tags/v')
run: |
for package in $(find -name "*.nupkg"); do
echo "${0##*/}": Pushing $package...
dotnet nuget push $package --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_KEY }} --skip-duplicate
done
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,4 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml
*.clef
37 changes: 37 additions & 0 deletions LoreSoft.Extensions.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LoreSoft.Extensions", "src\LoreSoft.Extensions\LoreSoft.Extensions.csproj", "{67E6AC70-1373-4807-A1A6-4BC14AE3471D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{D8C0701C-0F0A-44D2-8003-DDD39A74BC3C}"
ProjectSection(SolutionItems) = preProject
.github\workflows\dotnet.yml = .github\workflows\dotnet.yml
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoreSoft.Extensions.Tests", "test\LoreSoft.Extensions.Tests\LoreSoft.Extensions.Tests.csproj", "{BC0FC9BE-7771-4DB1-9BA2-66186716C31D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{67E6AC70-1373-4807-A1A6-4BC14AE3471D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{67E6AC70-1373-4807-A1A6-4BC14AE3471D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67E6AC70-1373-4807-A1A6-4BC14AE3471D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67E6AC70-1373-4807-A1A6-4BC14AE3471D}.Release|Any CPU.Build.0 = Release|Any CPU
{BC0FC9BE-7771-4DB1-9BA2-66186716C31D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC0FC9BE-7771-4DB1-9BA2-66186716C31D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC0FC9BE-7771-4DB1-9BA2-66186716C31D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC0FC9BE-7771-4DB1-9BA2-66186716C31D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F27CAFE9-3406-4BCC-ABE9-8290A536F7D9}
EndGlobalSection
EndGlobal
12 changes: 12 additions & 0 deletions coverlet.runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<Format>lcov</Format>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions src/LoreSoft.Extensions/DataRecordExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System.Data.Common;
using System.Data;
using System;

#nullable enable

namespace LoreSoft.Extensions;

/// <summary>
/// Extension methods for <see cref="IDataRecord"/>.
/// </summary>
public static class DataRecordExtensions
{
/// <summary>Gets the value of the specified column.</summary>
/// <param name="dataRecord">The data record.</param>
/// <param name="name">The name of the column to find.</param>
/// <returns>The value of the specified column.</returns>
public static object? GetValue(this IDataRecord dataRecord, string name)
{
if (dataRecord is null)
throw new ArgumentNullException(nameof(dataRecord));

int ordinal = dataRecord.GetOrdinal(name);
return dataRecord.IsDBNull(ordinal)
? null
: dataRecord.GetValue(ordinal);
}

/// <summary>
/// Gets the value of the specified column as the requested type.
/// </summary>
/// <typeparam name="T">The record value type</typeparam>
/// <param name="dataRecord">The data record.</param>
/// <param name="name">The name of the column to find.</param>
/// <returns>The value of the specified column.</returns>
public static T GetValue<T>(this IDataRecord dataRecord, string name)
{
if (dataRecord is null)
throw new ArgumentNullException(nameof(dataRecord));

int ordinal = dataRecord.GetOrdinal(name);
if (dataRecord is DbDataReader dataReader)
return dataReader.GetFieldValue<T>(ordinal);

return (T)dataRecord.GetValue(ordinal);
}

/// <summary>
/// Gets the value of the specified column as the requested type.
/// </summary>
/// <typeparam name="T">The record value type</typeparam>
/// <param name="dataRecord">The data record.</param>
/// <param name="index">The zero-based column ordinal.</param>
/// <returns>The value of the specified column.</returns>
public static T GetValue<T>(this IDataRecord dataRecord, int index)
{
if (dataRecord is null)
throw new ArgumentNullException(nameof(dataRecord));

if (dataRecord is DbDataReader dataReader)
return dataReader.GetFieldValue<T>(index);

return (T)dataRecord.GetValue(index);
}

/// <summary>Determines whether the specified field is set to <see langword="null"/>.</summary>
/// <param name="dataRecord">The data record.</param>
/// <param name="name">The <paramref name="name"/> of the field to find.</param>
/// <returns><c>true</c> if the specified field is set to <see langword="null"/>; otherwise, <c>false</c>.</returns>
public static bool IsDBNull(this IDataRecord dataRecord, string name)
{
int ordinal = dataRecord.GetOrdinal(name);
return dataRecord.IsDBNull(ordinal);
}

}
43 changes: 43 additions & 0 deletions src/LoreSoft.Extensions/DateOnlyExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;

#nullable enable

namespace LoreSoft.Extensions;

#if NET6_0_OR_GREATER
/// <summary>
/// <see cref="DateOnly" /> extension methods
/// </summary>
public static class DateOnlyExtensions
{
/// <summary>
/// Converts the <see cref="DateOnly"/> to a <see cref="DateTimeOffset"/> in the specified timezone.
/// </summary>
/// <param name="dateOnly">The date to convert.</param>
/// <param name="zone">The time zone the date is in.</param>
/// <returns>The converted <see cref="DateTimeOffset"/></returns>
public static DateTimeOffset ToDateTimeOffset(this DateOnly dateOnly, TimeZoneInfo? zone = null)
{
zone ??= TimeZoneInfo.Local;

var dateTime = dateOnly.ToDateTime(TimeOnly.MinValue);
var offset = zone.GetUtcOffset(dateTime);

return new DateTimeOffset(dateTime, offset);
}

/// <summary>
/// Converts the <see cref="DateTimeOffset"/> to a <see cref="DateOnly"/> in the specified timezone.
/// </summary>
/// <param name="dateTime">The <see cref="DateTimeOffset"/> to convert.</param>
/// <param name="zone">The time zone the date is in.</param>
/// <returns>The converted <see cref="DateOnly"/></returns>
public static DateOnly ToDateOnly(this DateTimeOffset dateTime, TimeZoneInfo? zone = null)
{
zone ??= TimeZoneInfo.Local;

var targetZone = TimeZoneInfo.ConvertTime(dateTime, zone);
return DateOnly.FromDateTime(targetZone.Date);
}
}
#endif
Loading

0 comments on commit cd0f402

Please sign in to comment.