Perform the following steps:
- Create a new activity function named ReadExcel_AT that connects to the blob using the StorageManager class that we developed in the previous section, and then reads the data using the EPPLusExcelManager class. Copy the following code to the ExcelImport_Orchestrator class:
[FunctionName("ReadExcel_AT")]
public static async Task<List<Employee>> ReadExcel_AT(
[ActivityTrigger] string name,
ILogger log)
{
log.LogInformation("Orchestration started");
StorageManager storageManager = new StorageManager();
Stream stream = null; ;
log.LogInformation("Reading the Blob Started");
stream = await storageManager.ReadBlob(name);
log.LogInformation("Reading the Blob has Completed");
EPPLusExcelManager ePPLusExcelManager = new EPPLusExcelManager();
log.LogInformation("Reading the Excel Data Started");
List<Employee> employees = ePPLusExcelManager.ReadExcelData(stream);
log.LogInformation("Reading the Blob has Completed");
return employees;
}
- Add System.IO to the namespace list if it's not there already and build the application.
- Let's now invoke this activity function from the Orchestrator. Go to the ExcelImport_Orchestrator Orchestrator function and replace it with the following code. The Orchestration function invokes the activity function by passing the name of the Excel that is uploaded so that the activity function reads the data from the Excel file:
[FunctionName("ExcelImport_Orchestrator")]
public static async Task<List<string>> RunOrchestrator(
[OrchestrationTrigger] DurableOrchestrationContext context)
{
var outputs = new List<string>();
string ExcelFileName = context.GetInput<string>();
List<Employee> employees = await context.CallActivityAsync<List<Employee>>("ReadExcel_AT", ExcelFileName);
return outputs;
}
- Let's run the application and then upload an Excel file. If everything is configured properly, then you should see something shown as follows in the ReadExcel_AT activity trigger function, where you can see the number of employee records being read from the Excel sheet: