subscription view finished

This commit is contained in:
2024-03-09 02:56:56 +01:00
Unverified
parent 70fdc10f50
commit 38475a96ad
17 changed files with 439 additions and 31 deletions

View File

@@ -0,0 +1,32 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VDownload.Models;
namespace VDownload.Services.Data.Subscriptions
{
public class Subscription
{
#region PROPERTIES
[JsonProperty("guid")]
public Guid Guid { get; private set; } = Guid.NewGuid();
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("source")]
public Source Source { get; set; }
[JsonProperty("url")]
public Uri Url { get; set; }
[JsonProperty("video_ids")]
public ICollection<string> VideoIds { get; private set; } = new List<string>();
#endregion
}
}

View File

@@ -1,12 +1,97 @@
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VDownload.Services.Data.Configuration;
namespace VDownload.Services.Data.Subscriptions
{
public class SubscriptionsDataService
public interface ISubscriptionsDataService
{
#region PROPERTIES
ICollection<Subscription> Data { get; }
#endregion
#region METHODS
Task Load();
Task Save();
#endregion
}
public class SubscriptionsDataService : ISubscriptionsDataService
{
#region SERVICES
protected readonly IConfigurationService _configurationService;
#endregion
#region FIELDS
protected readonly string _filePath;
#endregion
#region PROPERTIES
public ICollection<Subscription> Data { get; private set; }
#endregion
#region CONSTRUCTORS
public SubscriptionsDataService(IConfigurationService configurationService)
{
_configurationService = configurationService;
string appdataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string appdataDirectoryName = _configurationService.Common.Path.Appdata.DirectoryName;
string appdataAuthenticationFilename = _configurationService.Common.Path.Appdata.SubscriptionsFile;
_filePath = Path.Combine(appdataPath, appdataDirectoryName, appdataAuthenticationFilename);
}
#endregion
#region PUBLIC METHODS
public async Task Load()
{
if (File.Exists(_filePath))
{
string content = await File.ReadAllTextAsync(_filePath);
Data = JsonConvert.DeserializeObject<ICollection<Subscription>>(content);
}
else
{
Data = new List<Subscription>();
}
}
public async Task Save()
{
Directory.CreateDirectory(Path.GetDirectoryName(_filePath));
string content = JsonConvert.SerializeObject(Data);
await File.WriteAllTextAsync(_filePath, content);
}
#endregion
}
}

View File

@@ -6,4 +6,13 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\VDownload.Models\VDownload.Models.csproj" />
<ProjectReference Include="..\VDownload.Services.Data.Configuration\VDownload.Services.Data.Configuration.csproj" />
</ItemGroup>
</Project>