FileExtension–PostMortem- part 7
It was interesting to wrote this project. At the final, it features an web site (https://fileextension.azurewebsites.net/ ) and a NuGet package ( https://www.nuget.org/packages/FileExtension/ ). Also , I have learned how to start Windows Terminal to start Angular / .NET Core / Tests
wt new-tab -p “Windows PowerShell” -d . cmd /k “cd src && dotnet build && cd RecognizeFileExtWebAPI && dotnet watch run” ;split-pane -p “Windows PowerShell” -d . cmd /k “cd src && dotnet build && cd TestFileExtensions && dotnet watch test” ; split-pane -p “Windows PowerShell” -d . cmd /k “cd src && cd FileExtensionAng && npm i && ng serve -o”
and refreshed my GitHub actions knowledge ( I am very fond of CI – and , if I can, CD )
Also, I have now a better understanding of a csproj file in relation with nuget :
<ItemGroup>
<None Remove=”plugins\FileExtension.targets” />
<Content Include=”plugins\FileExtension.targets”>
<PackagePath>build\net5.0\</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup><ItemGroup>
<Content Include=”plugins\**\*.dll”>
<PackagePath>build\net5.0\plugins\</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
It was refreshing to know that, even I like the Skinny Controllers concept, however the WebAPI is not so light .
Hopefully someone will find the package useful – or at least the site https://fileextension.azurewebsites.net/
FileExtension–part 6 – CI/CD
So now how to make visible all those coding ?
For tests –CodeCov, https://app.codecov.io/gh/ignatandrei/FileExtension hosts for free to see the coverage
For documentation – ReadTheDocs, https://fileextension.readthedocs.io/en/latest/ hosts for free.
For packaging – NuGEt https://www.nuget.org/packages/FileExtension/
For more detailed analysis Sonar https://sonarcloud.io/summary/overall?id=ignatandrei_FileExtension can show code smells and bugs and more
GitHub actions https://github.com/ignatandrei/FileExtension/actions allows me to run all those automatically and gather results
For showing a website – Azure – https://fileextension.azurewebsites.net/ can show the usage.
I was thinking that it is enough for the people to understand the application
[ADCES]Devops By Docker & Life after Java 8
Details
Presentation 1 : Practical DevOps: One-Click Deployment using Docker
Presenter: Andrei Micuda,https://github.com/andrei-micuda/
Description:
Every developer wants to deploy and maintain the applications he develops with ease. Although this seems like a daunting task at first, you can achieve a one-click deployment pipeline by only using a few Docker containers. Join us if you want to find how to use Docker to automate your development workflow and build a fully customizable and easy-to-understand CI/CD pipeline from scratch.
Presentation 2: Life after Java 8
Presenter : Cosmin Popescu, https://www.chestiiautomate.ro/
FileExtension–Tests–part 5
The tests are the easy part. I have put some files on a folder( https://github.com/ignatandrei/FileExtension/tree/master/src/TestFileExtensions/TestFiles ) and test if the extension matches the recognizer.
As NuGet packages I used
FluentAssertions
xunit
LightBDD.XUnit2
FluentAssertion allows me to write more readable tests , like
AllExtensions.Should().HaveCountGreaterThanOrEqualTo(number);
LightBDD allows me to write tests in a more “business “ way :
await Runner
.AddSteps(Given_The_Recognizer)
.AddAsyncSteps(_ => When_Read_The_File(fileName))
.AddSteps(
_ => Then_Should_Recognize_File(fileName),
_ => Then_The_Extension_Matches(fileName)
)
.RunAsync();
You can see the result at https://fileextension.readthedocs.io/en/latest/BDD/LightBDDReport/ = go down to see the Given / When /
Also, for enumerating files from the folder to test, I use ClassData
[ClassData(typeof(DirectoryTestData))]
public async void TestMultipleFiles(string nameFile)
Friday Links 449
=ػ�=�h�
=ػ�
FileExtension – GUI–part 4
Now I must do something for the people that just want to use the software. The most usual , for me, it is a .NET Core WebAPI site ( with swagger ) and an Angular frontend.
You can find the sources at https://github.com/ignatandrei/FileExtension/tree/master/src . Some thoughts:
For .NET Core ( see https://github.com/ignatandrei/FileExtension/tree/master/src/RecognizeFileExtWebAPI ) I use the following NuGET packages ( other than usual .NET Core)
Microsoft.AspNetCore.Mvc.Versioning
Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer
Swashbuckle.AspNetCore
Hellang.Middleware.ProblemDetails
The final result can be seen at https://fileextension.azurewebsites.net/swagger
For Angular( https://github.com/ignatandrei/FileExtension/tree/master/src/FileExtensionAng) I use the following packages( other than usual Angular)
@angular/material
angular-shepherd
The final result can be seen at https://fileextension.azurewebsites.net/
FileExtension–plugins–part 3
What I have more in mind is that the people can add easy their code for extensions.
That means:
- Have an easy class to add the magic number in the header for an extension
- Have other people add their own implementations, not just the header
- Have an easy way to add the project with their code
First item it is easy – just create a class RecognizeFirstBytes and pass into constructor the first bytes
As an example , see the sln implementation
public class RecognizeSln : RecognizeFirstBytes { public RecognizeSln() : base("EFBBBF0D0A4D6963726F736F66742056697375616C2053747564696F20536F6C7574696F6E2046696C65") { Extension = new string[1] { "sln" }; } }
The second item can be implemented with an interface IRecognize
public interface IRecognize: IEquatable<IRecognize> { Result InfoNeeded(byte[] b=null); string[] Extension { get; set; } }
The third item can be made by making a third project that either references all other projects, either loading others as plugins . Because of the experience, I choose the most interesting one – plugins. I need first https://github.com/natemcmaster/DotNetCorePlugins . Second I need the plugins to be copied – I use a Target
<Target Name="PreBuild" BeforeTargets="PreBuildEvent"> <Exec Command="xcopy "$(ProjectDir)../plugins/*.dll" "$(ProjectDir)plugins" /E /F /I /Y /R" /> </Target>
And last I need this plugin loader , when packed as nuget at https://www.nuget.org/packages/FileExtension/ , to have also the plugins – for this I use the csproj
<ItemGroup> <Content Include="plugins\**\*.dll"> <PackagePath>build\net5.0\plugins\</PackagePath> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> </ItemGroup>
FileExtension– export data from CSV–part 2
First, is how to export data from table (https://en.wikipedia.org/wiki/List_of_file_signatures) into classes . First, the table must be transformed into a more programmatic recognizable way – like a CSV – see https://github.com/ignatandrei/FileExtension/blob/master/src/RSCG_GCK/offset0.txt
Then a solution is to have into the dll ( as embedded resource or as a file) . The second solution, more complicated , is to use Roslyn Source Code Generators to generate the classes for each element of the CSV .
I’d liked more the second solution – the sources are at https://github.com/ignatandrei/FileExtension/tree/master/src/RSCG_GCK
What it generates is like this
namespace RecognizeCustomSigs_GCK { class RecognizeFromGCKLine0_JP2: RecognizeFromLineCustomsigs{ public RecognizeFromGCKLine0_JP2(): base("JPEG2000 image files,00 00 00 0C 6A 50 20 20,JP2") { } } }
FileExtension–idea- part 1
Every now and then we accept file uploads ( to a site ) – or we have files in outlook that we want to open – but we do not know if the extension matches the content of the file.
There are numerous way to do it , however , I have been attracted by Magic Numbers – a header into the file that says what is the kind of the file.
For example, a .sln file has always those characters inside:
Microsoft Visual Studio Solution File, Format Version
You can then recognize if it is a real sln if it contains those characters.
Reading more on the internet, I have found
https://www.garykessler.net/library/file_sigs.html
https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files
https://en.wikipedia.org/wiki/List_of_file_signatures
Now, there are multiple programs and sites to do this magic number verifier – however, in order to practice programming, is always a good idea to start somewhere – so let’s see where it goes.
You can find the sources at https://github.com/ignatandrei/fileExtension/
The application is live at https://fileextension.azurewebsites.net/static/v1
You can find a NuGet package at https://www.nuget.org/packages/FileExtension/