protected override async Task <int> saveXML() { ge_data_file b = new ge_data_file(); data_xml = new ge_data(); b.data_xml = xml_data; ge_MimeTypes types = new ge_MimeTypes(); string stype; types.TryGetValue(FileExtension.XML, out stype); string filename = Path.GetFileNameWithoutExtension(data_ags.filename); data_xml.projectId = data_ags.projectId; data_xml.createdDT = DateTime.Now; data_xml.createdId = userId; data_xml.filename = filename + FileExtension.XML; data_xml.filesize = xml_data.Length; data_xml.filetype = stype; data_xml.filedate = DateTime.UtcNow; data_xml.fileext = FileExtension.XML; data_xml.encoding = "ascii"; data_xml.operations = "Read;Download;Update;Delete"; data_xml.file = b; await _dataService.CreateData(data_xml); return(1); }
private void saveGISFile(Guid projectId, string filename, string userId, string data_string, string ext) { ge_data_file b = new ge_data_file(); ge_data d = new ge_data(); b.data_string = data_string; ge_MimeTypes types = new ge_MimeTypes(); string stype; types.TryGetValue(ext, out stype); d.projectId = projectId; d.createdDT = DateTime.Now; d.createdId = userId; d.filename = filename + ext; d.filesize = data_string.Length; d.filetype = stype; d.filedate = DateTime.UtcNow; d.fileext = ext; d.encoding = "ascii"; d.operations = "Read;Download;Update;Delete"; d.file = b; _context.ge_data.Add(d); _context.SaveChanges(); // status = enumStatus.XMLSaved; }
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 string GetContentType() { var types = new ge_MimeTypes(); var ext = Path.GetExtension(filename).ToLowerInvariant(); if (ext == "") { ext = fileext; } String type = types[ext]; if (filetype != null) { return(filetype); } return(type); }
public async Task <int> CreateData(List <IFormFile> uploadFiles, string[] lastmodified, ge_data template, ModelStateDictionary ModelState, int MaxFileSize) { ge_MimeTypes mtypes = new ge_MimeTypes(); int last_modified_offset = 0; foreach (var formFile in uploadFiles) { ge_data d = new ge_data(); ge_data_file f; d.createdId = template.createdId; d.createdDT = DateTime.UtcNow; d.editedId = template.editedId; d.editedDT = DateTime.UtcNow; Boolean IsContentText = formFile.IsContentTypeText(true); if (IsContentText) { Boolean IsContentXML = formFile.IsContentTypeXML(); if (IsContentXML) { f = await _unitOfWork.Data.GetDataFileString(formFile, ModelState, MaxFileSize, Encoding.UTF8, true); d.SetEncoding(Encoding.UTF8); } else { Encoding encoding = formFile.ReadEncoding(Encoding.UTF8); f = await _unitOfWork.Data.GetDataFileString(formFile, ModelState, MaxFileSize, encoding, false); d.SetEncoding(encoding); } } else { f = await _unitOfWork.Data.GetDataFileBinary(formFile, ModelState, MaxFileSize); d.SetEncoding(null); } // Perform a second check to catch ProcessFormFile method // violations. if (!ModelState.IsValid) { return(-1); } d.projectId = template.Id; d.locEast = template.locEast; d.locNorth = template.locNorth; d.locLevel = template.locLevel; d.locLatitude = template.locLatitude; d.locLongitude = template.locLongitude; d.locHeight = template.locHeight; d.locMapReference = template.locMapReference; d.locName = template.locName; d.locAddress = template.locAddress; d.locPostcode = template.locPostcode; d.datumProjection = template.datumProjection; d.description = template.description; d.keywords = template.keywords; d.operations = template.operations; // Add deatils of uploaded file to new _ge_data record d.file = f; d.filesize = formFile.Length; d.filename = formFile.FilenameNoPath(); d.fileext = formFile.FileExtension(); if (mtypes.ContainsKey(d.fileext)) { d.filetype = mtypes[d.fileext]; } else { d.filetype = formFile.ContentType; } if (lastmodified[last_modified_offset].IsDateTimeFormat()) { d.filedate = Convert.ToDateTime(lastmodified[last_modified_offset]); } await _unitOfWork.Data.AddAsync(d); last_modified_offset++; } return(last_modified_offset); }
public async Task <IActionResult> OnPostAsync() { try { ViewData["ExceptionMessage"] = "No Exceptions"; if (!ModelState.IsValid) { setViewData(); return(Page()); } var project = await _context.ge_project .FirstOrDefaultAsync(p => p.Id == data.projectId); if (project == null) { setViewData(); return(Page()); } data.project = project; var UserAuthorised = await IsUserCreateAuthorised(); if (IsCreateAllowed() != geOPSResp.Allowed) { return(RedirectToPageMessage(msgCODE.DATA_CREATE_PROHIBITED)); } if (!UserAuthorised.Succeeded) { return(RedirectToPageMessage(msgCODE.DATA_CREATE_USER_PROHIBITED)); } if (!UpdateProjectionLoc(data)) { setViewData(); return(Page()); } if (String.IsNullOrEmpty(LastModifiedDates)) { setViewData(); return(Page()); } string[] lastmodified = LastModifiedDates.Split(";"); int i = 0; long MaxFileSize = _config.Value.defaultMaxFileSize; int DbCommandTimeout = Int32.Parse(_config.Value.defaultEFDBTimeOut); ge_MimeTypes mtypes = new ge_MimeTypes(); foreach (var formFile in uploadFiles) { Boolean IsContentText = formFile.IsContentTypeText(true); ge_data_file b = new ge_data_file(); ge_data d = new ge_data(); d.createdId = GetUserIdAsync().Result; if (IsContentText) { Boolean IsContentXML = formFile.IsContentTypeXML(); if (IsContentXML) { b.data_xml = await formFile.ProcessFormFileString(ModelState, MaxFileSize, Encoding.UTF8, true); d.SetEncoding(Encoding.UTF8); } else { Encoding encoding = formFile.ReadEncoding(Encoding.UTF8); b.data_string = await formFile.ProcessFormFileString(ModelState, MaxFileSize, encoding, false); d.SetEncoding(encoding); } } else { b.data_binary = await formFile.ProcessFormFileBinary(ModelState, MaxFileSize); d.SetEncoding(null); } // Perform a second check to catch ProcessFormFile method // violations. if (!ModelState.IsValid) { return(Page()); } d.projectId = project.Id; d.locEast = data.locEast; d.locNorth = data.locNorth; d.locLevel = data.locLevel; d.locLatitude = data.locLatitude; d.locLongitude = data.locLongitude; d.locHeight = data.locHeight; d.locMapReference = data.locMapReference; d.locName = data.locName; d.locAddress = data.locAddress; d.locPostcode = data.locPostcode; d.datumProjection = data.datumProjection; d.description = data.description; d.keywords = data.keywords; d.operations = data.operations; // Add deatils of uploaded file to new _ge_data record d.file = b; d.filesize = formFile.Length; d.filename = getFilenameNoPath(formFile.FileName); d.fileext = formFile.FileExtension(); if (mtypes.ContainsKey(d.fileext)) { d.filetype = mtypes[d.fileext]; } else { d.filetype = formFile.ContentType; } if (IsDateTimeFormat(lastmodified[i])) { d.filedate = Convert.ToDateTime(lastmodified[i]); } if (!UpdateCreated(d)) { return(Page()); } if (!UpdateLastEdited(d)) { return(Page()); } _context.ge_data.Add(d); i++; } if (DbCommandTimeout > 0) { _context.Database.SetCommandTimeout(DbCommandTimeout); } await _context.SaveChangesAsync(); return(RedirectToPage("./Index", new { projectId = data.projectId })); } catch (Exception e) { String msg = e.Message + e.InnerException.Message; ViewData["ExceptionMessage"] = "Exception: " + msg; return(Page()); } }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var project = await _context.ge_project .FirstOrDefaultAsync(m => m.Id == data.projectId); if (project == null) { return(Page()); } data.project = project; int isUpdateAllowed = IsUpdateAllowed(); var UserAuthorised = await IsUserUpdateAuthorised(); if (isUpdateAllowed != geOPSResp.Allowed) { if (isUpdateAllowed == geOPSResp.Data && !IsUserAdmin()) { return(RedirectToPageMessage(msgCODE.DATA_UPDATE_PROHIBITED)); } if (isUpdateAllowed == geOPSResp.ProjectData && !IsUserAdmin()) { return(RedirectToPageMessage(msgCODE.DATA_UPDATE_PROHIBITED)); } if (isUpdateAllowed == geOPSResp.DataApproved && !IsUserApprover()) { return(RedirectToPageMessage(msgCODE.DATA_UPDATE_PROHIBITED)); } if (isUpdateAllowed == geOPSResp.ProjectApproved && !IsUserApprover()) { return(RedirectToPageMessage(msgCODE.DATA_UPDATE_PROHIBITED)); } } if (!UserAuthorised.Succeeded && !IsUserAdmin()) { return(RedirectToPageMessage(msgCODE.DATA_UPDATE_USER_PROHIBITED)); } if (!UpdateProjectionLoc(data)) { return(Page()); } if (!UpdateLastEdited(data)) { return(Page()); } long MaxFileSize = _config.Value.defaultMaxFileSize; int DbCommandTimeout = Int32.Parse(_config.Value.defaultEFDBTimeOut); if (uploadFiles.Count > 0) { ge_MimeTypes mtypes = new ge_MimeTypes(); string[] lastmodified = LastModifiedDates.Split(";"); var formFile = uploadFiles[0]; var b = await _context.ge_data_file.FirstOrDefaultAsync(m => m.Id == data.Id); Boolean IsContentText = formFile.IsContentTypeText(true); if (IsContentText) { Boolean IsContentXML = formFile.IsContentTypeXML(); if (IsContentXML) { b.data_xml = await formFile.ProcessFormFileString(ModelState, MaxFileSize, Encoding.UTF8, true); b.data_string = null; b.data_binary = null; data.SetEncoding(Encoding.UTF8); } else { Encoding encoding = formFile.ReadEncoding(Encoding.UTF8); b.data_binary = null; b.data_xml = null; b.data_string = await formFile.ProcessFormFileString(ModelState, MaxFileSize, encoding, false); data.SetEncoding(encoding); } } else { b.data_xml = null; b.data_string = null; b.data_binary = await formFile.ProcessFormFileBinary(ModelState, MaxFileSize); data.SetEncoding(null); } if (!ModelState.IsValid) { return(Page()); } data.file = b; data.filesize = formFile.Length; data.filename = getFilenameNoPath(formFile.FileName); data.fileext = formFile.FileExtension(); if (mtypes.ContainsKey(data.fileext)) { data.filetype = mtypes[data.fileext]; } else { data.filetype = formFile.ContentType; } if (IsDateTimeFormat(lastmodified[0])) { data.filedate = Convert.ToDateTime(lastmodified[0]); } } _context.Attach(data).State = EntityState.Modified; try { if (DbCommandTimeout > 0) { _context.Database.SetCommandTimeout(DbCommandTimeout); } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!dataExists(data.Id)) { return(NotFound()); } else { throw; } } catch (Exception e) { String msg = e.Message + e.InnerException.Message; ViewData["ExceptionMessage"] = "Exception: " + msg; return(Page()); } return(RedirectToPage("./Index", new { projectId = data.projectId })); }