You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.2 KiB
71 lines
1.2 KiB
using System.Net.Http.Json; |
|
using Model.Documentation; |
|
|
|
#if NO_SQL |
|
|
|
#else |
|
using Contexts; |
|
using Microsoft.EntityFrameworkCore; |
|
#endif |
|
|
|
namespace Services.Development; |
|
|
|
public class DocumentationService : IDocumentationService |
|
{ |
|
private readonly HttpClient httpClient; |
|
|
|
private bool isLoaded; |
|
|
|
|
|
private event Action _onChange; |
|
|
|
|
|
public DocumentationService(HttpClient httpClient) |
|
{ |
|
this.httpClient = httpClient; |
|
} |
|
|
|
public List<DocumentationModel> DocumentationModels { get; set; } |
|
|
|
|
|
public void Subscribe(Action action) |
|
{ |
|
_onChange += action; |
|
} |
|
|
|
public void Unsubscribe(Action action) |
|
{ |
|
_onChange -= action; |
|
} |
|
|
|
public bool IsLoaded() |
|
{ |
|
return isLoaded; |
|
} |
|
|
|
|
|
public async Task Load() |
|
{ |
|
if (isLoaded) return; |
|
|
|
DocumentationModels = |
|
(await httpClient.GetFromJsonAsync<DocumentationModel[]>("generated/DocumentationModels.json") ?? Array.Empty<DocumentationModel>()).ToList(); |
|
|
|
|
|
isLoaded = true; |
|
|
|
NotifyDataChanged(); |
|
} |
|
|
|
|
|
public void Update() |
|
{ |
|
NotifyDataChanged(); |
|
} |
|
|
|
|
|
private void NotifyDataChanged() |
|
{ |
|
_onChange?.Invoke(); |
|
} |
|
} |