public void GetRowAndColumIndexTest() { DmnInfo dmnInfo = new DmnInfo() { DmnId = "id_01", DmnName = "Dmn_Test", FileName = "Dmn_test.dmn" }; DmnConverter.AddVariablesToDictionary(ref dmnInfo, "col_01", "Column 01", "String", "input"); DmnConverter.AddVariablesToDictionary(ref dmnInfo, "col_02", "Column 02", "String", "input"); DmnConverter.AddVariablesToDictionary(ref dmnInfo, "col_03", "Column 03", "String", "input"); dmnInfo.InputVariablesInfo.Length.Should().Be(3); }
public void Test1() { var file = "dmnTest1.dmn"; string ifcDataFile = Path.Combine(Directory.GetCurrentDirectory() + @"..\..\..\..\Data\", file); tDefinitions dmn; using (Stream dmnStream = File.Open(ifcDataFile, FileMode.Open)) { dmn = DmnConverter.DeserializeStreamDmnFile(dmnStream); } var Items = dmn.Items; var decision = Items.Where(t => t.GetType() == typeof(tDecision)); var excelPkg = new ExcelPackage(); foreach (var tdecision in decision) { tDecisionTable decisionTable = null; try { var dt = ((tDecision)tdecision).Item; decisionTable = (tDecisionTable)Convert.ChangeType(dt, typeof(tDecisionTable)); ExcelWorksheet wsSheet = excelPkg.Workbook.Worksheets.Add(tdecision.id); //Add Table Title ExcelConverter.AddTableTitle(tdecision.name, wsSheet, decisionTable.hitPolicy.ToString(), tdecision.id); // Add "input" and "output" headet to Excel table ExcelConverter.AddTableInputOutputTitle(wsSheet, decisionTable); //Add DMN Table to excel Sheet ExcelConverter.CreateExcelTableFromDecisionTable(decisionTable, wsSheet, tdecision.id); } catch { // } } var filename = Path.GetFileNameWithoutExtension(ifcDataFile); var path = string.Concat(@"c:\temp\"); Directory.CreateDirectory(path); var filePath = Path.Combine(path, string.Concat(filename, "new1", ".xlsx")); excelPkg?.SaveAs(new FileInfo(filePath)); File.Exists(filePath).Should().BeTrue(); }
private string GetValueParse(string cellValue) { var regex = DmnConverter.GetComparisonNumber(cellValue); var regex2 = DmnConverter.GetRangeNumber(cellValue); if (int.TryParse(cellValue, out var intType)) { return(intType.ToString()); } if (long.TryParse(cellValue, out var longType)) { return(longType.ToString()); } if (double.TryParse(cellValue, out var doubleType)) { return(doubleType.ToString()); } if (bool.TryParse(cellValue, out var booleanType)) { return(booleanType.ToString().ToLower()); } var values = cellValue.Split(";"); string newCellValue = cellValue; if (values != null && values.Any() && regex == null && regex2 == null && !string.IsNullOrEmpty(newCellValue)) { newCellValue = string.Empty; if (cellValue.StartsWith("\"") && cellValue.EndsWith("\"")) { newCellValue = cellValue; } else { for (int i = 0; i < values.Count(); i++) { newCellValue = i == 0 ? string.Concat("\"", values[i], "\"") : string.Concat(newCellValue, ",", "\"", values[i], "\""); } } } return(newCellValue); }
public void Test1() { var file = "dmnTest1.dmn"; var file2 = "dmnTest2.dmn"; var file3 = "BpmnTest01.bpmn"; var dmns = new List <tDefinitions>(); var filePath1 = Path.Combine(Directory.GetCurrentDirectory() + @"..\..\..\..\Data\", file); var filePath2 = Path.Combine(Directory.GetCurrentDirectory() + @"..\..\..\..\Data\", file2); var bpmn = Path.Combine(Directory.GetCurrentDirectory() + @"..\..\..\..\Data\", file3); XDocument bpmnXml = XDocument.Load(bpmn); using (Stream dmnStream = File.Open(filePath1, FileMode.Open)) { dmns.Add(DmnConverter.DeserializeStreamDmnFile(dmnStream)); } using (Stream dmnStream = File.Open(filePath2, FileMode.Open)) { dmns.Add(DmnConverter.DeserializeStreamDmnFile(dmnStream)); } var dmnDataDictionaryModels = new List <DmnInfo>(); var excelPkg = new ExcelPackage(); foreach (var tdefinitions in dmns) { var Items = tdefinitions.Items; var decision = Items.Where(t => t.GetType() == typeof(tDecision)); foreach (tDecision tdecision in decision) { tDecisionTable decisionTable = null; try { DmnConverter.GetDecisionsVariables(tdecision, Path.GetFileNameWithoutExtension(filePath1), ref dmnDataDictionaryModels); } catch { // } } } var bpmnDataDictionary = new List <BpmnInfo>(); DmnConverter.GetDmnInfoFromBpmnModel(bpmnXml, dmnDataDictionaryModels, ref bpmnDataDictionary); //List<DataDictionaryModel> dataDictionaryModels = new List<DataDictionaryModel>(); foreach (var dmnData in dmnDataDictionaryModels) { var submodel = new BpmnInfo(); try { var value = dmnData.GetType(); var property = value.GetProperty("DmnId"); String name = (String)(property.GetValue(dmnData, null)); } catch { } //dataDictionaryModels.Add(new DataDictionaryModel() //{ // BpmnData = submodel, // DmnData = dmnData //}); } ExcelWorksheet wsSheet = excelPkg.Workbook.Worksheets.Add("DmnTEK"); //Filter all dmn by Id var dmnIds = dmnDataDictionaryModels.GroupBy(x => x.DmnId).Select(y => y.First()); var objectPropertyNames = new[] { "DmnId", "DmnName", "TekKapitel", "TekLedd", "TekTabell", "TekForskriften", "TekWebLink" }; ExcelConverter.CreateDmnExcelTableDataDictionary(dmnIds, wsSheet, "dmnTek", objectPropertyNames); ExcelWorksheet wsSheet1 = excelPkg.Workbook.Worksheets.Add("Variables"); var dmnVariablesIds = DmnConverter.GetVariablesFormDmns(dmnDataDictionaryModels); var dmnVariablesIdstPropertyNames = new[] { "VariabelId", "VariabelNavn", "VariabelBeskrivelse", "IFC4", "IfcUrl" }; ExcelConverter.CreateVariablesExcelTableDataDictionary(dmnVariablesIds, wsSheet1, "Variables", dmnVariablesIdstPropertyNames); ExcelWorksheet wsSheet2 = excelPkg.Workbook.Worksheets.Add("Dmn+Variables"); var objectPropertyNames1 = new[] { "DmnId", "VariabelId", "VariabelType" }; ExcelConverter.CreateDMNAndVariablesExcelTableDataDictionary(dmnIds, wsSheet2, "Dmn+Variables", objectPropertyNames1); ExcelWorksheet wsSheet3 = excelPkg.Workbook.Worksheets.Add("summary"); var summaryPropertyNames = new[] { "FileName", "BpmnId", "DmnId", "VariabelId", "VariabelType", "VariablesUseType", "Kilde" }; ExcelConverter.CreateSummaryExcelTableDataDictionary(bpmnDataDictionary, wsSheet3, "summary", summaryPropertyNames); var path = string.Concat(@"c:\temp\"); Directory.CreateDirectory(path); var filePath = Path.Combine(path, string.Concat("dataDictionary", ".xlsx")); excelPkg?.SaveAs(new FileInfo(filePath)); File.Exists(filePath).Should().BeTrue(); }
public IActionResult PostModelsToExcelDataDictionary() { var httpRequest = HttpContext.Request; var httpFiles = httpRequest.Form.Files; var errorDictionary = new Dictionary <string, string>(); var dmnInfoList = new List <DmnInfo>(); var bpmnDataDictionaryModels = new List <BpmnInfo>(); //var dataDictionaryModels = new List<DataDictionaryModel>(); var dataDictionaryModels = new Dictionary <BpmnInfo, List <DmnInfo> >(); if (httpFiles == null && !httpFiles.Any()) { return(NotFound("Can't find any file")); } var dmnFiles = httpFiles.Where(f => Path.GetExtension(f.FileName) == ".dmn"); var bpmFiles = httpFiles.Where(f => Path.GetExtension(f.FileName) == ".bpmn"); var dmnFormsFiles = dmnFiles as IFormFile[] ?? dmnFiles.ToArray(); var bpmnFormFiles = bpmFiles as IFormFile[] ?? bpmFiles.ToArray(); if (!dmnFormsFiles.Any() || !bpmnFormFiles.Any()) { return(BadRequest("They must be one BPMN and at least one DMN to create the data dictionary")); } //get information drom DMN files foreach (var dmnFile in dmnFormsFiles) { tDefinitions dmn; //Deserialize DMN file try { using (Stream dmnfile = dmnFile.OpenReadStream()) { dmn = DmnConverter.DeserializeStreamDmnFile(dmnfile); } if (dmn == null) { errorDictionary.Add(dmnFile.FileName, "DMN Can't be Deserialize. DMN Version 1.2 read more: https://www.omg.org/spec/DMN/1.2"); continue; } } catch (Exception) { errorDictionary.Add(dmnFile.FileName, "DMN Can't be Deserialize. DMN Version 1.2 read more: https://www.omg.org/spec/DMN/1.2"); continue; } // check if DMN have desicion table var items = dmn.Items; var decision = items.Where(t => t.GetType() == typeof(tDecision)); var tdecisions = decision as tDRGElement[] ?? decision.ToArray(); if (!tdecisions.Any()) { errorDictionary.Add(dmnFile.FileName, "Dmn file have non decision"); continue; } //Add Dmn info foreach (var tDrgElement in tdecisions) { var tdecision = (tDecision)tDrgElement; try { DmnConverter.GetDecisionsVariables(tdecision, Path.GetFileNameWithoutExtension(dmnFile.FileName), ref dmnInfoList); } catch { errorDictionary.Add(dmnFile.FileName, "Can't add variables info from DMN"); } } } foreach (var bpmFile in bpmnFormFiles) { try { XDocument bpmnXml; using (Stream dmnfile = bpmFile.OpenReadStream()) { bpmnXml = XDocument.Load(dmnfile); } if (bpmnXml != null) { try { DmnConverter.GetDmnInfoFromBpmnModel(bpmnXml, dmnInfoList, ref bpmnDataDictionaryModels); } catch { errorDictionary.Add(bpmFile.FileName, "Can't add serialize bpmn to Data Model Dictionary"); } } } catch { errorDictionary.Add(bpmFile.FileName, "BPMN Can't be Deserialize. BPMN Version 2.0.2 read more: https://www.omg.org/spec/BPMN/2.0.2"); } } // create Excel Package ExcelPackage excelPkg = null; try { excelPkg = new ExcelPackage(); ExcelWorksheet wsSheet = excelPkg.Workbook.Worksheets.Add("DmnTEK"); var dmnIds = dmnInfoList.GroupBy(x => x.DmnId).Select(y => y.First()); var objectPropertyNames = new[] { "DmnId", "DmnName", "TekKapitel", "TekLedd", "TekTabell", "TekForskriften", "TekWebLink" }; var dmnInfos = dmnIds as DmnInfo[] ?? dmnIds.ToArray(); ExcelConverter.CreateDmnExcelTableDataDictionary(dmnInfos, wsSheet, "dmnTek", objectPropertyNames); ExcelWorksheet wsSheet1 = excelPkg.Workbook.Worksheets.Add("Variables"); var dmnVariablesIds = DmnConverter.GetVariablesFormDmns(dmnInfoList); var dmnVariablesIdstPropertyNames = new[] { "VariabelId", "VariabelName", "VariabelBeskrivelse", "IFC4", "IfcURL" }; ExcelConverter.CreateVariablesExcelTableDataDictionary(dmnVariablesIds, wsSheet1, "Variables", dmnVariablesIdstPropertyNames); ExcelWorksheet wsSheet2 = excelPkg.Workbook.Worksheets.Add("Dmn+Variables"); var objectPropertyNames1 = new[] { "DmnId", "VariabelId", "VariabelType" }; ExcelConverter.CreateDMNAndVariablesExcelTableDataDictionary(dmnInfos, wsSheet2, "Dmn+Variables", objectPropertyNames1); ExcelWorksheet wsSheet3 = excelPkg.Workbook.Worksheets.Add("summary"); var summaryPropertyNames = new[] { "FileName", "BpmnId", "DmnId", "VariabelId", "VariabelType", "VariablesUseType" }; ExcelConverter.CreateSummaryExcelTableDataDictionary(bpmnDataDictionaryModels, wsSheet3, "summary", summaryPropertyNames); } catch { errorDictionary.Add("Error", "Can't create Excel file"); } // Create Excel Stream response var filename = Path.GetFileNameWithoutExtension("Bpmn&Dmn Data Dictionary"); Stream fileStream = null; try { excelPkg.Save(); fileStream = excelPkg.Stream; } catch { errorDictionary.Add(filename, "Can't create excel Stream response"); } if (errorDictionary.Any()) { return(BadRequest(errorDictionary)); } fileStream.Flush(); fileStream.Position = 0; return(File(fileStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"{filename}.xlsx")); }
public IActionResult PosDmnToExcel() { var httpRequest = HttpContext.Request; var httpFiles = httpRequest.Form.Files; var errorDictionary = new Dictionary <string, string>(); if (httpFiles == null && !httpFiles.Any()) { return(NotFound("Can't find any file")); } if (httpFiles.Count == 1) { var file = httpFiles.FirstOrDefault(); tDefinitions dmn = null; //Deserialize DMN file if (file != null) { using (Stream dmnfile = file.OpenReadStream()) { dmn = DmnConverter.DeserializeStreamDmnFile(dmnfile); } } if (dmn == null) { if (file != null) { return(BadRequest(new Dictionary <string, string>() { { file.FileName + ".dmn", "Can't Deserialize DMN file" } })); } } // check if DMN have desicion table var items = dmn.Items; var decision = items.Where(t => t.GetType() == typeof(tDecision)); var tDrgElements = decision as tDRGElement[] ?? decision.ToArray(); if (!tDrgElements.Any()) { if (file != null) { return(BadRequest(new Dictionary <string, string>() { { file.FileName + ".dmn", "Dmn file have non Decision tables" } })); } } // create Excel Package var excelPkg = new ExcelPackage(); foreach (var tdecision in tDrgElements) { try { var dt = ((tDecision)tdecision).Item; var decisionTable = (tDecisionTable)Convert.ChangeType(dt, typeof(tDecisionTable)); ExcelWorksheet wsSheet = excelPkg.Workbook.Worksheets.Add(tdecision.id); //Add Table Title ExcelConverter.AddTableTitle(tdecision.name, wsSheet, decisionTable.hitPolicy.ToString(), tdecision.id); // Add "input" and "output" headet to Excel table ExcelConverter.AddTableInputOutputTitle(wsSheet, decisionTable); //Add DMN Table to excel Sheet ExcelConverter.CreateExcelTableFromDecisionTable(decisionTable, wsSheet, tdecision.id); wsSheet.Protection.IsProtected = true; } catch { if (file != null) { return(BadRequest(new Dictionary <string, string>() { { file.FileName + ".dmn", "Can't be create ExcelPackage" } })); } } } // Create Excel Stream response try { if (file != null) { var filename = Path.GetFileNameWithoutExtension(file.FileName); excelPkg.Save(); var fileStream = excelPkg.Stream; fileStream.Flush(); fileStream.Position = 0; return(File(fileStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"{filename}.xlsx")); } } catch { if (file != null) { errorDictionary.Add(file.FileName, "Can't create excel Stream response"); } } } else { return(BadRequest(new Dictionary <string, string>() { { "Error", "Can't convert more than one file." } })); } return(Ok(new Dictionary <string, string>() { { "Error", "No data to process." } })); }