public int loadTemplateAndLines(ge_data data_file, ge_search template, string table, string sheet, IDataService _dataService, out ge_search template_loaded, out string[] lines) { lines = null; template_loaded = null; if (data_file.fileext == ".csv") { var resp = _dataService.GetFileAsLines(data_file.Id); lines = (string[])resp.Result; SearchTerms st = new SearchTerms(); template_loaded = st.findSearchTerms(template, table, lines); if (template_loaded.search_tables.Count == 0) { return(-1); } } if (data_file.fileext == ".xlsx") { var resp = _dataService.GetFileAsMemoryStream(data_file.Id); using (MemoryStream ms = (MemoryStream)resp.Result) { ge_log_workbook wb = new ge_log_workbook(ms); SearchTerms st = new SearchTerms(); if (sheet.Contains(",")) { string[] sheets = sheet.Split(","); template_loaded = st.findSearchTerms(template, table, wb, sheets); } else { template_loaded = st.findSearchTerms(template, table, wb, sheet); } if (template_loaded.search_tables.Count == 0) { lines = null; return(-1); } wb.setWorksheet(template_loaded.search_tables[0].sheet); wb.evaluateSheet(); lines = wb.WorksheetToTable(50, true); wb.close(); return(1); } } return(-1); }
public async Task <ge_log_file> NewFile(Guid Id, Guid templateId, string table, string sheet, IDataService _dataService) { string[] lines = null; ge_search template_loaded = null; ge_search template = await _dataService.GetFileAsClass <ge_search>(templateId); ge_data data_file = await _dataService.GetDataById(Id); if (data_file.fileext == ".csv") { lines = await _dataService.GetFileAsLines(data_file.Id); SearchTerms st = new SearchTerms(); template_loaded = st.findSearchTerms(template, table, lines); if (template_loaded.search_tables.Count == 0) { return(null); } } if (data_file.fileext == ".xlsx") { using (MemoryStream ms = await _dataService.GetFileAsMemoryStream(data_file.Id)) { ge_log_workbook wb = new ge_log_workbook(ms); SearchTerms st = new SearchTerms(); if (sheet.Contains(",")) { string[] sheets = sheet.Split(","); template_loaded = st.findSearchTerms(template, table, wb, sheets); } else { template_loaded = st.findSearchTerms(template, table, wb, sheet); } if (template_loaded.search_tables.Count == 0) { return(null); } wb.setWorksheet(template_loaded.search_tables[0].sheet); wb.evaluateSheet(); lines = wb.WorksheetToTable(); wb.close(); } } return(NewFile(template_loaded, lines, Id, templateId)); }