Skip to content

Commit

Permalink
Finished Web Api impl of AASX File Server
Browse files Browse the repository at this point in the history
  • Loading branch information
JMayrbaeurl committed Dec 21, 2021
1 parent 25f6ce0 commit b215e32
Show file tree
Hide file tree
Showing 24 changed files with 4,500 additions and 129 deletions.
4 changes: 2 additions & 2 deletions src/aas-aasxfile-service-tests/AASXFileServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void TestGetAASXPackageForSimple()
try
{
AASAASXFile service = CreateAASAASXFileService();
byte[] packageContents = service.GetAASXByPackageId("Simple").GetAwaiter().GetResult();
byte[] packageContents = service.GetAASXByPackageId("Simple").GetAwaiter().GetResult().Contents;
Assert.IsNotNull(packageContents);
Assert.IsTrue(packageContents.Length > 0);
Assert.AreEqual<string>(teststring, Encoding.UTF8.GetString(packageContents));
Expand All @@ -127,7 +127,7 @@ public void TestGetAASXPackageForSimple()
public void TestGetAASXPackageForStdSampleFesto()
{
AASAASXFile service = CreateAASAASXFileService();
byte[] packageContents = service.GetAASXByPackageId("01_Festo").GetAwaiter().GetResult();
byte[] packageContents = service.GetAASXByPackageId("01_Festo").GetAwaiter().GetResult().Contents;
Assert.IsNotNull(packageContents);
Assert.IsTrue(packageContents.Length > 0);
}
Expand Down
23 changes: 13 additions & 10 deletions src/aas-aasxfile-service/AzureBlobImpl/AzureBlobAASXFileService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AAS.API.Models;
using AAS.API.Models.Interfaces;
using Azure;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
Expand Down Expand Up @@ -133,7 +134,7 @@ public async Task DeleteAASXByPackageId(string packageId)
}
}

public async Task<byte[]> GetAASXByPackageId(string packageId)
public async Task<PackageFile> GetAASXByPackageId(string packageId)
{
if (containerClient == null)
throw new AASXFileServiceException("Invalid setup. No Blob container client configured");
Expand All @@ -143,7 +144,7 @@ public async Task<byte[]> GetAASXByPackageId(string packageId)

_logger.LogDebug($"Retrieving AASX package with id '{packageId}'");

byte[] result = null;
PackageFile result = null;

try
{
Expand All @@ -154,7 +155,8 @@ public async Task<byte[]> GetAASXByPackageId(string packageId)
if (await blobClient.ExistsAsync())
{
BlobDownloadResult downloadResult = await blobClient.DownloadContentAsync();
result = downloadResult.Content.ToArray();
string filename = (await blobClient.GetPropertiesAsync()).Value.Metadata[PACKAGE_FILENAME_KEY];
result = new PackageFile() { Filename = filename, Contents = downloadResult.Content.ToArray() };
}
}
catch (RequestFailedException exc)
Expand All @@ -169,21 +171,22 @@ public async Task<byte[]> GetAASXByPackageId(string packageId)

public async Task<List<PackageDescription>> GetAllAASXPackageIds(string aasId)
{
if (aasId == null || aasId.Length == 0)
throw new AASXFileServiceException("Parameter 'aasId' must not be empty");

List<PackageDescription> result = new List<PackageDescription>();
BlobContainerClient blobContainer = await GetContainerClient();

await foreach (BlobItem item in blobContainer.GetBlobsAsync(BlobTraits.Metadata, BlobStates.None))
{
if (item.Metadata.ContainsKey(PACKAGE_METADATA_KEY))
if (item.Metadata.ContainsKey(PACKAGE_METADATA_KEY) && item.Name.Contains('/'))
{
List<string> aasIds = item.Metadata.Where(key => key.Key.StartsWith("aasId_")).Select(key => key.Value).ToList();
if (aasIds != null && aasIds.Contains(aasId) && item.Name.Contains('/'))

if (aasIds != null )
{
string packId = WebUtility.UrlDecode(item.Name.Split('/')[0]);
result.Add(new PackageDescription() { PackageId = packId, AasIds = aasIds });
if (aasId == null || aasIds.Contains(aasId))
{
string packId = WebUtility.UrlDecode(item.Name.Split('/')[0]);
result.Add(new PackageDescription() { PackageId = packId, AasIds = aasIds });
}
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion src/aas-api-models/Interfaces/AASXFileServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface AASXFileServer
/// Returns a specific AASX package from the server
/// </summary>
/// <param name="packageId">The package Id (BASE64-URL-encoded)</param>
public Task<byte[]> GetAASXByPackageId(string packageId);
public Task<PackageFile> GetAASXByPackageId(string packageId);

/// <summary>
/// Returns a list of available AASX packages at the server
Expand All @@ -35,4 +35,22 @@ public interface AASXFileServer
/// </summary>
public Task<PackageDescription> UpdateAASXPackage(string packageId, List<string> aasIds, byte[] file, string fileName);
}

public class PackageFile
{
private string filename;

public string Filename
{
get { return filename; }
set { filename = value; }
}
private byte[] contents;

public byte[] Contents
{
get { return contents; }
set { contents = value; }
}
}
}
208 changes: 208 additions & 0 deletions src/aas-api-webapp-aasxfile/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
PID

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/

# Visual Studio 2015 cache/options directory
.vs/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

# DNX
project.lock.json
artifacts/

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding add-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
_NCrunch_*
.*crunch*.local.xml

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config

# Windows Azure Build Output
csx/
*.build.csdef

# Windows Store app package directory
AppPackages/

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

# Others
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
bower_components/
orleans.codegen.cs

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/

# Node.js Tools for Visual Studio
.ntvs_analysis.dat

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt
37 changes: 26 additions & 11 deletions src/aas-api-webapp-aasxfile/AAS WebApp AASX File Server.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>AAS_WebApp_AASX_File_Server</RootNamespace>
<UserSecretsId>8307df6a-cd8c-45e8-9ab0-2cbc62a85639</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>AAS_WebApp_AASX_File_Server</RootNamespace>
<UserSecretsId>8307df6a-cd8c-45e8-9ab0-2cbc62a85639</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.11.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="5.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="5.5.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.11.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\aas-aasxfile-service\AAS AASX File Service.csproj" />
</ItemGroup>


</Project>
Loading

0 comments on commit b215e32

Please sign in to comment.