From 5d575c95cab910641fc1e7a10cf064d2c72ca185 Mon Sep 17 00:00:00 2001 From: Pavel Vesely Date: Mon, 9 Mar 2020 19:04:34 +0100 Subject: [PATCH] ILogger reference removed --- Oqtane.Client/Services/FileService.cs | 27 +++++-------- Oqtane.Client/Services/FolderService.cs | 50 ++++++++++--------------- 2 files changed, 30 insertions(+), 47 deletions(-) diff --git a/Oqtane.Client/Services/FileService.cs b/Oqtane.Client/Services/FileService.cs index d377d62e..265ccb67 100644 --- a/Oqtane.Client/Services/FileService.cs +++ b/Oqtane.Client/Services/FileService.cs @@ -5,7 +5,6 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; -using Microsoft.Extensions.Logging; using Microsoft.JSInterop; using Oqtane.Models; using Oqtane.Shared; @@ -14,14 +13,13 @@ namespace Oqtane.Services { public class FileService : ServiceBase, IFileService { - - private readonly ILogger _logger; private readonly HttpClient _http; private readonly SiteState _siteState; private readonly NavigationManager _navigationManager; private readonly IJSRuntime _jsRuntime; - public FileService(HttpClient http, SiteState siteState, NavigationManager navigationManager, IJSRuntime jsRuntime, ILogger Logger) + public FileService(HttpClient http, SiteState siteState, NavigationManager navigationManager, + IJSRuntime jsRuntime) { _http = http; _siteState = siteState; @@ -46,19 +44,11 @@ namespace Oqtane.Services public async Task> GetFilesAsync(int siteId, string folderPath) { - try - { - if (!folderPath.EndsWith("\\")) folderPath += "\\"; - var path = WebUtility.UrlEncode(folderPath); - return await _http.GetJsonAsync>($"{apiurl}/{siteId}/{path}"); - } - catch (Exception e) - { - _logger.LogDebug(e,"Folder not found: {path}"); - } - return null; + if (!folderPath.EndsWith("\\")) folderPath += "\\"; + var path = WebUtility.UrlEncode(folderPath); + return await _http.GetJsonAsync>($"{apiurl}/{siteId}/{path}"); } - + public async Task GetFileAsync(int FileId) { return await _http.GetJsonAsync(apiurl + "/" + FileId.ToString()); @@ -81,7 +71,8 @@ namespace Oqtane.Services public async Task UploadFileAsync(string Url, int FolderId) { - return await _http.GetJsonAsync(apiurl + "/upload?url=" + WebUtility.UrlEncode(Url) + "&folderid=" + FolderId.ToString()); + return await _http.GetJsonAsync(apiurl + "/upload?url=" + WebUtility.UrlEncode(Url) + "&folderid=" + + FolderId.ToString()); } public async Task UploadFilesAsync(int FolderId, string[] Files, string Id) @@ -117,8 +108,10 @@ namespace Oqtane.Services } } } + attempts += 1; } + if (!success) { result = result.Substring(0, result.Length - 1); diff --git a/Oqtane.Client/Services/FolderService.cs b/Oqtane.Client/Services/FolderService.cs index 630231fe..a457b021 100644 --- a/Oqtane.Client/Services/FolderService.cs +++ b/Oqtane.Client/Services/FolderService.cs @@ -8,7 +8,6 @@ using Oqtane.Shared; using System; using System.Diagnostics.CodeAnalysis; using System.Net; -using Microsoft.Extensions.Logging; namespace Oqtane.Services { @@ -17,66 +16,55 @@ namespace Oqtane.Services private readonly HttpClient _http; private readonly SiteState _siteState; private readonly NavigationManager _navigationManager; - private readonly ILogger _logger; - - public FolderService(HttpClient http, SiteState siteState, NavigationManager navigationManager, ILogger logger) + + public FolderService(HttpClient http, SiteState siteState, NavigationManager navigationManager) { _http = http; _siteState = siteState; _navigationManager = navigationManager; - _logger = logger; } - private string apiurl - { - get { return CreateApiUrl(_siteState.Alias, _navigationManager.Uri, "Folder"); } - } + private string ApiUrl => CreateApiUrl(_siteState.Alias, _navigationManager.Uri, "Folder"); public async Task> GetFoldersAsync(int SiteId) { - List folders = await _http.GetJsonAsync>(apiurl + "?siteid=" + SiteId.ToString()); + List folders = await _http.GetJsonAsync>(ApiUrl + "?siteid=" + SiteId.ToString()); folders = GetFoldersHierarchy(folders); return folders; } public async Task GetFolderAsync(int FolderId) { - return await _http.GetJsonAsync(apiurl + "/" + FolderId.ToString()); + return await _http.GetJsonAsync(ApiUrl + "/" + FolderId.ToString()); } - - public async Task GetFolderAsync(int siteId, [NotNull]string folderPath) + + public async Task GetFolderAsync(int siteId, [NotNull] string folderPath) { - try - { - if (!folderPath.EndsWith("\\")) folderPath += "\\"; - var path = WebUtility.UrlEncode(folderPath); - return await _http.GetJsonAsync($"{apiurl}/{siteId}/{path}"); - } - catch (Exception e) - { - _logger.LogDebug(e,"Folder not found: {path}"); - } - return null; + if (!folderPath.EndsWith("\\")) folderPath += "\\"; + var path = WebUtility.UrlEncode(folderPath); + return await _http.GetJsonAsync($"{ApiUrl}/{siteId}/{path}"); } public async Task AddFolderAsync(Folder Folder) { - return await _http.PostJsonAsync(apiurl, Folder); + return await _http.PostJsonAsync(ApiUrl, Folder); } public async Task UpdateFolderAsync(Folder Folder) { - return await _http.PutJsonAsync(apiurl + "/" + Folder.FolderId.ToString(), Folder); + return await _http.PutJsonAsync(ApiUrl + "/" + Folder.FolderId.ToString(), Folder); } public async Task UpdateFolderOrderAsync(int SiteId, int FolderId, int? ParentId) { - await _http.PutJsonAsync(apiurl + "/?siteid=" + SiteId.ToString() + "&folderid=" + FolderId.ToString() + "&parentid=" + ((ParentId == null) ? "" : ParentId.ToString()), null); + await _http.PutJsonAsync( + ApiUrl + "/?siteid=" + SiteId.ToString() + "&folderid=" + FolderId.ToString() + "&parentid=" + + ((ParentId == null) ? "" : ParentId.ToString()), null); } public async Task DeleteFolderAsync(int FolderId) { - await _http.DeleteAsync(apiurl + "/" + FolderId.ToString()); + await _http.DeleteAsync(ApiUrl + "/" + FolderId.ToString()); } private static List GetFoldersHierarchy(List Folders) @@ -97,10 +85,11 @@ namespace Oqtane.Services level = folder.Level; children = Folders.Where(item => item.ParentId == folder.FolderId); } + foreach (Folder child in children) { child.Level = level + 1; - child.HasChildren = Folders.Where(item => item.ParentId == child.FolderId).Any(); + child.HasChildren = Folders.Any(item => item.ParentId == child.FolderId); hierarchy.Add(child); GetPath(folders, child); } @@ -109,13 +98,14 @@ namespace Oqtane.Services GetPath(Folders, null); // add any non-hierarchical items to the end of the list - foreach(Folder folder in Folders) + foreach (Folder folder in Folders) { if (hierarchy.Find(item => item.FolderId == folder.FolderId) == null) { hierarchy.Add(folder); } } + return hierarchy; } }