public void Write(Mapping configuration) { var filePath = _configFilePathLocator.Locate(); using (StreamWriter file = File.CreateText(filePath.FullName)) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, configuration); } }
// Methods public void Write(IEnumerable <FileNode> fileConfigurations) { var filePath = _configFilePathLocator.Locate(); using (var fileStream = new FileStream(filePath.FullName, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) using (StreamWriter file = new StreamWriter(fileStream)) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, fileConfigurations); } }
public FileNode Manage(FileInfo fileInfo) { var node = _configuration.FirstOrDefault(x => Path.Combine(x.Directory, x.FileName) == fileInfo.FullName); if (node == null) { var newNode = new FileNode(fileInfo, _configFilePathLocator.Locate().Directory); _configuration.Add(newNode); _fileConfigurationWriter.Write(_configuration); CreateFileWatcher(newNode); node = newNode; } return(node); }
// Methods public Mapping Read() { Mapping result = null; var filePath = _configFilePathLocator.Locate(); using (StreamReader fileReader = File.OpenText(filePath.FullName)) { JsonSerializer serializer = new JsonSerializer(); result = (Mapping)serializer.Deserialize(fileReader, typeof(Mapping)); } return(result); }
// Methods public IList <FileNode> Read() { List <FileNode> result = null; var filePath = _configFilePathLocator.Locate(); using (StreamReader fileReader = File.OpenText(filePath.FullName)) { JsonSerializer serializer = new JsonSerializer(); result = (List <FileNode>)serializer.Deserialize(fileReader, typeof(List <FileNode>)); } return(result ?? new List <FileNode>()); }