A codeunit to upload files to different containers, implemented with interfaces and monitored with telemetry
- The requirement is to replace the reference of “File Management” codeunit with a new “Azure File Management” for the SaaS (Cloud) version of Business Central.
- I want to implement a base “app” that manages file basic operation on different cloud platforms: upload, download, create folders, copy and move files and folders.
- I want the app to be reusable by all other app depending on it.
- I want to monitor the activity with telemetry and application insights.
THE WONDERFUL WORLD OF INTERFACES AND TELEMETRY
This project allows me to use in the real world two of the new powerful and wonderful features of Business Central: interfaces and telemetry. Interfaces are available with a minimum of runtime 5 (you have to kiss goodbye older versions of BC).
AZURE BLOBS VS AZURE FILES
One of the requirement was to work with Azure Files, not just with Azure Blobs. The web is full of samples of Azure Blobs integration but it lacks Azure Files implementation.
As you should already know, Azure Files and Azure Blobs are two different containers and you deal with them with a different set of APIs.
First of all I implemented the interface, in my GitHub sample I only give you the code of Download() 🙂
Then I implemented Download codeunits for Azure Files and Azure Blobs.
The “ALV AzBlob Service API” contains Azure Blob implementation, to deal with blobs is really easy and with a few lines of code the job is done. This is a dummy copy/paste from Demiliani sample integrated with telemetry monitoring.
The Azure File, implemented in “ALV AzFile Service API”, drove me mad because I didn’t find any ready-to-use solution on the internet and I had to implement all by myself.
The Azure Files management involves a tricky feature to calculate a Base64Hash SharedKey by using “Cryptographic Management” codeunit. The azure file API needs an authentication procedure which is not so easy to implement from scratch in AL language. By the way, here it is.
The “ALV Application Insights Mgt.” and “ALV Application Insights SDK” allow to deal with azure application insight telemetry. The Management codeunit implements the TraceInformation(), TraceError() and all the other function to write logs data.
I added just a function to manage telemetry where I manage the telemetry duration.
APPLICATION INSIGHT AND TELEMETRY FOR BUSINESS CENTRAL
AZURE FILE API REFERERENCE
In next article I will cover how to access telemetry and how to implement Alibaba Cloud Container Download() function.
30th of May, 2020