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; }
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); }
public async Task <IActionResult> OnPostAsync(Guid?id) { if (id == null) { return(NotFound()); } data = await _context.ge_data .Include(m => m.project) .SingleOrDefaultAsync(m => m.Id == id); if (data == null) { return(NotFound()); } var UserAuthorised = await IsUserDeleteAuthorised(); if (IsDeleteAllowed() != geOPSResp.Allowed) { return(RedirectToPageMessage(msgCODE.DATA_DELETE_PROHIBITED)); } if (!UserAuthorised.Succeeded) { return(RedirectToPageMessage(msgCODE.DATA_DELETE_USER_PROHIBITED)); } // remember projectId before deleting data Guid projectId = data.projectId; //var objectContext = (_context as IObjectContextAdapter).ObjectContext; // Sets the command timeout for all the commands //objectContext.CommandTimeout = 120; _context.Database.SetCommandTimeout(120); // _context.Database.ExecuteSqlCommand("delete dbo.ge_data where Id = {0}", new object[] { data.Id }); // Create empty ge_data_file with ge_data Id to avoid having to download all data ge_data_file empty_file = new ge_data_file() { Id = data.Id }; _context.ge_data_file.Attach(empty_file); // Now mark the ge_data entity and ge_data_file for deletion _context.ge_data_file.Remove(empty_file); _context.ge_data.Remove(data); //_context.Entry<ge_data_file>(empty_file).State = EntityState.Deleted; //_context.Entry<ge_data>(data).State = EntityState.Deleted; // Apply changes await _context.SaveChangesAsync(); return(RedirectToPage("./Index", new { projectId = projectId })); }
public async Task <IActionResult> Post(string log_file, string origin_data, string format) { ge_log_file f = null; ge_data d = null; ge_data_file b = new ge_data_file(); if (format == "json") { d = JsonConvert.DeserializeObject <ge_data>(origin_data); f = JsonConvert.DeserializeObject <ge_log_file>(log_file); d.filetype = "text/json"; d.fileext = ".json"; d.encoding = "utf-8"; b.data_string = log_file; } if (format == "xml") { d = (ge_data)origin_data.DeserializeFromXmlString <ge_data>(); f = (ge_log_file)log_file.DeserializeFromXmlString <ge_log_file>(); d.filetype = "text/xml"; d.fileext = ".xml"; d.encoding = "utf-8"; b.data_xml = log_file; } var user = await GetUserAsync(); d.Id = f.Id; string filename = d.filename.Substring(0, d.filename.IndexOf(".")) + ' ' + f.channel + ".xml"; d.filename = filename; d.filesize = log_file.Length; d.createdDT = DateTime.Now; d.editedDT = DateTime.Now; d.editedId = user.Id; d.createdId = user.Id; string s1 = d.SerializeToXmlString <ge_data>(); string s2 = b.SerializeToXmlString <ge_data_file>(); var resp_post = await new ge_dataController(_context, _authorizationService, _userManager, _env, _ge_config).Post(s1, s2, "xml"); return(resp_post); }
public ge_data NewData(Guid projectId, string UserId, ge_log_file log_file, string saveAsFormat) { ge_data _data = NewData(projectId, UserId); ge_data_file _file = new ge_data_file(); if (saveAsFormat == "text/xml") { // _file.data_xml = SerializeToXmlString<ge_log_file>(); } if (saveAsFormat == "json") { _file.data_string = JsonConvert.SerializeObject(log_file); } _data.file = _file; return(_data); }
public async Task <IActionResult> Put(Guid Id, string data, string data_big, string format) { ge_data data1 = null; ge_data_file data_big1 = null; if (format == "json") { data1 = JsonConvert.DeserializeObject <ge_data>(data); data_big1 = JsonConvert.DeserializeObject <ge_data_file>(data_big); } if (format == "xml") { data1 = data.DeserializeFromXmlString <ge_data>(); data_big1 = data_big.DeserializeFromXmlString <ge_data_file>(); } data1.Id = Id; data1.file = data_big1; _context.ge_data.Update(data1); int DbCommandTimeout = Int32.Parse(_ge_config.Value.defaultEFDBTimeOut); if (DbCommandTimeout > 0) { _context.Database.SetCommandTimeout(DbCommandTimeout); } int resp = await _context.SaveChangesAsync(); if (resp == 1) { return(Ok(data1)); } return(BadRequest(data1)); }
public async Task <ActionResult> View(Guid transformId, Guid?Id, Guid?projectId, Guid?groupId, string[] projects, string[] holes, string[] tables, string[] geols, string[] options, string[] args, string[] vals, string flwor, string xpath, string version) { if (transformId == Guid.Empty) { return(new EmptyResult()); } transform = _context.ge_transform. Include(t => t.project). Where(t => t.Id == transformId).FirstOrDefault(); if (transform == null) { return(new EmptyResult()); } string arg_val = ""; for (int i = 0; i < args.Length; i++) { if (arg_val.Length > 0) { arg_val += "&"; } arg_val += args[i] + "=" + vals[i]; } if (projectId == null) { projectId = transform.projectId; } if (groupId == null) { groupId = transform.project.groupId; } ge_transform_parameters transform_params = getTransformParameters(transformId, Id, projectId, groupId, projects, holes, tables, geols, options, arg_val, flwor, xpath, version); /* Convert JSON back to string to pass via ViewBag */ string parameters = JsonConvert.SerializeObject(transform_params); if (transform.service_endpoint != null) { string endpoint = getEndPointURL(transform.service_endpoint); var resp = await getServiceEndPointData(endpoint, transform_params); var xmlResult = resp as XmlActionResult; if (xmlResult != null) { xml_data = xmlResult.Value(); } var okResult = resp as OkObjectResult; if (okResult != null) { if (okResult.StatusCode == 200) { xml_data = okResult.Value as string; } } } if (transform.dataId != null && transform.storedprocedure == null) { xml_data = await new ge_dataController(_context, _authorizationService, _userManager, _env, _ge_config).getDataAsParsedXmlString(transform.dataId.Value); } if (transform.styleId != null) { xsl_data = await new ge_dataController(_context, _authorizationService, _userManager, _env, _ge_config).getDataAsParsedXmlString(transform.styleId.Value); } if (transform.queryId != null) { qry_data = await new ge_dataController(_context, _authorizationService, _userManager, _env, _ge_config).getDataAsString(transform.queryId.Value, false); } if (transform.dataId != null && transform.storedprocedure != null) { string dataId = transform.dataId.ToString(); if (!String.IsNullOrEmpty(transform.add_data)) { dataId = dataId + ";" + transform.add_data; } string[] data_all = dataId.Split(";"); string rawSQL = getSQLCommand(constSELECTALLFROM, data_all, holes, tables, version); ge_data_file task_xml_data_big = await _context.ge_data_file.FromSql(rawSQL).SingleOrDefaultAsync(); xml_data = task_xml_data_big.getParsedXMLstring(null); } if (!String.IsNullOrEmpty(qry_data)) { string res = XQuery(xml_data, qry_data); if (!String.IsNullOrEmpty(res)) { xml_data = res; } } if (xml_data == null || xsl_data == null) { new EmptyResult(); } ViewBag.xml_data = xml_data; ViewBag.xsl_stylesheet = xsl_data; ViewBag.xlt_arguments = parameters; return(View("View")); }
public async Task <ge_data_file> GetDataFileBinary(IFormFile formFile, ModelStateDictionary modelState, long MaxFileSize) { var fieldDisplayName = string.Empty; // Use reflection to obtain the display name for the model // property associated with this IFormFile. If a display // name isn't found, error messages simply won't show // a display name. MemberInfo property = typeof(ge_fileUpload).GetProperty(formFile.Name.Substring(formFile.Name.IndexOf(".") + 1)); if (property != null) { var displayAttribute = property.GetCustomAttribute(typeof(DisplayAttribute)) as DisplayAttribute; if (displayAttribute != null) { if (displayAttribute != null) { fieldDisplayName = $"{displayAttribute.Name} "; } } } // Use Path.GetFileName to obtain the file name, which will // strip any path information passed as part of the // FileName property. HtmlEncode the result in case it must // be returned in an error message. var fileName = WebUtility.HtmlEncode(Path.GetFileName(formFile.FileName)); // Check the file length and don't bother attempting to // read it if the file contains no content. This check // doesn't catch files that only have a BOM as their // content, so a content length check is made later after // reading the file's content to catch a file that only // contains a BOM. if (formFile.Length == 0) { modelState.AddModelError(formFile.Name, $"The {fieldDisplayName}file ({fileName}) is empty."); } else if (formFile.Length > MaxFileSize) { modelState.AddModelError(formFile.Name, $"The {fieldDisplayName}file ({fileName}) exceeds max file size ({MaxFileSize/1e6} Mb)"); } else { try { byte[] buffer = new byte[16 * 1024]; MemoryStream ms = new MemoryStream(); BinaryReader reader = new BinaryReader(formFile.OpenReadStream()); int read; while ((read = reader.Read(buffer, 0, buffer.Length)) > 0) { await ms.WriteAsync(buffer, 0, read); } ge_data_file _file = new ge_data_file(); _file.data_binary = ms.ToArray(); // Check the content length in case the file's only // content was a BOM and the content is actually // empty after removing the BOM. if (_file.data_binary.Length > 0) { return(_file); } else { modelState.AddModelError(formFile.Name, $"The {fieldDisplayName}file ({fileName}) is empty."); } } catch (Exception ex) { modelState.AddModelError(formFile.Name, $"The {fieldDisplayName}file ({fileName}) upload failed. " + $"Please contact the Help Desk for support. Error: {ex.Message}"); // Log the exception } } return(null); }
public async Task <ge_data_file> GetDataFileString(IFormFile formFile, ModelStateDictionary modelState, long MaxFileSize, Encoding encoding, Boolean removeXMLDeclaration) { var fieldDisplayName = string.Empty; // Use reflection to obtain the display name for the model // property associated with this IFormFile. If a display // name isn't found, error messages simply won't show // a display name. MemberInfo property = typeof(ge_fileUpload).GetProperty(formFile.Name.Substring(formFile.Name.IndexOf(".") + 1)); if (property != null) { var displayAttribute = property.GetCustomAttribute(typeof(DisplayAttribute)) as DisplayAttribute; if (displayAttribute != null) { if (displayAttribute != null) { fieldDisplayName = $"{displayAttribute.Name} "; } } } // Use Path.GetFileName to obtain the file name, which will // strip any path information passed as part of the // FileName property. HtmlEncode the result in case it must // be returned in an error message. var fileName = WebUtility.HtmlEncode(Path.GetFileName(formFile.FileName)); if (!formFile.IsContentTypeText(true)) { modelState.AddModelError(formFile.Name, $"The {fieldDisplayName}file ({fileName}) must be a text file."); } // Check the file length and don't bother attempting to // read it if the file contains no content. This check // doesn't catch files that only have a BOM as their // content, so a content length check is made later after // reading the file's content to catch a file that only // contains a BOM. if (formFile.Length == 0) { modelState.AddModelError(formFile.Name, $"The {fieldDisplayName}file ({fileName}) is empty."); } else if (formFile.Length > MaxFileSize) { modelState.AddModelError(formFile.Name, $"The {fieldDisplayName}file ({fileName}) exceeds {MaxFileSize/1e6} MB."); } else { try { // The StreamReader is created to read files that are UTF-8 encoded. // If uploads require some other encoding, provide the encoding in the // using statement. To change to 32-bit encoding, change // new UTF8Encoding(...) to new UTF32Encoding(). using ( var reader = new StreamReader( formFile.OpenReadStream(), encoding, detectEncodingFromByteOrderMarks: true)) { ge_data_file _file = new ge_data_file(); _file.data_string = await reader.ReadToEndAsync(); // Check the content length in case the file's only // content was a BOM and the content is actually // empty after removing the BOM. if (_file.data_string.Length > 0) { if (removeXMLDeclaration == true) { // Encoding newEncoding = new UnicodeEncoding(); // string fileContents2 = fileContents.SetEncoding(newEncoding); _file.data_string = _file.data_string.RemoveXmlDeclaration(); return(_file); } return(_file); } else { modelState.AddModelError(formFile.Name, $"The {fieldDisplayName}file ({fileName}) is empty."); } } } catch (Exception ex) { modelState.AddModelError(formFile.Name, $"The {fieldDisplayName}file ({fileName}) upload failed. " + $"Please contact the Help Desk for support. Error: {ex.Message}"); // Log the exception } } return(null); }
public async Task <IActionResult> Post([FromForm] ge_fileUpload data) { if (data.files == null) { throw new ArgumentNullException(nameof(data.files)); } if (data.projectId == null) { throw new ArgumentNullException(nameof(data.files)); } if (_ge_config == null) { throw new ArgumentNullException(nameof(data.files)); } var ge_project = await _context.ge_project.FindAsync(data.projectId); if (ge_project == null) { return(NotFound()); } long size = data.files.Sum(f => f.Length); long max_size = _ge_config.Value.defaultMaxFileSize; // full path to file in temp location var filePath = Path.GetTempFileName(); foreach (var uploadFile in data.files) { if (uploadFile.Length > 0) { Boolean IsContentText = uploadFile.IsContentTypeText(true); var b = new ge_data_file(); var d = new ge_data(); if (IsContentText) { Boolean IsContentXML = uploadFile.IsContentTypeXML(); Encoding encoding = uploadFile.ReadEncoding(Encoding.Unicode); d.SetEncoding(encoding); if (IsContentXML) { Encoding encoding16 = new UnicodeEncoding(); d.SetEncoding(encoding16); b.data_xml = await uploadFile.ProcessFormFileString(ModelState, max_size, encoding, true); } else { b.data_string = await uploadFile.ProcessFormFileString(ModelState, max_size, encoding, false); } } else { b.data_binary = await uploadFile.ProcessFormFileBinary(ModelState, max_size); d.SetEncoding(null); } // Perform a second check to catch ProcessFormFile method violations. if (!ModelState.IsValid) { return(NotFound()); } d.projectId = ge_project.Id; d.locEast = ge_project.locEast; d.locNorth = ge_project.locNorth; // Add deatils of uploaded file to new _ge_data record d.file = b; d.filesize = uploadFile.Length; d.filename = uploadFile.FileName; d.createdDT = DateTime.UtcNow; // ge_data.ownerId = User. _context.ge_data.Add(d); await _context.SaveChangesAsync(); } } // process uploaded files // Don't rely on or trust the FileName property without validation. return(Ok()); }
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 void insertBigData(ge_data_file data) { }