-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStockRepositoryManager.cs
39 lines (33 loc) · 1.34 KB
/
StockRepositoryManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using RussellScreener.Entities;
namespace RussellScreener {
public class StockRepositoryManager {
#region Methods
/// <summary>
/// Deserialize a stock repository from a JSON file for caching purpose
/// </summary>
/// <param name="cacheFilename">Cache filename</param>
/// <returns>A deserialized StockRepository object</returns>
public StockRepository ReadStockRepositoryFromCache(string cacheFilename) {
var json = File.ReadAllText(cacheFilename);
return (StockRepository)BaseJsonObject.FromJson<StockRepository>(json);
}
/// <summary>
/// Serialize a stock repository as a JSON file for caching purpose
/// </summary>
/// <param name="stockRepository">StockRepository object that must be serialized</param>
/// <param name="cacheFilename">Cache filename</param>
public void WriteStockRepositoryCache(StockRepository stockRepository, string cacheFilename) {
var json = BaseJsonObject.ToJson(stockRepository);
File.WriteAllText(cacheFilename, json);
}
#endregion Methods
}
}