public async Task <IActionResult> UploadXmlFile(List <IFormFile> files) { var file = this.Request?.Form?.Files?.FirstOrDefault(); if (file == null) { return(this.BadRequest("Datei konnte nicht geladen werden.")); } this.applicationState.CurrentSupplierFile = new SupplierFile(); this.applicationState.CurrentSupplierFile.Data = new MemoryStream(); this.applicationState.CurrentSupplierFile.Filename = file.FileName; await file.CopyToAsync(this.applicationState.CurrentSupplierFile.Data); this.applicationState.CurrentSupplierFile.DigestRipemd160 = DigestUtils.GetRipemd160(this.applicationState.CurrentSupplierFile.Data); this.applicationState.CurrentSupplierFile.DigestSha3 = DigestUtils.GetSha3(this.applicationState.CurrentSupplierFile.Data); try { this.applicationState.CurrentSupplierFile.Data.Position = 0; this.applicationState.CurrentSupplierFile.Xml = XDocument.Load(this.applicationState.CurrentSupplierFile.Data); } catch (Exception ex) { Log.Error(ex, "Failed to XML file: {0}", ex.Message); this.applicationState.CurrentSupplierFile.Xml = null; return(this.BadRequest("Datei konnte nicht geladen werden.")); } return(this.Ok()); }
/// <summary> /// Gets the digest of the specified file. /// </summary> /// <param name="item">The item to calculate the digest for.</param> private void GetDigest(DigestItem item) { var directory = Path.GetDirectoryName(this.GetType().Assembly.Location); var filepath = Path.Combine(directory, item.Filepath); if (File.Exists(filepath)) { item.Digest = DigestUtils.GetRipemd160(filepath).AddSpace(4).Value; } else { item.Digest = "nicht gefunden"; } }
public async Task <IActionResult> DownloadFile(string url, string username, string password) { try { using (var client = new HttpClient()) { if (!string.IsNullOrWhiteSpace(username) || !string.IsNullOrWhiteSpace(password)) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( "Basic", Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}"))); } var request = new HttpRequestMessage(HttpMethod.Get, url); using (var response = await client.SendAsync(request)) { if (response.IsSuccessStatusCode) { this.applicationState.CurrentSupplierFile = new SupplierFile(); this.applicationState.CurrentSupplierFile.Data = new MemoryStream(await response.Content.ReadAsByteArrayAsync()); this.applicationState.CurrentSupplierFile.DownloadUrl = url; this.applicationState.CurrentSupplierFile.Username = username; this.applicationState.CurrentSupplierFile.Password = password; this.applicationState.CurrentSupplierFile.DigestRipemd160 = DigestUtils.GetRipemd160(this.applicationState.CurrentSupplierFile.Data); this.applicationState.CurrentSupplierFile.DigestSha3 = DigestUtils.GetSha3(this.applicationState.CurrentSupplierFile.Data); this.applicationState.CurrentSupplierFile.Data.Position = 0; this.applicationState.CurrentSupplierFile.Xml = XDocument.Load(this.applicationState.CurrentSupplierFile.Data); } } } } catch (Exception ex) { return(this.BadRequest(ex.Message)); } return(this.Ok()); }