2022-06-29 13:05:12 -04:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using DeskHubSharpRevised.Models;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
2022-06-29 12:59:53 -04:00
|
|
|
namespace DeskHubSharpRevised.DAL;
|
|
|
|
|
2022-06-30 17:44:06 -04:00
|
|
|
public class JsonDataService : IDataService
|
2022-06-29 12:59:53 -04:00
|
|
|
{
|
2022-06-29 13:05:12 -04:00
|
|
|
private string _dataConfig;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// reads all the things from the json string/data
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public IEnumerable<Search> ReadAll()
|
|
|
|
{
|
|
|
|
List<Search> user = new List<Search>();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (StreamReader sr = new StreamReader(_dataConfig))
|
|
|
|
{
|
|
|
|
string jsonString = sr.ReadToEnd();
|
|
|
|
|
|
|
|
Search.ItemsItem users = JsonConvert.DeserializeObject<Search.ItemsItem>(_dataConfig);
|
|
|
|
//user = users.items;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void WriteAll(IEnumerable<User> characters)
|
|
|
|
{
|
|
|
|
//RootObject rootObject = new RootObject();
|
|
|
|
//rootObject.Characters = new Characters();
|
|
|
|
//rootObject.Characters.Character = characters as List<Character>;
|
|
|
|
//string jsonString = JsonConvert.SerializeObject(rootObject);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
StreamWriter writer = new StreamWriter(_dataConfig);
|
|
|
|
using (writer)
|
|
|
|
{
|
|
|
|
//writer.WriteLine(jsonString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public JsonDataService()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public JsonDataService(string dataFile)
|
|
|
|
{
|
|
|
|
_dataConfig = dataFile;
|
|
|
|
}
|
2022-06-30 17:44:06 -04:00
|
|
|
|
|
|
|
public void SearchRequest()
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UserRequest()
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void BranchRequest()
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
2022-06-29 12:59:53 -04:00
|
|
|
}
|