-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from GyroGearl00se/presetservice
Presetservice
- Loading branch information
Showing
11 changed files
with
282 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Blazored.Toast.Services; | ||
using Blazorise; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
namespace SolaceWebClient.Services | ||
{ | ||
public class PresetModel | ||
{ | ||
public string Name { get; set; } | ||
public string Host { get; set; } | ||
public string VpnName { get; set; } | ||
public string Username { get; set; } | ||
public string QueueName { get; set; } | ||
public string Topic { get; set; } | ||
} | ||
|
||
public class PresetService | ||
{ | ||
private readonly string presetsFilePath = Path.Combine("presets", "presets.json"); | ||
|
||
public async Task<List<PresetModel>> GetPresetsAsync() | ||
{ | ||
if (!File.Exists(presetsFilePath)) | ||
{ | ||
return new List<PresetModel>(); | ||
} | ||
|
||
var json = await File.ReadAllTextAsync(presetsFilePath); | ||
var presets = JsonSerializer.Deserialize<List<PresetModel>>(json); | ||
|
||
return presets ?? new List<PresetModel>(); | ||
} | ||
|
||
public async Task SavePresetsAsync(List<PresetModel> presets) | ||
{ | ||
var json = JsonSerializer.Serialize(presets, new JsonSerializerOptions { WriteIndented = true }); | ||
var directory = Path.GetDirectoryName(presetsFilePath); | ||
|
||
if (!Directory.Exists(directory)) | ||
{ | ||
Directory.CreateDirectory(directory); | ||
} | ||
|
||
await File.WriteAllTextAsync(presetsFilePath, json); | ||
} | ||
} | ||
} |
Oops, something went wrong.