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.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<FileService> _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<FileService> 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<List<File>> GetFilesAsync(int siteId, string folderPath)
{
try
{
if (!folderPath.EndsWith("\\")) folderPath += "\\";
var path = WebUtility.UrlEncode(folderPath);
return await _http.GetJsonAsync<List<File>>($"{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<List<File>>($"{apiurl}/{siteId}/{path}");
}
public async Task<File> GetFileAsync(int FileId)
{
return await _http.GetJsonAsync<File>(apiurl + "/" + FileId.ToString());
@ -81,7 +71,8 @@ namespace Oqtane.Services
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)
@ -117,8 +108,10 @@ namespace Oqtane.Services
}
}
}
attempts += 1;
}
if (!success)
{
result = result.Substring(0, result.Length - 1);

View File

@ -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<FolderService> _logger;
public FolderService(HttpClient http, SiteState siteState, NavigationManager navigationManager, ILogger<FolderService> 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<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);
return folders;
}
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 += "\\";
var path = WebUtility.UrlEncode(folderPath);
return await _http.GetJsonAsync<Folder>($"{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<Folder>($"{ApiUrl}/{siteId}/{path}");
}
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)
{
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)
{
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<Folder> GetFoldersHierarchy(List<Folder> 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;
}
}