private void DownloadLogieAppsToModel(ErrorReportArgs errorReportArgs, LogicAppManager logicAppManager, Model model) { //Get all logic apps into model Console.WriteLine("Downloading logic app list"); foreach (var resourceGroup in errorReportArgs.ResourceGroups) { var resourceGroupModel = new ResourceGroupModel(); resourceGroupModel.Name = resourceGroup; model.ResourceGroups.Add(resourceGroupModel); var logicApps = logicAppManager.GetLogicAppList(resourceGroup); foreach (var logicApp in logicApps) { var logicAppModel = new LogicAppModel(); logicAppModel.Id = logicApp.Id; logicAppModel.LogicAppManagementObject = logicApp; logicAppModel.Name = logicApp.Name; logicAppModel.ResourceGroupName = resourceGroupModel.Name; resourceGroupModel.LogicApps.Add(logicAppModel); } Console.WriteLine($"Completed downloading logic app list for resource group: {resourceGroup}"); } }
private void DownloadLogicAppRunToModel(DateTime startDate, DateTime endDate, LogicAppManager logicAppManager, ResourceGroupModel resourceGroupModel, LogicAppModel logicAppModel) { var runList = logicAppManager.GetLogicAppRuns(resourceGroupModel.Name, logicAppModel.LogicAppManagementObject, startDate, endDate); if (runList.Count > 0) { Console.WriteLine($"\t\tLogic app has failed runs. Checking for actions"); } var options = new ParallelOptions() { MaxDegreeOfParallelism = 3 }; Parallel.ForEach(runList, options, run => { var runModel = new LogicAppRunModel(); runModel.Id = run.Name; runModel.IsError = false; runModel.Result = run.Status; runModel.WorkflowRun = run; if (run.Status.ToLower() == "failed") { Console.WriteLine($"\tLogic App Failed: {run.Name} : {run.StartTime.Value.ToString()}"); runModel.IsError = true; logicAppModel.FailedRuns.Add(runModel); logicAppModel.NoFailedRuns++; var actionList = logicAppManager.GetLogicAppRunActionList(resourceGroupModel.Name, logicAppModel.LogicAppManagementObject, run); Console.WriteLine($"\t\tChecking for actions {run.Name}"); foreach (var action in actionList) { if (action.Status.ToLower() == "failed") { var actionModel = new FailedRunActionsModel(); actionModel.Name = action.Name; var errorMessageJson = JsonConvert.SerializeObject(action.Error); try { var errorDictionary = JsonConvert.DeserializeObject <Dictionary <string, string> >(errorMessageJson); if (errorDictionary != null) { if (errorDictionary.ContainsKey("message")) { actionModel.Error = errorDictionary["message"]; } } } catch (Exception) { //Swallow error incase error object not as expected } Console.WriteLine($"\t\tAction Failed: {action.Name}"); runModel.FailedActions.Add(actionModel); } } } else { //Ignore for now } }); }