public ge_data_table NewFile(ge_search dic, string[] lines, Guid dataId, Guid templateId) { search_table st = dic.search_tables[0]; search_range sr = st.header; string header_row = dic.search_items.Find(e => e.name == sr.search_item_name).row_text; string[] columns = Split(header_row, 100); int line_start = dic.data_start_row(NOT_FOUND); int line_end = dic.data_end_row(lines.Count()); ge_data_table _dt = new ge_data_table(st.name, columns); for (int i = line_start; i < line_end; i++) { string line = lines[i]; if (line.Length > 0) { string[] values = Split(line, _dt.dt.Columns.Count); DataRow row = _dt.dt.NewRow(); set_values(columns, values, row); _dt.dt.Rows.Add(row); } } return(_dt); }
public async Task <ge_data_table> 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); int resp = loadTemplateAndLines(data_file, template, table, sheet, _dataService, out template_loaded, out lines); if (resp == -1) { return(null); } ge_data_table dt = NewFile(template_loaded, lines, Id, templateId); dt.search_template = template; dt.search_table = template_loaded.search_tables[0]; return(dt); }
public async Task <ge_data> CreateData(Guid projectId, string UserId, ge_data_table dt_file, string filename, string description, string format) { ge_MimeTypes mtypes = new ge_MimeTypes(); string fileext = "xml"; string s1 = dt_file.SerializeToXmlStringUTF8 <ge_data_table>(); if (format == "xml") { fileext = ".xml"; } if (format == "json") { fileext = ".json"; } string filetype = mtypes[fileext]; var _data = new ge_data { Id = Guid.NewGuid(), projectId = projectId, createdId = UserId, createdDT = DateTime.Now, editedDT = DateTime.Now, editedId = UserId, filename = filename, filesize = s1.Length, fileext = fileext, filetype = filetype, filedate = DateTime.Now, encoding = "utf-8", datumProjection = datumProjection.NONE, pstatus = PublishStatus.Uncontrolled, cstatus = ConfidentialityStatus.RequiresClientApproval, version = "P01.1", vstatus = VersionStatus.Intermediate, qstatus = QualitativeStatus.AECOMFactual, description = description, operations = "Read;Download;Update;Delete", file = new ge_data_file { data_xml = s1 } }; return(await CreateData(_data)); }
public async Task <IAGSGroupTables> CreateAGS(Guid Id, Guid tablemapId, string[] agstables, string options, IDataService _dataService) { ge_data_table dt = await _dataService.GetFileAsClass <ge_data_table>(Id); ge_table_map map = await _dataService.GetFileAsClass <ge_table_map>(tablemapId); if (dt != null && map != null) { IAGSGroupTables ags_file = CreateAGS(dt, map, agstables, options); return(ags_file); } return(null); }
public async Task <KMLDoc> CreateKML(Guid Id, Guid tablemapId, string options, IDataService _dataService) { ge_data_table dt = await _dataService.GetFileAsClass <ge_data_table>(Id); ge_table_map map = await _dataService.GetFileAsClass <ge_table_map>(tablemapId); if (dt != null && map != null) { KMLDoc kml_file = CreateKML(dt, map, options); return(kml_file); } return(null); }
public KMLDoc CreateKML(ge_data_table dt_file, ge_table_map map, string options) { KMLDoc kml = new KMLDoc(); ILocaService _locaService = new LocaService(); foreach (table_map tm in map.table_maps.Where(m => m.destination == "kml")) { List <ge_data> list = ConvertDataTable <ge_data>(dt_file.dt, tm); foreach (ge_data d in list) { string msg; if (d.folder == null) { d.folder = dt_file.dt.TableName; } if (d.datumProjection == datumProjection.NONE) { d.datumProjection = datumProjection.OSGB36NG; } if (d.locName == "P2BH20") { Console.WriteLine("P2BH20"); } _locaService.UpdateProjectionLoc(d, out msg, ""); d.phistory = msg; } string[] folders = list.Select(m => m.folder).Distinct().ToArray(); foreach (string folder in folders) { Folder f = new Folder(); f.name = folder; f.Placemarks = GetPlacemarks(list); kml.Document.Folders.Add(f); } } return(kml); }
public IAGSGroupTables CreateAGS(ge_data_table dt_file, ge_table_map map, string[] agstables, string options) { IAGSGroupTables ags_tables = new AGS404GroupTables(); if (agstables.Contains("PROJ")) { List <PROJ> proj = getPROJ(); ags_tables.AddTable(proj); } if (agstables.Contains("ERES")) { foreach (table_map tm in map.table_maps.Where(m => m.destination == "ERES")) { if (tm != null) { List <ERES> list = ConvertDataTable <ERES>(dt_file.dt, tm); ags_tables.AddTable(list); if (agstables.Contains("ABBR")) { List <ABBR> abbr = getABBR(list); ags_tables.AddTable(abbr); } if (agstables.Contains("UNIT")) { List <UNIT> unit = getUNIT(list); ags_tables.AddTable(unit); } } } } if (agstables.Contains("TRAN")) { List <TRAN> tran = getTRAN(); ags_tables.AddTable(tran); } if (agstables.Contains("POINT")) { foreach (table_map tm in map.table_maps.Where(m => m.destination == "LOCA")) { List <POINT> list = ConvertDataTable <POINT>(dt_file.dt, tm); string[] distinct = list.Select(m => m.PointID).Distinct().ToArray(); List <POINT> unique = getFirsts(list, distinct); ags_tables.AddTable(unique); if (agstables.Contains("ABBR")) { List <ABBR> abbr = getABBR(list); ags_tables.AddTable(abbr); } } } if (agstables.Contains("SAMP")) { foreach (table_map tm in map.table_maps.Where(m => m.destination == "SAMP")) { List <SAMP> list = ConvertDataTable <SAMP>(dt_file.dt, tm); string[] distinct = list.Select(m => m.SAMP_ID).Distinct().ToArray(); List <SAMP> unique = getFirsts(list, distinct); ags_tables.AddTable(unique); } } if (agstables.Contains("MOND")) { foreach (table_map tm in map.table_maps.Where(m => m.destination == "MOND")) { if (tm != null) { List <MOND> list = ConvertDataTable <MOND>(dt_file.dt, tm); ags_tables.AddTable(list); if (agstables.Contains("ABBR")) { List <ABBR> abbr = getABBR(list); ags_tables.AddTable(abbr); } if (agstables.Contains("UNIT")) { List <UNIT> unit = getUNIT(list); ags_tables.AddTable(unit); } } } } if (agstables.Contains("MONG")) { foreach (table_map tm in map.table_maps.Where(m => m.destination == "MONG")) { if (tm != null) { List <MONG> list = ConvertDataTable <MONG>(dt_file.dt, tm); ags_tables.AddTable(list); if (agstables.Contains("ABBR")) { List <ABBR> abbr = getABBR(list); ags_tables.AddTable(abbr); } } } } if (agstables.Contains("ABBR")) { foreach (table_map tm in map.table_maps.Where(m => m.destination == "ABBR")) { if (tm != null) { List <ABBR> list = ConvertDataTable <ABBR>(dt_file.dt, tm); ags_tables.AddTable(list); } } } if (agstables.Contains("UNIT")) { foreach (table_map tm in map.table_maps.Where(m => m.destination == "UNIT")) { if (tm != null) { List <UNIT> list = ConvertDataTable <UNIT>(dt_file.dt, tm); ags_tables.AddTable(list); } } } if (agstables.Contains("TYPE")) { foreach (table_map tm in map.table_maps.Where(m => m.destination == "TYPE")) { if (tm != null) { List <TYPE> list = ConvertDataTable <TYPE>(dt_file.dt, tm); ags_tables.AddTable(list); } } } if (agstables.Contains("DICT")) { foreach (table_map tm in map.table_maps.Where(m => m.destination == "DICT")) { if (tm != null) { List <DICT> list = ConvertDataTable <DICT>(dt_file.dt, tm); ags_tables.AddTable(list); } } } return(ags_tables); }
public async Task <IActionResult> ProcessFileToAGS(Guid Id, Guid?templateId, string table, string sheet, Guid?tablemapId, string[] agstables, Guid?agslibraryId, string options = "", string format = "view", Boolean save = false) { Boolean save_file = true; Boolean save_ags = save; if (options == null) { options = ""; } if (options.Contains("background")) { if (save == true && !options.Contains("save_ags")) { options += ",save_ags"; } return(await ProcessFileBackground(Id, templateId, table, sheet, tablemapId, agstables, options)); } if (options.Contains("read_file_only")) { save_file = false; } var calc_resp = await ReadFile(Id, templateId.Value, table, sheet, "", save_file); var okResult = calc_resp as OkObjectResult; if (okResult == null) { var vwResult = calc_resp as ViewResult; if (vwResult == null) { return(Json(calc_resp)); } return(calc_resp); // return View ("OperationRequest",calc_resp); } ge_data_table _dt_file = okResult.Value as ge_data_table; if (options.Contains("view_file")) { if (format == "view") { return(View("ReadData", _dt_file)); } if (format == "json") { return(Json(_dt_file)); } return(Ok(_dt_file)); } if (save_file == false) { ITableFileAGSService _tableFileAGSService = new TableFileAGSService(); ge_table_map _tm = await _dataTableFileService.GetFileAsClass <ge_table_map>(tablemapId.Value); if (_tm == null) { return(Json($"table map for field not found for id={tablemapId.Value}")); } IAGSGroupTables _ags_tables = _tableFileAGSService.CreateAGS(_dt_file, _tm, agstables, options); if (agslibraryId != null) { await _dataAGSService.SetLibraryAGSData(agslibraryId.Value, null); } await _dataAGSService.AddLibraryAGSData(_ags_tables, null); if (save_ags == true) { var _data = await _dataTableFileService.GetDataByIdWithAll(Id); var _tablemap = await _dataTableFileService.GetDataByIdWithAll(tablemapId.Value); var _user = await GetUserAsync(); await _dataAGSService.CreateData(_data.projectId, _user.Id, _ags_tables, _data.FileNameNoExtention() + ".ags", $"AGS Conversion from data table {_data.filename} using table map {_tablemap.filename}", "ags"); } if (format == "view") { return(View(_ags_tables)); } if (format == "json") { return(Json(_ags_tables)); } return(Ok(_ags_tables)); // return await View (mond, format); } return(await CreateAGS(Id, tablemapId.Value, agstables, options, format, save_ags)); }
public async Task <IActionResult> ReadFile(Guid Id, Guid templateId, string table, string sheet, string format = "view", Boolean save = false) { if (Id == Guid.Empty) { return(NotFound()); } if (templateId == Guid.Empty) { return(NotFound()); } var _data = await _dataTableFileService.GetDataByIdWithAll(Id); if (_data == null) { return(NotFound()); } var _template = await _dataTableFileService.GetDataById(templateId); if (_template == null) { return(NotFound()); } var empty_data = new ge_data(); var user = await GetUserAsync(); if (user == null) { return(NotFound()); } var _AllowedDataOperations = await _userService.GetAllowedOperations(user.Id, _data); var _AllowedProjectOperations = await _userService.GetAllowedOperations(user.Id, _data.project); var _AllowedGroupOperations = await _userService.GetAllowedOperations(user.Id, _data.project.group); var _IsProjectAdmin = await _userService.IsUserProjectAdmin(user.Id, _data.project); var _IsGroupAdmin = await _userService.IsUserGroupAdmin(user.Id, _data.project.group); var _OperationRequest = await _userService.GetOperationRequest(user.Id, _data); if (_OperationRequest.AreProjectOperationsAllowed("Download;Create") == false) { if (format == "view") { return(View("OperationRequest", _OperationRequest)); } return(NotFound()); } ITableFileService _tableFileService = new TableFileService(); ge_data_table _tableFile = await _tableFileService.NewFile(Id, templateId, table, sheet, _dataTableFileService); if (_tableFile == null) { return(Json($"Unable to locate table ({table}) from template file ({_template.filename}) in data file ({_data.filename})")); } if (save == true) { await _dataTableFileService.CreateData(_data.projectId, user.Id, _tableFile, _data.FileNameNoExtention() + ".xml", $"datatable read from {_data.filename}", "xml"); } if (format == "view") { return(View(_tableFile)); } return(Ok(_tableFile)); }