public TagsToSerialize readTagsFromFile() { try { using (StreamReader r = new StreamReader(currentPath + directory_path + file_path)) { string json = r.ReadToEnd(); TagsToSerialize tags = JsonConvert.DeserializeObject <TagsToSerialize>(json); return(tags); } } catch (Exception) { return(null); } }
public bool writeTagsToFile(TagsToSerialize tags) { try { using (StreamWriter file = File.CreateText(currentPath + directory_path + file_path)) { JsonSerializer serializer = new JsonSerializer(); //serialize object directly into file stream serializer.Serialize(file, tags); return(true); } } catch (Exception) { return(false); } }
public Tag[] getTags() { lock (tags) { if (tags.Count == 0) { tagsToSer = tagIO.readTagsFromFile(); if (tagsToSer != null) { processLoadedTags(); } else { tagsToSer = new TagsToSerialize(); } } return(tags.Values.ToArray()); } }