17 using System.Collections;
18 using System.Collections.Generic;
21 using System.Xml.Serialization;
22 using Newtonsoft.Json;
36 public event EventHandler<ObjectStoreErrorRaisedEventArgs>
ErrorRaised
62 _store.Initialize(userId, projectId, userToken, controls);
68 public ICollection<string>
Keys => _store.Keys;
73 public void Clear() => _store.Clear();
82 return _store.ContainsKey(path);
92 return _store.ReadBytes(path);
103 return _store.SaveBytes(path, contents);
113 return _store.Delete(path);
123 return _store.GetFilePath(path);
132 public string Read(
string path, Encoding encoding =
null)
134 encoding = encoding ?? Encoding.UTF8;
136 var data = _store.ReadBytes(path);
137 return data !=
null ? encoding.GetString(data) :
null;
146 public string ReadString(
string path, Encoding encoding =
null)
148 return Read(path, encoding);
158 public T
ReadJson<T>(
string path, Encoding encoding =
null, JsonSerializerSettings settings =
null)
160 encoding = encoding ?? Encoding.UTF8;
162 var json =
Read(path, encoding);
163 return JsonConvert.DeserializeObject<T>(json, settings);
174 encoding = encoding ?? Encoding.UTF8;
176 var xml =
Read(path, encoding);
178 var serializer =
new XmlSerializer(typeof(T));
179 using (var reader =
new StringReader(xml))
181 return (T)serializer.Deserialize(reader);
195 if (!
File.Exists(filePath))
197 throw new ArgumentException($
"There is no file associated with path {path} in '{filePath}'");
199 var bytes =
File.ReadAllBytes(filePath);
201 return _store.SaveBytes(path, bytes);
211 public bool Save(
string path,
string text, Encoding encoding =
null)
213 encoding ??= Encoding.UTF8;
214 return _store.SaveBytes(path, encoding.GetBytes(text));
224 public bool SaveString(
string path,
string text, Encoding encoding =
null)
226 encoding = encoding ?? Encoding.UTF8;
228 return _store.SaveBytes(path, encoding.GetBytes(text));
239 public bool SaveJson<T>(
string path, T obj, Encoding encoding =
null, JsonSerializerSettings settings =
null)
241 encoding = encoding ?? Encoding.UTF8;
243 var json = JsonConvert.SerializeObject(obj, settings);
254 public bool SaveXml<T>(
string path, T obj, Encoding encoding =
null)
256 encoding = encoding ?? Encoding.UTF8;
258 using (var writer =
new StringWriter())
260 var serializer =
new XmlSerializer(typeof(T));
261 serializer.Serialize(writer, obj);
263 var xml = writer.ToString();
273 return _store.GetEnumerator();
279 IEnumerator IEnumerable.GetEnumerator()
281 return ((IEnumerable) _store).GetEnumerator();