Skip to content

Commit 8ac138a

Browse files
committed
initial setup
1 parent 3fb30b2 commit 8ac138a

9 files changed

Lines changed: 248 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
trigger:
2+
- main
3+
4+
pool:
5+
vmImage: ubuntu-latest
6+
7+
stages:
8+
- stage: buildPush
9+
displayName: 'Deploy Nuget'
10+
jobs:
11+
- job: buildAndPush
12+
displayName: 'Build and Publish'
13+
steps:
14+
- task: NuGetAuthenticate@1
15+
displayName: 'Authenticate to NuGet'
16+
17+
- task: DotNetCoreCLI@2
18+
displayName: Restore
19+
inputs:
20+
command: 'restore'
21+
projects: '**/**.csproj'
22+
feedsToUse: 'config'
23+
nugetConfigPath: 'nuget.config'
24+
noCache: true
25+
26+
- task: DotNetCoreCLI@2
27+
displayName: Build
28+
inputs:
29+
command: 'build'
30+
projects: '**/**.csproj'
31+
arguments: '--configuration Release'
32+
33+
- task: DotNetCoreCLI@2
34+
displayName: Package
35+
inputs:
36+
command: "pack"
37+
projects: '**/RTLS.Common.csproj'
38+
nobuild: true
39+
configuration: "Release"
40+
versioningScheme: "off"
41+
42+
- task: DotNetCoreCLI@2
43+
displayName: Push
44+
inputs:
45+
command: 'push'
46+
packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
47+
nuGetFeedType: 'internal'
48+
publishVstsFeed: '4630136d-be08-48b6-9030-7d0af08008c5/dc097e14-fd70-4bd5-b7f9-92941a543baa'
49+

.github/workflows/deploy.nuget.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Deploy teslacode Common NuGet
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build-and-push:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
15+
- name: Setup .NET (use global.json)
16+
uses: actions/setup-dotnet@v4
17+
with:
18+
source-url: https://api.nuget.org/v3/index.json
19+
env:
20+
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_API_KEY }}
21+
22+
- name: Restore dependencies
23+
run: dotnet restore **/*.csproj --configfile nuget.config --no-cache
24+
25+
- name: Build project
26+
run: dotnet build **/*.csproj --configuration Release --no-restore
27+
28+
- name: Package RTLS.Common
29+
run: dotnet pack **/RTLS.Common.csproj --configuration Release --no-build --output ./artifacts
30+
31+
- name: Push NuGet package
32+
run: dotnet nuget push "./artifacts/*.nupkg" --api-key ${{ secrets.NUGET_AUTH_TOKEN }} --source "https://pkgs.dev.azure.com/<your-org>/_packaging/<your-feed>/nuget/v3/index.json"

Teslacode.Common.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36301.6
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Teslacode.Common", "src\Teslacode.Common\Teslacode.Common.csproj", "{37E04510-78FE-4B84-96AE-AAC8236D3D44}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{37E04510-78FE-4B84-96AE-AAC8236D3D44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{37E04510-78FE-4B84-96AE-AAC8236D3D44}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{37E04510-78FE-4B84-96AE-AAC8236D3D44}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{37E04510-78FE-4B84-96AE-AAC8236D3D44}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {E44577BA-DAC1-404D-8E3B-8BF073A6A8D5}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Microsoft.Extensions.Configuration;
2+
3+
namespace Teslacode.Common;
4+
5+
public static class ApplicationSettings
6+
{
7+
public static IConfiguration GetBaseConfiguration()
8+
{
9+
IConfiguration _configuration = new ConfigurationBuilder()
10+
.SetBasePath(AppContext.BaseDirectory)
11+
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
12+
.AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true)
13+
.AddEnvironmentVariables()
14+
.Build();
15+
16+
return _configuration;
17+
}
18+
19+
public static IConfiguration? GetLocalConfiguration(string path)
20+
{
21+
if (string.IsNullOrEmpty(path))
22+
return null;
23+
24+
if (!File.Exists(path))
25+
return null;
26+
27+
string? setBase = Path.GetDirectoryName(path);
28+
string file = Path.GetFileName(path);
29+
30+
IConfiguration _configuration = new ConfigurationBuilder()
31+
.SetBasePath(setBase)
32+
.AddJsonFile(file, optional: true, reloadOnChange: true)
33+
.Build();
34+
35+
return _configuration;
36+
}
37+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Teslacode.Common.Extensions;
2+
3+
public static class CastingExtensions
4+
{
5+
public static long Tolong(this string value) => long.Parse(value);
6+
7+
public static Guid ToGuid(this string value) => Guid.Parse(value);
8+
9+
public static int ToInt(this string value) => int.Parse(value);
10+
11+
public static Int16 ToSmallInt(this string value) => Int16.Parse(value);
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Teslacode.Common.Extensions;
2+
3+
public static class CheckExtensions
4+
{
5+
public static bool IsNotNull<T>(this T value) where T : class
6+
{
7+
return value != null;
8+
}
9+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.ComponentModel;
2+
3+
namespace Teslacode.Common.Extensions;
4+
5+
public static class EnumExtensions
6+
{
7+
public static T ParseEnum<T>(this string value) => (T)Enum.Parse(typeof(T), value, true);
8+
9+
public static T ParseEnum<T>(this int intValue) => (T)Enum.ToObject(typeof(T), intValue);
10+
11+
public static T? ParseFromDescription<T>(this string description)
12+
{
13+
var fields = typeof(T).GetFields();
14+
var field = fields.SelectMany(sm => sm.GetCustomAttributes(typeof(DescriptionAttribute), false), (sm, a) => new { Field = sm, Att = a })
15+
.Where(a => ((DescriptionAttribute)a.Att).Description == description)
16+
.SingleOrDefault();
17+
18+
return field == null ? default : (T?)field.Field.GetRawConstantValue();
19+
}
20+
21+
public static string GetDescription(this Enum value)
22+
{
23+
var field = value.GetType().GetField(value.ToString());
24+
var attribs = field?.GetCustomAttributes(typeof(DescriptionAttribute), true);
25+
return attribs?.Length > 0 ? ((DescriptionAttribute)attribs[0]).Description : string.Empty;
26+
}
27+
28+
public static string? GetEnumString<T>(this int intValue)
29+
{
30+
var enumType = (T)Enum.ToObject(typeof(T), intValue);
31+
return enumType?.ToString();
32+
}
33+
}

src/Teslacode.Common/Result.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace Teslacode.Common;
2+
3+
public class Result<T>
4+
{
5+
public virtual T Value { get; private set; }
6+
public virtual bool IsSuccess { get; private set; } = true;
7+
public virtual string ErrorMessage { get; private set; } = string.Empty;
8+
9+
public static Result<T> Success() => new();
10+
public static Result<T> Success(T data) => new() { Value = data };
11+
12+
public static Result<T> Fail(string message) => new()
13+
{
14+
IsSuccess = false,
15+
ErrorMessage = message
16+
};
17+
public static Result<T> Fail() => new Result<T>()
18+
{
19+
ErrorMessage = string.Empty,
20+
IsSuccess = false
21+
};
22+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
8+
<PackageId>Teslacode.Common</PackageId>
9+
<Title> teslacode Common Library</Title>
10+
<Authors>Victor A Chavez</Authors>
11+
<Product>Teslacode.Common</Product>
12+
<Version>9.0.0</Version>
13+
<Description>Has some useful extension and utilities that allow for every day development</Description>
14+
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="AutoMapper" Version="15.0.1" />
18+
<PackageReference Include="MediatR" Version="13.0.0" />
19+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.9" />
20+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.9" />
21+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.9" />
22+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.9" />
23+
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.9" />
24+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.9" />
25+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.9" />
26+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.9" />
27+
</ItemGroup>
28+
29+
</Project>

0 commit comments

Comments
 (0)