ILogger reference removed

This commit is contained in:
Pavel Vesely 2020-03-09 19:04:34 +01:00
parent 979463b365
commit 5d575c95ca
2 changed files with 30 additions and 47 deletions

View File

@ -5,7 +5,6 @@ using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Logging;
using Microsoft.JSInterop; using Microsoft.JSInterop;
using Oqtane.Models; using Oqtane.Models;
using Oqtane.Shared; using Oqtane.Shared;
@ -14,14 +13,13 @@ namespace Oqtane.Services
{ {
public class FileService : ServiceBase, IFileService public class FileService : ServiceBase, IFileService
{ {
private readonly ILogger<FileService> _logger;
private readonly HttpClient _http; private readonly HttpClient _http;
private readonly SiteState _siteState; private readonly SiteState _siteState;
private readonly NavigationManager _navigationManager; private readonly NavigationManager _navigationManager;
private readonly IJSRuntime _jsRuntime; private readonly IJSRuntime _jsRuntime;
public FileService(HttpClient http, SiteState siteState, NavigationManager navigationManager, IJSRuntime jsRuntime, ILogger<FileService> Logger) public FileService(HttpClient http, SiteState siteState, NavigationManager navigationManager,
IJSRuntime jsRuntime)
{ {
_http = http; _http = http;
_siteState = siteState; _siteState = siteState;
@ -45,19 +43,11 @@ namespace Oqtane.Services
} }
public async Task<List<File>> GetFilesAsync(int siteId, string folderPath) public async Task<List<File>> GetFilesAsync(int siteId, string folderPath)
{
try
{ {
if (!folderPath.EndsWith("\\")) folderPath += "\\"; if (!folderPath.EndsWith("\\")) folderPath += "\\";
var path = WebUtility.UrlEncode(folderPath); var path = WebUtility.UrlEncode(folderPath);
return await _http.GetJsonAsync<List<File>>($"{apiurl}/{siteId}/{path}"); return await _http.GetJsonAsync<List<File>>($"{apiurl}/{siteId}/{path}");
} }
catch (Exception e)
{
_logger.LogDebug(e,"Folder not found: {path}");
}
return null;
}
public async Task<File> GetFileAsync(int FileId) public async Task<File> GetFileAsync(int FileId)
{ {
@ -81,7 +71,8 @@ namespace Oqtane.Services
public async Task<File> UploadFileAsync(string Url, int FolderId) public async Task<File> UploadFileAsync(string Url, int FolderId)
{ {
return await _http.GetJsonAsync<File>(apiurl + "/upload?url=" + WebUtility.UrlEncode(Url) + "&folderid=" + FolderId.ToString()); return await _http.GetJsonAsync<File>(apiurl + "/upload?url=" + WebUtility.UrlEncode(Url) + "&folderid=" +
FolderId.ToString());
} }
public async Task<string> UploadFilesAsync(int FolderId, string[] Files, string Id) public async Task<string> UploadFilesAsync(int FolderId, string[] Files, string Id)
@ -117,8 +108,10 @@ namespace Oqtane.Services
} }
} }
} }
attempts += 1; attempts += 1;
} }
if (!success) if (!success)
{ {
result = result.Substring(0, result.Length - 1); result = result.Substring(0, result.Length - 1);

View File

@ -8,7 +8,6 @@ using Oqtane.Shared;
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Net; using System.Net;
using Microsoft.Extensions.Logging;
namespace Oqtane.Services namespace Oqtane.Services
{ {
@ -17,66 +16,55 @@ namespace Oqtane.Services
private readonly HttpClient _http; private readonly HttpClient _http;
private readonly SiteState _siteState; private readonly SiteState _siteState;
private readonly NavigationManager _navigationManager; private readonly NavigationManager _navigationManager;
private readonly ILogger<FolderService> _logger;
public FolderService(HttpClient http, SiteState siteState, NavigationManager navigationManager, ILogger<FolderService> logger) public FolderService(HttpClient http, SiteState siteState, NavigationManager navigationManager)
{ {
_http = http; _http = http;
_siteState = siteState; _siteState = siteState;
_navigationManager = navigationManager; _navigationManager = navigationManager;
_logger = logger;
} }
private string apiurl private string ApiUrl => CreateApiUrl(_siteState.Alias, _navigationManager.Uri, "Folder");
{
get { return CreateApiUrl(_siteState.Alias, _navigationManager.Uri, "Folder"); }
}
public async Task<List<Folder>> GetFoldersAsync(int SiteId) public async Task<List<Folder>> GetFoldersAsync(int SiteId)
{ {
List<Folder> folders = await _http.GetJsonAsync<List<Folder>>(apiurl + "?siteid=" + SiteId.ToString()); List<Folder> folders = await _http.GetJsonAsync<List<Folder>>(ApiUrl + "?siteid=" + SiteId.ToString());
folders = GetFoldersHierarchy(folders); folders = GetFoldersHierarchy(folders);
return folders; return folders;
} }
public async Task<Folder> GetFolderAsync(int FolderId) public async Task<Folder> GetFolderAsync(int FolderId)
{ {
return await _http.GetJsonAsync<Folder>(apiurl + "/" + FolderId.ToString()); return await _http.GetJsonAsync<Folder>(ApiUrl + "/" + FolderId.ToString());
} }
public async Task<Folder> GetFolderAsync(int siteId, [NotNull] string folderPath) public async Task<Folder> GetFolderAsync(int siteId, [NotNull] string folderPath)
{
try
{ {
if (!folderPath.EndsWith("\\")) folderPath += "\\"; if (!folderPath.EndsWith("\\")) folderPath += "\\";
var path = WebUtility.UrlEncode(folderPath); var path = WebUtility.UrlEncode(folderPath);
return await _http.GetJsonAsync<Folder>($"{apiurl}/{siteId}/{path}"); return await _http.GetJsonAsync<Folder>($"{ApiUrl}/{siteId}/{path}");
}
catch (Exception e)
{
_logger.LogDebug(e,"Folder not found: {path}");
}
return null;
} }
public async Task<Folder> AddFolderAsync(Folder Folder) public async Task<Folder> AddFolderAsync(Folder Folder)
{ {
return await _http.PostJsonAsync<Folder>(apiurl, Folder); return await _http.PostJsonAsync<Folder>(ApiUrl, Folder);
} }
public async Task<Folder> UpdateFolderAsync(Folder Folder) public async Task<Folder> UpdateFolderAsync(Folder Folder)
{ {
return await _http.PutJsonAsync<Folder>(apiurl + "/" + Folder.FolderId.ToString(), Folder); return await _http.PutJsonAsync<Folder>(ApiUrl + "/" + Folder.FolderId.ToString(), Folder);
} }
public async Task UpdateFolderOrderAsync(int SiteId, int FolderId, int? ParentId) 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) public async Task DeleteFolderAsync(int FolderId)
{ {
await _http.DeleteAsync(apiurl + "/" + FolderId.ToString()); await _http.DeleteAsync(ApiUrl + "/" + FolderId.ToString());
} }
private static List<Folder> GetFoldersHierarchy(List<Folder> Folders) private static List<Folder> GetFoldersHierarchy(List<Folder> Folders)
@ -97,10 +85,11 @@ namespace Oqtane.Services
level = folder.Level; level = folder.Level;
children = Folders.Where(item => item.ParentId == folder.FolderId); children = Folders.Where(item => item.ParentId == folder.FolderId);
} }
foreach (Folder child in children) foreach (Folder child in children)
{ {
child.Level = level + 1; 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); hierarchy.Add(child);
GetPath(folders, child); GetPath(folders, child);
} }
@ -116,6 +105,7 @@ namespace Oqtane.Services
hierarchy.Add(folder); hierarchy.Add(folder);
} }
} }
return hierarchy; return hierarchy;
} }
} }