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)); }
public async Task <IActionResult> PSDWorkbook(Guid Id, Guid templateId, string table, string sheet, string format = "view", Boolean save = false) { var _data = await _context.ge_data .Include(d => d.project) .SingleOrDefaultAsync(m => m.Id == Id); if (_data == null) { return(NotFound()); } if (_data.fileext != ".xlsx") { return(UnprocessableEntity()); } var assert = await new ge_accessController(_context, _authorizationService, _userManager, _env, _ge_config).AssertOperations(_data, new string[] { "Download", "Create" }); var template = await new ge_dataController(_context, _authorizationService, _userManager, _env, _ge_config).getDataAsClass <ge_search>(templateId); List <GRAG_WC> GRAG_WC; using (MemoryStream ms = await new ge_dataController(_context, _authorizationService, _userManager, _env, _ge_config).GetMemoryStream(Id)) { ge_log_workbook wb = new ge_log_workbook(ms); SearchTerms st = new SearchTerms(); ge_search template_loaded = st.findSearchTerms(template, table, wb, sheet); if (template_loaded.search_tables.Count == 0) { return(BadRequest(template_loaded)); } var psd_resp = await ReadPSDData(template_loaded, wb, sheet); var psd_okResult = psd_resp as OkObjectResult; if (psd_okResult.StatusCode != 200) { return(Json(psd_resp)); } GRAG_WC = psd_okResult.Value as List <GRAG_WC>; } string[] tables = new string[] { "GRAG", "GRAT" }; var ags_resp = await new ge_gINTController(_context, _authorizationService, _userManager, _env, _ge_config).getAGSTable(GRAG_WC, tables, "4.04", false); var ags_okResult = ags_resp as OkObjectResult; if (ags_okResult.StatusCode != 200) { return(Json(ags_resp)); } string s1 = ags_okResult.Value as string; byte[] ags = Encoding.ASCII.GetBytes(s1); if (format == "download") { return(File(ags, "text/plain", _data.filename)); } if (format == null || format == "view") { return(File(ags, "text/plain")); } // if (format=="view") { // return View("GRAG_WC",GRAG_WC); // } return(Ok(GRAG_WC)); }
private async Task <IActionResult> ReadPSDData(ge_search template, ge_log_workbook wb, string sheet) { search_table st = template.search_tables[0]; int psize_col = st.headers.Find(e => e.id == "PARTICLESIZE").found; int descr_row = template.search_items.Find(e => e.name == "soil_description").row; int cobble_row = template.search_items.Find(e => e.name == "cobbles").row; int gravel_row = template.search_items.Find(e => e.name == "gravel").row; int sand_row = template.search_items.Find(e => e.name == "sand").row; int silt_row = template.search_items.Find(e => e.name == "silt").row; int clay_row = template.search_items.Find(e => e.name == "clay").row; int sampid_row = template.search_items.Find(e => e.name == "sample_ref").row; int depth_row = template.search_items.Find(e => e.name == "sample_depth").row; int line_start = template.data_start_row(-1); int line_end = template.data_end_row(40); List <GRAG_WC> GRAG_WC = new List <GRAG_WC>(); foreach (value_header vh in st.headers) { if (vh.id == "PARTICLESIZE") { continue; } GRAG_WC gg = new GRAG_WC(); gg.PointID = vh.id; gg.SAMP_Depth = getDouble(wb.getValue(depth_row, vh.found)).Value; gg.Depth = getDouble(wb.getValue(depth_row, vh.found)).Value; gg.SAMP_ID = Convert.ToString(wb.getValue(sampid_row, vh.found)); gg.SPEC_DESC = Convert.ToString(wb.getValue(descr_row, vh.found)); gg.SAMP_TYPE = "EB"; gg.GRAG_VCRE = getDouble(wb.getValue(cobble_row, vh.found)); gg.GRAG_GRAV = getDouble(wb.getValue(gravel_row, vh.found)); gg.GRAG_SAND = getDouble(wb.getValue(sand_row, vh.found)); gg.GRAG_SILT = getDouble(wb.getValue(silt_row, vh.found)); gg.GRAG_CLAY = getDouble(wb.getValue(clay_row, vh.found)); GRAG_WC.Add(gg); for (int i = line_start; i <= line_end; i++) { string psize = Convert.ToString(wb.getValue(i, psize_col)); if (psize == "") { break; } string ppassing = Convert.ToString(wb.getValue(i, vh.found)); if (ppassing == "") { break; } GRAT gt = newGRAT(gg); gt.Reading = Convert.ToDouble(psize); gt.GRAT_PERP = Convert.ToInt16(ppassing); gg.GRAT.Add(gt); } } return(Ok(GRAG_WC)); }