Skip to content

Commit

Permalink
Merge pull request #10 from dutchgrit/develop
Browse files Browse the repository at this point in the history
merge: develop into main
  • Loading branch information
Rokimajo authored Nov 13, 2024
2 parents c9a9c67 + 8058b85 commit 6ca04f0
Show file tree
Hide file tree
Showing 71 changed files with 4,202 additions and 9 deletions.
23 changes: 15 additions & 8 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ on:
- develop

env:
VALUE: 67
VALUE: ${{ github.run_number }}
NET_VERSION: 8.0.x
CONFIGURATION: Release
PROJECT: ./src/AfasClient.csproj
PROJECT_TEST: ./test/AfasClient.Test.csproj
PROJECT_NAME: DutchGrit.AfasClient

jobs:
Expand All @@ -37,19 +38,19 @@ jobs:
shell: pwsh
run: |
$currentPatch = 1 + [int]${{ env.VALUE }}
echo "currentPatch=$currentPatch" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
if ($env:GITHUB_REF_NAME -eq "main") {
$nugetVersion = "2.1.0.$currentPatch"
echo "currentPatch=$currentPatch" >> $ENV:GITHUB_OUTPUT
if ("${{ github.ref_name }}" -eq "main") {
$nugetVersion = "2.2.0.$currentPatch"
} else {
$nugetVersion = "2.1.0.$currentPatch-beta"
$nugetVersion = "2.2.0.$currentPatch-beta"
}
echo "nugetVersion=$nugetVersion" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
echo "nugetVersion=$nugetVersion" >> $ENV:GITHUB_OUTPUT
- name: Replace project version
shell: pwsh
run: |
(Get-Content "${{ env.PROJECT }}") -replace 'Version>1.0.0.0<', "Version>${{ steps.vars.outputs.nugetVersion }}<" | Set-Content "${{ env.PROJECT }}"
(Get-Content ".\src\Properties\AssemblyInfo.cs") -replace '1.0.0.0', "2.1.0.${{ steps.vars.outputs.currentPatch }}" | Set-Content ".\src\Properties\AssemblyInfo.cs"
(Get-Content ".\src\Properties\AssemblyInfo.cs") -replace '1.0.0.0', "2.2.0.${{ steps.vars.outputs.currentPatch }}" | Set-Content ".\src\Properties\AssemblyInfo.cs"
- name: Setup .NET
uses: actions/setup-dotnet@v3
Expand All @@ -58,7 +59,11 @@ jobs:
include-prerelease: true

- name: Dotnet Test
run: dotnet test ${{ env.PROJECT }} --configuration ${{ env.CONFIGURATION }}
env:
AfasToken: ${{ secrets.TEST_AFAS_TOKEN }}
AfasMemberId: ${{ secrets.TEST_AFAS_MEMBERID }}
AfasEnvironment: ${{ secrets.TEST_AFAS_ENVIRONMENT }}
run: dotnet test ${{ env.PROJECT_TEST }} --configuration ${{ env.CONFIGURATION }}

- name: Cache SonarQube packages
uses: actions/cache@v1
Expand Down Expand Up @@ -108,6 +113,8 @@ jobs:

- name: Download Artifact
uses: actions/download-artifact@v4.1.8
with:
name: ${{ env.PROJECT_NAME }}

- name: Push to NuGet
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,6 @@ NuGetBackup
error-*.xml

PublishOutput/

# afascli
afas-cli.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ See the [tracing](Documentation/Tracing.MD) option for monitoring and debugging
Feel free to report any bugs or missing features.

### Got feedback or ideas?
[File an issue](https://github.com/dutchgrit/afasclient/issues) and tell us what you want to change or add, or what doesn't work for you. All issues are welcome!
[File an issue](https://github.com/dutchgrit/afasclient/issues) and tell us what you want to change, add, or what doesn't work for you if that's the case. All issues are welcome, from improvements to bugs!
### Want to contribute?
If you want to contribute to the AfasClient project, a great place to start would be the project's 'Issues' tab! You can also contribute by creating bug reports, try playing around with the client and see if you find any problems. If so, make an issue!
31 changes: 31 additions & 0 deletions src/AfasClient.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AfasClient", "src\AfasClient.csproj", "{EADE59A9-F190-4CE8-96F9-FDFCA6ED0C89}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AfasClient.Test", "test\AfasClient.Test.csproj", "{7474F40B-DE4A-43AB-9151-205323440276}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EADE59A9-F190-4CE8-96F9-FDFCA6ED0C89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EADE59A9-F190-4CE8-96F9-FDFCA6ED0C89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EADE59A9-F190-4CE8-96F9-FDFCA6ED0C89}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EADE59A9-F190-4CE8-96F9-FDFCA6ED0C89}.Release|Any CPU.Build.0 = Release|Any CPU
{7474F40B-DE4A-43AB-9151-205323440276}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7474F40B-DE4A-43AB-9151-205323440276}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7474F40B-DE4A-43AB-9151-205323440276}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7474F40B-DE4A-43AB-9151-205323440276}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BCA53C4B-1269-40BF-AB07-744328BE6610}
EndGlobalSection
EndGlobal
4 changes: 4 additions & 0 deletions src/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# LICENSE
(c) DutchGrit 2022, a Lucrasoft Digital B.V. brand. All rights reservered.

Please contact us at DutchGrit.nl for licensing options.
4 changes: 4 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# Afas Library

The documentation is maintained on a public github repository [here](https://github.com/dutchgrit/afasclient)
77 changes: 77 additions & 0 deletions src/src/AfasBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace DutchGrit.Afas
{
public class AfasBase : GeneralBase
{

protected HttpClient httpClient = GeneralBase.httpClientInternal;

protected int MemberNumber { get; set; }

protected Environments Environment { get; set; }

protected string Token64 { get; set; }

protected override string GetBaseUrl
{
get
{
return $"https://{MemberNumber}.rest{Environment.AsUrlAddition()}.afas.online/profitrestservices/";
}
}

protected override async Task<HttpResponseMessage> GetAuthHttp(string urlPath)
{
using (var httpRequestMessage = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri(this.GetBaseUrl + urlPath),
Headers = {
{ "Authorization", this.Token64 }
}
})
{
return await httpClient.SendAsync(httpRequestMessage);
}
}


protected override async Task<HttpResponseMessage> SendAuthHttp(string urlPath, string content, HttpMethod method)
{
using (var httpRequestMessage = new HttpRequestMessage
{
Method = method,
RequestUri = new Uri(this.GetBaseUrl + urlPath),
Headers = {
{ "Authorization", this.Token64 }
},
Content = new StringContent(content)
})
{
return await httpClient.SendAsync(httpRequestMessage);
}
}

protected override async Task<HttpResponseMessage> OtpPost(string urlPath, string content)
{
using (var httpRequestMessage = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri(this.GetBaseUrl + urlPath),
Content = new StringContent(content)
})
{
return await httpClient.SendAsync(httpRequestMessage);
}
}


}
}
85 changes: 85 additions & 0 deletions src/src/AfasClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using Newtonsoft.Json;
using System;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace DutchGrit.Afas
{

public class AfasClient : AfasBase, IAfasClient
{

public AfasClient(int MemberNumber, string Token, Environments Env = Environments.Production, HttpClient customHttpClient=null)
{
this.MemberNumber = MemberNumber;
this.Environment = Env;
//Convert the Token string into Base64.
var authToken = Encoding.ASCII.GetBytes(Token);
this.Token64 = "AfasToken " + Convert.ToBase64String(authToken);


if (customHttpClient != null)
{
this.httpClient = customHttpClient;
}
}

public Task<SessionInfo> GetSessionInfoAsync()
{
return GetApiAsync<SessionInfo>("metainfo");
}

public Task<UpdateConMetaInfo> GetMetaDataUpdConAsync(string connector)
{
return GetApiAsync<UpdateConMetaInfo>($"metainfo/update/{connector}");
}

public Task<GetConMetaInfo> GetMetaDataGetConAsync(string connector)
{
return GetApiAsync<GetConMetaInfo>($"metainfo/get/{connector}");
}

public async Task<string> GetVersionAsync()
{
//Only works when AppConnectorVersion is included!
var z = await this.GetApiAsync<AfasVersion>("profitversion");
return z.Version;
}


public async Task<FileInfo> GetFileBySubjectAsync(int SubjectID, string FileID)
{
using (var res = await this.GetAuthHttp($"subjectconnector/{SubjectID}/{FileID}"))
{
int code = (int)res.StatusCode;
if (code >= 200 && code <= 299)
{
var txt = await res.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<FileInfo>(txt);
}
if (res.StatusCode == HttpStatusCode.NotFound)
{
return null;
}
//bij een andere reden, gewoon laten klappen!
res.EnsureSuccessStatusCode();
return null;
}
}

public AfasQuery<T> Query<T>() where T : IGetEntity
{
return new AfasQuery<T>(this);
}


public string GetVersion() => AsyncHelpers.RunSync<string>(() => GetVersionAsync());

public SessionInfo GetSessionInfo() => AsyncHelpers.RunSync<SessionInfo>(() => GetSessionInfoAsync());

public FileInfo GetFileBySubject(int SubjectID, string FileID) => AsyncHelpers.RunSync<FileInfo>( () => GetFileBySubjectAsync(SubjectID, FileID ));

}
}
41 changes: 41 additions & 0 deletions src/src/AfasClient.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<UserSecretsId>2508f9d2-d815-49df-a709-f739ec918282</UserSecretsId>
<RootNamespace>DutchGrit.Afas</RootNamespace>
<AssemblyName>DutchGrit.AfasClient</AssemblyName>
<Company>DutchGrit - Lucrasoft Digital BV</Company>
<Copyright>Lucrasoft Digital BV</Copyright>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Authors>DutchGrit</Authors>
<Description>.NET Standard 2.0 Library for interacting with the AFAS (Profit) RestAPI</Description>
<PackageLicenseExpression></PackageLicenseExpression>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<Version>1.0.0.0</Version>
<PackageProjectUrl></PackageProjectUrl>
<RepositoryUrl>https://github.com/dutchgrit/afasclient</RepositoryUrl>
<SignAssembly>false</SignAssembly>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
</ItemGroup>

<ItemGroup>
<None Include="../LICENSE.md">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<Folder Include="Images\" />
</ItemGroup>

</Project>
Loading

0 comments on commit 6ca04f0

Please sign in to comment.