Seperation of concerns: Seperated used File Management form Overall FIle Management

This commit is contained in:
schnulller
2022-06-05 15:18:32 +02:00
parent abc27c6d04
commit c95059b2e8
22 changed files with 211 additions and 186 deletions

View File

@@ -8,6 +8,7 @@ using Microsoft.Net.Http.Headers;
using HaWeb.Filters;
using HaWeb.FileHelpers;
using HaWeb.XMLParser;
using HaWeb.Models;
using System.Text.Json.Serialization;
using System.Text.Json;
using HaDocument.Interfaces;
@@ -25,14 +26,16 @@ public class APIController : Controller {
private readonly long _fileSizeLimit;
private readonly string _targetFilePath;
private readonly IXMLService _xmlService;
private readonly IXMLProvider _xmlProvider;
// Options
private static readonly string[] _permittedExtensions = { ".xml" };
private static readonly FormOptions _defaultFormOptions = new FormOptions();
public APIController(IHaDocumentWrappper lib, IReaderService readerService, IXMLService xmlService, IConfiguration config) {
public APIController(IHaDocumentWrappper lib, IReaderService readerService, IXMLService xmlService, IXMLProvider xmlProvider, IConfiguration config) {
_lib = lib;
_xmlProvider = xmlProvider;
_readerService = readerService;
_xmlService = xmlService;
_fileSizeLimit = config.GetValue<long>("FileSizeLimit");
@@ -117,7 +120,13 @@ public class APIController : Controller {
//// 5. Stage: Saving the File(s)
foreach (var doc in retdocs) {
await _xmlService.UpdateAvailableFiles(doc, _targetFilePath, ModelState);
// Physical saving
var task = _xmlProvider.Save(doc, _targetFilePath, ModelState);
// Setting the new docuemnt as used
_xmlService.Use(doc);
// Unsetting all old docuemnts as ununsed
_xmlService.AutoUse(doc.Prefix);
await task;
if (!ModelState.IsValid) return StatusCode(500, ModelState);
if (docs == null) docs = new List<XMLRootDocument>();
docs.Add(doc);

View File

@@ -18,16 +18,18 @@ public class UploadController : Controller {
private readonly long _fileSizeLimit;
private readonly string _targetFilePath;
private readonly IXMLService _xmlService;
private readonly IXMLProvider _xmlProvider;
// Options
private static readonly string[] _permittedExtensions = { ".xml" };
private static readonly FormOptions _defaultFormOptions = new FormOptions();
public UploadController(IHaDocumentWrappper lib, IReaderService readerService, IXMLService xmlService, IConfiguration config) {
public UploadController(IHaDocumentWrappper lib, IReaderService readerService, IXMLService xmlService, IXMLProvider xmlProvider, IConfiguration config) {
_lib = lib;
_readerService = readerService;
_xmlService = xmlService;
_xmlProvider = xmlProvider;
_fileSizeLimit = config.GetValue<long>("FileSizeLimit");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
_targetFilePath = config.GetValue<string>("StoredFilePathWindows");
@@ -42,23 +44,25 @@ public class UploadController : Controller {
[GenerateAntiforgeryTokenCookie]
public IActionResult Index(string? id) {
if (id != null) {
id = id.ToLower();
var root = _xmlService.GetRoot(id);
if (root == null) return error404();
var roots = _xmlService.GetRoots();
var roots = _xmlService.GetRootsList();
if (roots == null) return error404();
var usedFiles = _xmlService.GetUsed();
var availableFiles = _xmlService.GetAvailableFiles(id);
var usedFiles = _xmlService.GetUsedDictionary();
var availableFiles = _xmlProvider.GetFiles(id);
var model = new UploadViewModel(root.Type, id, roots, availableFiles, usedFiles);
return View("../Admin/Upload/Index", model);
}
else {
var roots = _xmlService.GetRoots();
var roots = _xmlService.GetRootsList();
if (roots == null) return error404();
var usedFiles = _xmlService.GetUsed();
var usedFiles = _xmlService.GetUsedDictionary();
var model = new UploadViewModel("Upload", id, roots, null, usedFiles);
return View("../Admin/Upload/Index", model);