morning4coffe-dev / recurrents

Tired of losing track of your spending on many different services? With Recurrents, just input your subscriptions for an easy overview and stay in control with reminders, save money, and enjoy a stress-free experience. Take control of your expenses effortlessly!
https://www.microsoft.com/store/apps/9N5MJT8G06KC
MIT License
10 stars 1 forks source link

Log #80

Closed github-actions[bot] closed 11 months ago

github-actions[bot] commented 11 months ago

https://github.com/morning4coffe-dev/recurrents/blob/47c018836e9073dbaf01f0d3c7621c6f38d68242/ProjectSBS/ProjectSBS/Services/Storage/Data/DataService.cs#L110


    {
        var data = await LoadAsync(itemsPath, typeof(List<Item>));

        return (data as List<Item>) ?? [];
    }

    public async Task<List<ItemLog>> LoadLogsAsync()
    {
        var logs = await LoadAsync(logsPath, typeof(List<ItemLog>));

        return (logs as List<ItemLog>) ?? [];
    }

    private async Task<object?> LoadAsync(string path, Type type)
    {
        try
        {
            //TODO var isSigned = await _authentication.IsAuthenticated();
            var isSigned = _userService.IsLoggedIn;
            string remoteContent = "";

            if (isSigned)
            {
                //TODO Use CancellationToken
                var data = await _userService.RetrieveData(path, CancellationToken.None);
                remoteContent = data.ReadToEnd();
            }

            if (!isSigned)
            {
                if (!_storage.DoesFileExist(path))
                {
                    return null;
                }
                var fileContent = await _storage.ReadFileAsync(path);
                remoteContent = fileContent;
            }

            //TODO Compare remote and local content
            if (remoteContent is not { })
            {
                return null;
            }

            return JsonSerializer.Deserialize(remoteContent, type);
        }
        catch(Exception ex)
        {
            //TODO Log
            Console.WriteLine(ex);
            return null;
        }
    }
}
github-actions[bot] commented 11 months ago

Closed in 92dd3c57c55d102a79b41bf2e3241c06332d4cf3