Skip to content

Commit

Permalink
Added console output for VaultService to give indication when stuff g…
Browse files Browse the repository at this point in the history
…oes sideways.
  • Loading branch information
jake1164 committed Oct 4, 2024
1 parent 8c7e739 commit 7ceda7e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions ShelterViewer/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
protected override async Task OnInitializedAsync()
{
VaultService.OnVaultChanged += async () => await InvokeAsync(StateHasChanged);

try
{
var vJson = await Http.GetFromJsonAsync<Dictionary<string, string>>(".version");
Expand Down
27 changes: 19 additions & 8 deletions ShelterViewer/Services/VaultService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
using ShelterViewer.Models;
using ShelterViewer.Utility;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;

namespace ShelterViewer.Services;

public class VaultService
{
public event Action? OnVaultChanged = null;

private IJSRuntime JS;
private string _vaultString = String.Empty;

private dynamic? _vaultData = null;
Expand Down Expand Up @@ -59,6 +61,11 @@ public int Quantums
}
}

public VaultService(IJSRuntime jsRuntime)
{
JS = jsRuntime;
}

public void InitializeVault(string vaultJsonString)
{

Expand All @@ -73,7 +80,7 @@ public void InitializeVault(string vaultJsonString)
catch (Exception ex)
{
_vaultString = String.Empty;
Console.WriteLine("Unable to convert vault string to JSON Object: " + ex.Message);
Log("Unable to convert vault string to JSON Object: " + ex.Message);
}
}

Expand All @@ -94,17 +101,18 @@ public List<Dweller> GetDwellers()
List<Dweller> dwellers = new();
if (_vaultData == null)
return new();

foreach (var dweller in _vaultData.dwellers.dwellers)
{
try
{
Console.WriteLine(dweller);
Log(dweller);
dwellers.Add(JsonConvert.DeserializeObject<Dweller>(dweller.ToString(), settings));

}
catch (Exception ex)
{
Console.WriteLine("Unable to convert dwellers string to JSON Object: " + ex.Message);
Log("Unable to convert dwellers string to JSON Object: " + ex.Message);
}
}

Expand All @@ -115,25 +123,28 @@ public List<Room> GetRooms()
{
var settings = new IntJsonConverter();
List<Room> rooms = new();
if (_vaultData == null)
return new();


foreach (var room in _vaultData.vault.rooms)
foreach (var room in _vaultData?.vault.rooms ?? new List<Room>())
{
try
{
rooms.Add(JsonConvert.DeserializeObject<Room>(room.ToString(), settings));
}
catch (Exception ex)
{
Console.WriteLine("Unable to convert rooms string to JSON Object: " + ex.Message);
Log("Unable to convert rooms string to JSON Object: " + ex.Message);
}
}

return rooms;
}

private void Log(params object?[]? message)
{
if(JS != null)
JS.InvokeVoidAsync("console.log", message);
}

private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
OnVaultChanged?.Invoke();
Expand Down
7 changes: 1 addition & 6 deletions ShelterViewer/wwwroot/js/shelter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ window.shelter = {
},

decryptString: async function (base64String) {
return new Promise((resolve, reject) => {
// Initialize necessary variables (sjcl, key, iv, base64Str, prp, cipherBits)
//import { key, iv } from './aes.js'

return new Promise((resolve, reject) => {
const iv = sjcl.codec.hex.toBits("7475383967656A693334307438397532");
const cipherBits = sjcl.codec.base64.toBits(base64String);
console.log('cipherBits', cipherBits);
const prp = new sjcl.cipher.aes(key);
const plainBits = sjcl.mode.cbc.decrypt(prp, cipherBits, iv);
const jsonStr = sjcl.codec.utf8String.fromBits(plainBits);
try {
console.log(JSON.parse(jsonStr));
resolve(jsonStr);
} catch (e) {
reject(new Error("Error Decrypting String"));
Expand Down

0 comments on commit 7ceda7e

Please sign in to comment.