public void Execute(string serviceDecompositionFilePath, string filename, int serviceDeskId) { if (serviceDecompositionFilePath == null) { throw new ArgumentNullException(nameof(serviceDecompositionFilePath)); } if (filename == null) { throw new ArgumentNullException(nameof(filename)); } if (!File.Exists(serviceDecompositionFilePath)) { throw new FileNotFoundException(serviceDecompositionFilePath); } // Read the contents of Service Decomposition spreadsheet (This will have been uploaded via the Web UI) var importResults = _serviceDecompositionTemplateImporter.ImportSpreadsheet(serviceDecompositionFilePath); if (importResults.ValidationResults.Count > 0) { throw new DataImportException( $"Error reading Service Decomposition Template spreadsheet ({filename}) - ", importResults.ValidationResults); } if (importResults.Results.Count == 0) { throw new DataImportException( $"Error reading Service Decomposition Template spreadsheet ({filename}) - Spreadsheet does not contain any valid data."); } using (var dbConnection = _unitOfWork.CreateConnection()) { try { // Open the connection and begin a transaction dbConnection.Open(); _repositoryTransaction = _unitOfWork.BeginTransaction(); _serviceDeskService.Clear(serviceDeskId); _transformTemplateToDesign.Transform(serviceDeskId, importResults.AsTemplateRows()); Save(); } catch (Exception) { // If we have a transaction then roll it back Rollback(); // Throw the exception throw; } } }
public void Execute(string serviceDecompositionFilePath, string filename, int templateType) { // Set the license for Aspose var license = new License(); license.SetLicense("Aspose.Total.lic"); if (serviceDecompositionFilePath == null) { throw new ArgumentNullException(nameof(serviceDecompositionFilePath)); } if (filename == null) { throw new ArgumentNullException(nameof(filename)); } if (!Enum.IsDefined(typeof(TemplateType), templateType)) { throw new ArgumentException(nameof(templateType)); } if (!FileExists(serviceDecompositionFilePath)) { throw new FileNotFoundException(serviceDecompositionFilePath); } if (templateType == TemplateTypeNames.SORT.GetEnumIntFromText <TemplateType>() && _templateService.All().Any(x => x.TemplateType == TemplateTypeNames.SORT.GetEnumIntFromText <TemplateType>())) { throw new DataImportException("A SORT Service Decomposition Template already exists, please delete before importing a new SORT spreadsheet."); } // Read the contents of Service Decomposition spreadsheet (This will have been uploaded via the Web UI) var importResults = _serviceDecompositionTemplateImporter.ImportSpreadsheet(serviceDecompositionFilePath); if (importResults.ValidationResults.Count > 0) { throw new DataImportException( $"Error reading Service Decomposition Template spreadsheet ({filename}) - ", importResults.ValidationResults); } if (importResults.Results.Count == 0) { throw new DataImportException( $"Error reading Service Decomposition Template spreadsheet ({filename}) - Spreadsheet does not contain any valid data."); } var template = CreateTemplate(serviceDecompositionFilePath, filename, templateType); _transformSpreadsheetToTemplate.Transform(template, importResults.AsTemplateRows()); _templateService.Create(template); }